From 3688d2b9e9668ab199ad41173fcf6629350e9a1a Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 22 Apr 2011 16:59:33 +0200 Subject: Added out-of-bounds-check, initalize global static --- tagstats/geodistribution.hpp | 10 ++++++++++ tagstats/tagstats.cpp | 1 + 2 files changed, 11 insertions(+) (limited to 'tagstats') 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); -- cgit v1.2.3