diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index 61d70a9edc..cab2758094 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -1,4 +1,5 @@ #include "routing/bicycle_directions.hpp" +#include "routing/routing_helpers.hpp" #include "routing/num_mwm_id.hpp" #include "routing/road_point.hpp" #include "routing/router_delegate.hpp" @@ -293,16 +294,6 @@ void BicycleDirectionsEngine::GetUniNodeIdAndAdjacentEdges(IRoadGraph::TEdgeVect } } -Segment BicycleDirectionsEngine::GetSegment(FeatureID const & featureId, uint32_t segId, bool forward) const -{ - auto info = featureId.m_mwmId.GetInfo(); - if (!info) - MYTHROW(RoutingException, ("Mwm:", featureId.m_mwmId, "is not alive.")); - - NumMwmId const numMwmId = m_numMwmIds->GetId(info->GetLocalFile().GetCountryFile()); - return Segment(numMwmId, featureId.m_index, segId, forward); -} - void BicycleDirectionsEngine::GetEdges(RoadGraphBase const & graph, Junction const & currJunction, bool isCurrJunctionFinish, IRoadGraph::TEdgeVector & outgoing, IRoadGraph::TEdgeVector & ingoing) @@ -345,16 +336,14 @@ void BicycleDirectionsEngine::FillPathSegmentsAndAdjacentEdgesMap( // It happens for example near starts and a finishes. FeatureID const & inFeatureId = inEdge.GetFeatureId(); uint32_t const inSegId = inEdge.GetSegId(); - bool const inIsForward = inEdge.IsForward(); if (startSegId == kInvalidSegId) startSegId = inSegId; prevJunctions.push_back(prevJunction); - if (inEdge.IsFake()) - prevSegments.push_back(Segment()); // Fake segment - else - prevSegments.push_back(GetSegment(inFeatureId, inSegId, inIsForward)); + Segment segment; + EdgeToSegment(*m_numMwmIds, inEdge, segment); + prevSegments.push_back(segment); if (!IsJoint(ingoingEdges, outgoingEdges, inEdge, routeEdges[i], isCurrJunctionFinish, inFeatureId.IsValid())) diff --git a/routing/bicycle_directions.hpp b/routing/bicycle_directions.hpp index 323a485369..5daf7eddae 100644 --- a/routing/bicycle_directions.hpp +++ b/routing/bicycle_directions.hpp @@ -47,8 +47,6 @@ private: IRoadGraph::TEdgeVector const & routeEdges, my::Cancellable const & cancellable); - Segment GetSegment(FeatureID const & featureId, uint32_t segId, bool forward) const; - void GetEdges(RoadGraphBase const & graph, Junction const & currJunction, bool isCurrJunctionFinish, IRoadGraph::TEdgeVector & outgoing, IRoadGraph::TEdgeVector & ingoing); diff --git a/routing/pedestrian_directions.cpp b/routing/pedestrian_directions.cpp index 81954f791f..9657b2c054 100644 --- a/routing/pedestrian_directions.cpp +++ b/routing/pedestrian_directions.cpp @@ -38,7 +38,7 @@ void PedestrianDirectionsEngine::Generate(RoadGraphBase const & graph, my::Cancellable const & cancellable, Route::TTimes & times, Route::TTurns & turns, vector & routeGeometry, - vector & /* segments */) + vector & segments) { times.clear(); turns.clear(); diff --git a/routing/pedestrian_directions.hpp b/routing/pedestrian_directions.hpp index 4a3fda5dd8..977b1e709f 100644 --- a/routing/pedestrian_directions.hpp +++ b/routing/pedestrian_directions.hpp @@ -13,7 +13,7 @@ public: // IDirectionsEngine override: void Generate(RoadGraphBase const & graph, vector const & path, my::Cancellable const & cancellable, Route::TTimes & times, Route::TTurns & turns, - vector & routeGeometry, vector & /* segments */) override; + vector & routeGeometry, vector & segments) override; private: void CalculateTurns(RoadGraphBase const & graph, vector const & routeEdges, diff --git a/routing/routing_helpers.cpp b/routing/routing_helpers.cpp index f369cb6c9f..d27f4f14c6 100644 --- a/routing/routing_helpers.cpp +++ b/routing/routing_helpers.cpp @@ -85,4 +85,17 @@ void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, route.SetTraffic(move(traffic)); } + +void EdgeToSegment(NumMwmIds const & numMwmIds, Edge const & edge, Segment & segment) +{ + if (edge.IsFake()) + { + segment = Segment(); + return; + } + + NumMwmId const numMwmId = + numMwmIds.GetId(edge.GetFeatureId().m_mwmId.GetInfo()->GetLocalFile().GetCountryFile()); + segment = Segment(numMwmId, edge.GetFeatureId().m_index, edge.GetSegId(), edge.IsForward()); +} } // namespace rouing diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index 4d5024ffee..31bb2b87fc 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -34,6 +34,10 @@ void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, my::Cancellable const & cancellable, bool hasAltitude, vector & path, Route & route); +/// \brief Converts |edge| to |segment|. +/// \returns false if mwm of |edge| is not alive. +void EdgeToSegment(NumMwmIds const & numMwmIds, Edge const & edge, Segment & segment); + /// \brief Checks is edge connected with world graph. Function does BFS while it finds some number /// of edges, /// if graph ends before this number is reached then junction is assumed as not connected to the diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index 7f3121990a..69ac602635 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -258,7 +258,7 @@ IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, vector & junctions, Route::TTurns & turnsDir, Route::TTimes & times, Route::TStreets & streets, - vector & trafficSegs) + vector & segments) { double estimatedTime = 0; @@ -273,7 +273,7 @@ IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, // Annotate turns. size_t skipTurnSegments = 0; auto const & loadedSegments = result.GetSegments(); - trafficSegs.reserve(loadedSegments.size()); + segments.reserve(loadedSegments.size()); for (auto loadedSegmentIt = loadedSegments.cbegin(); loadedSegmentIt != loadedSegments.cend(); ++loadedSegmentIt) { @@ -336,8 +336,8 @@ IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, ? loadedSegmentIt->m_path.cbegin() : loadedSegmentIt->m_path.cbegin() + 1, loadedSegmentIt->m_path.cend()); - trafficSegs.insert(trafficSegs.end(), loadedSegmentIt->m_trafficSegs.cbegin(), - loadedSegmentIt->m_trafficSegs.cend()); + segments.insert(segments.end(), loadedSegmentIt->m_trafficSegs.cbegin(), + loadedSegmentIt->m_trafficSegs.cend()); } // Path found. Points will be replaced by start and end edges junctions. diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index 7dda0685bd..76dcc62923 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -51,7 +51,7 @@ IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, vector & points, Route::TTurns & turnsDir, Route::TTimes & times, Route::TStreets & streets, - vector & trafficSegs); + vector & segments); /*! * \brief The TurnInfo struct is a representation of a junction.