aboutsummaryrefslogtreecommitdiff
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
parent0eb82ad8ff660f6a5542e66b7e4f5179880baf27 (diff)
downloadtaginfo-3688d2b9e9668ab199ad41173fcf6629350e9a1a.tar
taginfo-3688d2b9e9668ab199ad41173fcf6629350e9a1a.tar.gz
Added out-of-bounds-check, initalize global static
-rw-r--r--tagstats/geodistribution.hpp10
-rw-r--r--tagstats/tagstats.cpp1
2 files changed, 11 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
diff --git a/tagstats/tagstats.cpp b/tagstats/tagstats.cpp
index 88026c4..718c4bc 100644
--- a/tagstats/tagstats.cpp
+++ b/tagstats/tagstats.cpp
@@ -77,6 +77,7 @@ public:
int main(int argc, char *argv[]) {
Osmium::Framework osmium;
+ GeoDistribution::reset();
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " OSMFILE" << std::endl;
exit(1);