diff --git a/Algorithms/DouglasPeucker.cpp b/Algorithms/DouglasPeucker.cpp index 09ad4e5da..ac6dd9d72 100644 --- a/Algorithms/DouglasPeucker.cpp +++ b/Algorithms/DouglasPeucker.cpp @@ -83,31 +83,6 @@ struct CoordinatePairCalculator }; } -DouglasPeucker::DouglasPeucker() - : douglas_peucker_thresholds({ - 512440, // z0 - 256720, // z1 - 122560, // z2 - 56780, // z3 - 28800, // z4 - 14400, // z5 - 7200, // z6 - 3200, // z7 - 2400, // z8 - 1000, // z9 - 600, // z10 - 120, // z11 - 60, // z12 - 45, // z13 - 36, // z14 - 20, // z15 - 8, // z16 - 6, // z17 - 4 // z18 - }) -{ -} - void DouglasPeucker::Run(std::vector &input_geometry, const unsigned zoom_level) { Run(std::begin(input_geometry), std::end(input_geometry), zoom_level); @@ -165,15 +140,16 @@ void DouglasPeucker::Run(RandomAccessIt begin, RandomAccessIt end, const unsigne { const int distance = dist_calc(it->location); // found new feasible maximum? - if (distance > max_int_distance && distance > douglas_peucker_thresholds[zoom_level]) + if (distance > max_int_distance && distance > DOUGLAS_PEUCKER_THRESHOLDS[zoom_level]) { farthest_entry_it = it; max_int_distance = distance; } } + // check if maximum violates a zoom level dependent threshold - if (max_int_distance > douglas_peucker_thresholds[zoom_level]) + if (max_int_distance > DOUGLAS_PEUCKER_THRESHOLDS[zoom_level]) { // mark idx as necessary farthest_entry_it->necessary = true; diff --git a/Algorithms/DouglasPeucker.h b/Algorithms/DouglasPeucker.h index b5146721e..4bd4c9a98 100644 --- a/Algorithms/DouglasPeucker.h +++ b/Algorithms/DouglasPeucker.h @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include /* This class object computes the bitvector of indicating generalized input * points according to the (Ramer-)Douglas-Peucker algorithm. @@ -40,20 +41,38 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * Note: points may also be pre-selected*/ struct SegmentInformation; +static const std::array DOUGLAS_PEUCKER_THRESHOLDS = { + 512440, // z0 + 256720, // z1 + 122560, // z2 + 56780, // z3 + 28800, // z4 + 14400, // z5 + 7200, // z6 + 3200, // z7 + 2400, // z8 + 1000, // z9 + 600, // z10 + 120, // z11 + 60, // z12 + 45, // z13 + 36, // z14 + 20, // z15 + 8, // z16 + 6, // z17 + 4 // z18 +}; class DouglasPeucker { public: using RandomAccessIt = std::vector::iterator; - private: - std::vector douglas_peucker_thresholds; using GeometryRange = std::pair; // Stack to simulate the recursion std::stack recursion_stack; public: - DouglasPeucker(); void Run(RandomAccessIt begin, RandomAccessIt end, const unsigned zoom_level); void Run(std::vector &input_geometry, const unsigned zoom_level); };