summaryrefslogtreecommitdiff
path: root/tagstats/geodistribution.hpp
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2011-04-22 16:59:33 +0200
committerJochen Topf <jochen@topf.org>2011-04-22 16:59:33 +0200
commit3688d2b9e9668ab199ad41173fcf6629350e9a1a (patch)
tree6dcf3102aad15ef549b101f19f319353999ff7dd /tagstats/geodistribution.hpp
parent0eb82ad8ff660f6a5542e66b7e4f5179880baf27 (diff)
downloadtaginfo-3688d2b9e9668ab199ad41173fcf6629350e9a1a.tar
taginfo-3688d2b9e9668ab199ad41173fcf6629350e9a1a.tar.gz
Added out-of-bounds-check, initalize global static
Diffstat (limited to 'tagstats/geodistribution.hpp')
-rw-r--r--tagstats/geodistribution.hpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tagstats/geodistribution.hpp b/tagstats/geodistribution.hpp
index 4065b5c..c246564 100644
--- a/tagstats/geodistribution.hpp
+++ b/tagstats/geodistribution.hpp
@@ -39,6 +39,12 @@ public:
void add_coordinate(double dx, double dy) {
int x = int(2 * (dx + 180));
int y = resolution_y - int(2 * (dy + 90));
+
+ if (x < 0) x=0;
+ if (y < 0) y=0;
+ if (x >= resolution_x) x = resolution_x-1;
+ if (y >= resolution_y) y = resolution_y-1;
+
int n = resolution_x * y + x;
if (cells == 0) {
loc = n;
@@ -50,6 +56,7 @@ public:
(*location)[loc] = true;
location_all[loc] = true;
(*location)[n] = true;
+ location_all[n] = true;
cells++;
}
} else {
@@ -118,6 +125,9 @@ public:
return location_all.count();
}
+ static void reset() {
+ location_all.reset();
+ }
};
#endif // TAGSTATS_GEODISTRIBUTION_HPP