From 5e17cdbe67f7b7ff72462995f99c25c6a1702e61 Mon Sep 17 00:00:00 2001 From: Mikhail Gorbushin Date: Mon, 12 Aug 2019 19:20:28 +0300 Subject: [PATCH] [routing] Changed IndexRouter::AreMwmsNear In previous version start and finish could have only one mwm related to them, but after adding several fake segments, start and finish could be linked with different mwms, because of that AreMwmsNear returns false when start or finish placed near mwm's border. Because of that LeapsOnly is chosen instead of Joints mode. --- routing/index_router.cpp | 27 ++++++++++++------- routing/index_router.hpp | 2 +- .../routing_integration_tests/route_test.cpp | 10 +++++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 441820cf1a..2835ea4892 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -560,8 +560,8 @@ RouterResultCode IndexRouter::CalculateSubroute(Checkpoints const & checkpoints, starter.GetGraph().SetMode(WorldGraphMode::NoLeaps); break; case VehicleType::Car: - starter.GetGraph().SetMode(AreMwmsNear(starter.GetMwms()) ? WorldGraphMode::Joints - : WorldGraphMode::LeapsOnly); + starter.GetGraph().SetMode(AreMwmsNear(starter) ? WorldGraphMode::Joints + : WorldGraphMode::LeapsOnly); break; case VehicleType::Count: CHECK(false, ("Unknown vehicle type:", m_vehicleType)); @@ -1365,17 +1365,24 @@ RouterResultCode IndexRouter::RedressRoute(vector const & segments, return RouterResultCode::NoError; } -bool IndexRouter::AreMwmsNear(set const & mwmIds) const +bool IndexRouter::AreMwmsNear(IndexGraphStarter const & starter) const { - for (auto const & outerId : mwmIds) + auto const & startMwmIds = starter.GetStartMwms(); + auto const & finishMwmIds = starter.GetFinishMwms(); + for (auto const startMwmId : startMwmIds) { - m2::RectD const rect = m_countryRectFn(m_numMwmIds->GetFile(outerId).GetName()); - size_t found = 0; - m_numMwmTree->ForEachInRect(rect, [&](NumMwmId id) { found += mwmIds.count(id); }); - if (found != mwmIds.size()) - return false; + m2::RectD const & rect = m_countryRectFn(m_numMwmIds->GetFile(startMwmId).GetName()); + bool found = false; + m_numMwmTree->ForEachInRect(rect, + [&finishMwmIds, &found](NumMwmId id) { + if (!found && finishMwmIds.count(id) > 0) + found = true; + }); + if (found) + return true; } - return true; + + return false; } bool IndexRouter::DoesTransitSectionExist(NumMwmId numMwmId) const diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 17854550a6..3cafe9057b 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -153,7 +153,7 @@ private: RouterDelegate const & delegate, IndexGraphStarter & starter, Route & route) const; - bool AreMwmsNear(std::set const & mwmIds) const; + bool AreMwmsNear(IndexGraphStarter const & starter) const; bool DoesTransitSectionExist(NumMwmId numMwmId) const; RouterResultCode ConvertTransitResult(std::set const & mwmIds, diff --git a/routing/routing_integration_tests/route_test.cpp b/routing/routing_integration_tests/route_test.cpp index 682f36b11a..84570803d6 100644 --- a/routing/routing_integration_tests/route_test.cpp +++ b/routing/routing_integration_tests/route_test.cpp @@ -559,4 +559,14 @@ namespace TEST_EQUAL(route.second, RouterResultCode::NoError, ()); } + + UNIT_TEST(AreMwmsNear_HelsinkiPiter) + { + TRouteResult route = + integration::CalculateRoute(integration::GetVehicleComponents(VehicleType::Car), + MercatorBounds::FromLatLon(60.87083, 26.53612), {0., 0.}, + MercatorBounds::FromLatLon(60.95360, 28.53979)); + + TEST_EQUAL(route.second, RouterResultCode::NoError, ()); + } } // namespace