From 4cfe13d92b8821634d8c7be17c090e3c20a0e21a Mon Sep 17 00:00:00 2001 From: Olga Khlopkova Date: Fri, 11 Dec 2020 17:21:50 +0300 Subject: [PATCH] [routing] Added AStarSubProgress for RegionsRouter. --- routing/regions_router.cpp | 24 ++++++++++++++++++------ routing/regions_router.hpp | 4 +++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/routing/regions_router.cpp b/routing/regions_router.cpp index e427dce950..561c32c45f 100644 --- a/routing/regions_router.cpp +++ b/routing/regions_router.cpp @@ -8,6 +8,8 @@ #include "routing_common/car_model.hpp" +#include "base/scope_guard.hpp" + namespace routing { RegionsRouter::RegionsRouter(CountryFileGetterFn const & countryFileGetter, @@ -36,13 +38,21 @@ RouterResultCode RegionsRouter::ConvertResult( } RouterResultCode RegionsRouter::CalculateSubrouteNoLeapsMode(IndexGraphStarter & starter, - std::vector & subroute) + std::vector & subroute, + m2::PointD const & startCheckpoint, + m2::PointD const & finishCheckpoint) { using Vertex = IndexGraphStarter::Vertex; using Edge = IndexGraphStarter::Edge; using Weight = IndexGraphStarter::Weight; + double constexpr almostZeroContribution = 1e-7; auto progress = std::make_shared(); + AStarSubProgress subProgress(mercator::ToLatLon(startCheckpoint), + mercator::ToLatLon(finishCheckpoint), almostZeroContribution); + + progress->AppendSubProgress(subProgress); + SCOPE_GUARD(eraseProgress, [&progress]() { progress->PushAndDropLastSubProgress(); }); using Visitor = JunctionVisitor; uint32_t constexpr kVisitPeriod = 40; @@ -106,20 +116,22 @@ void RegionsRouter::Do() std::vector subroute; - auto const result = CalculateSubrouteNoLeapsMode(subrouteStarter, subroute); + auto const result = CalculateSubrouteNoLeapsMode( + subrouteStarter, subroute, m_checkpoints.GetPoint(i), m_checkpoints.GetPoint(i + 1)); if (result != RouterResultCode::NoError) - { - m_mwmNames.clear(); return; - } for (auto const & s : subroute) { - for (bool front : {true, false}) + for (bool front : {false, true}) { LatLonWithAltitude const & point = subrouteStarter.GetJunction(s, front); std::string name = m_countryFileGetterFn(mercator::FromLatLon(point.GetLatLon())); + + if (name.empty() && !IndexGraphStarter::IsFakeSegment(s)) + name = m_numMwmIds->GetFile(s.GetMwmId()).GetName(); + m_mwmNames.emplace(name); } } diff --git a/routing/regions_router.hpp b/routing/regions_router.hpp index 90f86a0f54..9d37463816 100644 --- a/routing/regions_router.hpp +++ b/routing/regions_router.hpp @@ -42,7 +42,9 @@ private: typename AStarAlgorithm::Result result) const; RouterResultCode CalculateSubrouteNoLeapsMode(IndexGraphStarter & starter, - std::vector & subroute); + std::vector & subroute, + m2::PointD const & startCheckpoint, + m2::PointD const & finishCheckpoint); // Gets checkpoint with |index| from |m_checkpoints| and returns its location and mwm number. std::pair GetCheckpointRegion(size_t index) const;