diff --git a/geometry/geometry_tests/geometry_tests.pro b/geometry/geometry_tests/geometry_tests.pro index e1d394d5ed..146431658b 100644 --- a/geometry/geometry_tests/geometry_tests.pro +++ b/geometry/geometry_tests/geometry_tests.pro @@ -6,7 +6,7 @@ CONFIG -= app_bundle TEMPLATE = app ROOT_DIR = ../.. -DEPENDENCIES = geometry base +DEPENDENCIES = indexer geometry base include($$ROOT_DIR/common.pri) diff --git a/geometry/geometry_tests/simplification_test.cpp b/geometry/geometry_tests/simplification_test.cpp index 3c1263314b..c39de827d3 100644 --- a/geometry/geometry_tests/simplification_test.cpp +++ b/geometry/geometry_tests/simplification_test.cpp @@ -1,10 +1,16 @@ #include "../../testing/testing.hpp" + #include "../simplification.hpp" + +#include "../../indexer/scales.hpp" + #include "../../geometry/distance.hpp" #include "../../geometry/point2d.hpp" + #include "../../base/logging.hpp" #include "../../base/macros.hpp" #include "../../base/stl_add.hpp" + #include "../../std/limits.hpp" #include "../../std/vector.hpp" @@ -114,6 +120,39 @@ UNIT_TEST(Simplification_Opt20_Polyline) &SimplifyNearOptimal20); } +namespace +{ + void CheckDistance(P const * arr) + { + double const eps = my::sq(scales::GetEpsilonForSimplify(17)); + + for (int prev = 0; prev < 3; ++prev) + { + int const curr = (prev+1) % 3; + int const next = (prev+2) % 3; + + double const dist = DistanceF(arr[prev], arr[next])(arr[curr]); + TEST_GREATER(dist, eps, ("Iteration = ", prev)); + + P const edgeL = arr[prev] - arr[curr]; + P const edgeR = arr[next] - arr[curr]; + double const cpLR = CrossProduct(edgeR, edgeL); + + TEST_NOT_EQUAL(cpLR, 0.0, ("Iteration = ", prev)); + } + } +} + +UNIT_TEST(Simpfication_DataSets) +{ + P arr1[] = { + P(23.6662673950195, 61.6197395324707), + P(23.6642074584961, 61.6190528869629), + P(23.6631774902344, 61.618709564209) + }; + CheckDistance(arr1); +} + // This is actually part of coastline of Australia. m2::PointD const kSimplifyTestLargePolylineData[] = { diff --git a/geometry/point2d.hpp b/geometry/point2d.hpp index 291204e307..5a17895479 100644 --- a/geometry/point2d.hpp +++ b/geometry/point2d.hpp @@ -207,6 +207,7 @@ namespace m2 template string debug_print(m2::Point const & p) { ostringstream out; + out.precision(15); out << "m2::Point<" << typeid(T).name() << ">(" << p.x << ", " << p.y << ")"; return out.str(); } diff --git a/geometry/polygon.hpp b/geometry/polygon.hpp index 6b4e8c14aa..d2734f8b15 100644 --- a/geometry/polygon.hpp +++ b/geometry/polygon.hpp @@ -80,7 +80,8 @@ template bool IsSegmentInCone(PointT v, PointT v1, PointT vPre PointT const edgeL = vPrev - v; PointT const edgeR = vNext - v; double const cpLR = CrossProduct(edgeR, edgeL); - ASSERT(!my::AlmostEqual(cpLR, 0.0), + //ASSERT(!my::AlmostEqual(cpLR, 0.0), + ASSERT_NOT_EQUAL(cpLR, 0.0, ("vPrev, v, vNext shouldn't be collinear!", edgeL, edgeR, v, v1, vPrev, vNext)); if (cpLR > 0) { diff --git a/indexer/indexer_tool/feature_sorter.cpp b/indexer/indexer_tool/feature_sorter.cpp index 09b6527af7..06cc7bf28c 100644 --- a/indexer/indexer_tool/feature_sorter.cpp +++ b/indexer/indexer_tool/feature_sorter.cpp @@ -88,8 +88,11 @@ namespace feature { if (in.size() >= 2) { - SimplifyNearOptimal >(20, in.begin(), in.end()-1, - my::sq(scales::GetEpsilonForSimplify(level)), MakeBackInsertFunctor(out)); + typedef mn::DistanceToLineSquare DistanceF; + double const eps = my::sq(scales::GetEpsilonForSimplify(level)); + + SimplifyNearOptimal(20, in.begin(), in.end()-1, + eps, MakeBackInsertFunctor(out)); switch (out.size()) { @@ -103,6 +106,14 @@ namespace feature if (!is_equal(out.back(), in.back())) out.push_back(in.back()); } + +#ifdef DEBUG + for (size_t i = 2; i < out.size(); ++i) + { + double const dist = DistanceF(out[i-2], out[i])(out[i-1]); + ASSERT_GREATER(dist, eps, ()); + } +#endif } }