From 476b7279054c53ac0c891bb41f37f90a3e0cc197 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Wed, 11 May 2016 13:39:32 +0300 Subject: [PATCH] Make point comparison more accurate. --- .../editor_tests/osm_feature_matcher_test.cpp | 67 ++++++++++++++++++- editor/osm_feature_matcher.cpp | 2 +- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/editor/editor_tests/osm_feature_matcher_test.cpp b/editor/editor_tests/osm_feature_matcher_test.cpp index d0a8361b6c..8299ca4754 100644 --- a/editor/editor_tests/osm_feature_matcher_test.cpp +++ b/editor/editor_tests/osm_feature_matcher_test.cpp @@ -263,6 +263,8 @@ char const * const osmRawResponseRelation = R"SEP( )SEP"; } // namespace +// Note: Geometry should not contain duplicates. + UNIT_TEST(GetBestOsmNode_Test) { { @@ -277,8 +279,8 @@ UNIT_TEST(GetBestOsmNode_Test) pugi::xml_document osmResponse; TEST(osmResponse.load_buffer(osmRawResponseNode, ::strlen(osmRawResponseNode)), ()); - auto const bestNode = osm::GetBestOsmNode(osmResponse, ms::LatLon(53.8978398, 27.5579251)); - TEST(bestNode, ()); + auto const bestNode = osm::GetBestOsmNode(osmResponse, ms::LatLon(53.8977254, 27.5578377)); + TEST_EQUAL(bestNode.attribute("id").value(), string("277172019"), ()); } } @@ -352,3 +354,64 @@ UNIT_TEST(GetBestOsmRealtion_Test) auto const bestWay = osm::GetBestOsmWayOrRelation(osmResponse, geometry); TEST_EQUAL(bestWay.attribute("id").value(), string("365808"), ()); } + +namespace +{ +char const * const osmResponseBuildingMiss = R"SEP( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +)SEP"; +} // namespace + +UNIT_TEST(HouseBuildingMiss_test) +{ + pugi::xml_document osmResponse; + TEST(osmResponse.load_buffer(osmResponseBuildingMiss, ::strlen(osmResponseBuildingMiss)), ()); + vector const geometry = { + {-0.2048121407986514, 60.333984198674443}, + {-0.20478800091734684, 60.333909096821458}, + {-0.20465925488366565, 60.334029796228037}, + {-0.20463511500236109, 60.333954694375052}, + }; + + auto const bestWay = osm::GetBestOsmWayOrRelation(osmResponse, geometry); + TEST_EQUAL(bestWay.attribute("id").value(), string("345630019"), ()); +} diff --git a/editor/osm_feature_matcher.cpp b/editor/osm_feature_matcher.cpp index fac7dc7305..fe421ba47e 100644 --- a/editor/osm_feature_matcher.cpp +++ b/editor/osm_feature_matcher.cpp @@ -11,7 +11,7 @@ namespace osm { using editor::XMLFeature; -constexpr double kPointDiffEps = MercatorBounds::GetCellID2PointAbsEpsilon(); +constexpr double kPointDiffEps = 1e-5; bool PointsEqual(m2::PointD const & a, m2::PointD const & b) {