diff --git a/routing/index_road_graph.cpp b/routing/index_road_graph.cpp index 94a7b1454c..bcb377f1ea 100644 --- a/routing/index_road_graph.cpp +++ b/routing/index_road_graph.cpp @@ -80,6 +80,8 @@ bool IndexRoadGraph::IsRouteEdgesImplemented() const return true; } +bool IndexRoadGraph::IsRouteSegmentsImplemented() const { return true; } + void IndexRoadGraph::GetRouteEdges(TEdgeVector & edges) const { edges.clear(); @@ -101,6 +103,8 @@ void IndexRoadGraph::GetRouteEdges(TEdgeVector & edges) const } } +vector const & IndexRoadGraph::GetRouteSegments() const { return m_segments; } + void IndexRoadGraph::GetEdges(Junction const & junction, bool isOutgoing, TEdgeVector & edges) const { edges.clear(); diff --git a/routing/index_road_graph.hpp b/routing/index_road_graph.hpp index e8ef441de6..83df6cd99b 100644 --- a/routing/index_road_graph.hpp +++ b/routing/index_road_graph.hpp @@ -29,8 +29,9 @@ public: virtual void GetJunctionTypes(Junction const & junction, feature::TypesHolder & types) const override; virtual bool IsRouteEdgesImplemented() const override; + virtual bool IsRouteSegmentsImplemented() const override; virtual void GetRouteEdges(TEdgeVector & edges) const override; - + virtual std::vector const & GetRouteSegments() const override; private: void GetEdges(Junction const & junction, bool isOutgoing, TEdgeVector & edges) const; diff --git a/routing/pedestrian_directions.cpp b/routing/pedestrian_directions.cpp index 9ed8d22c33..29177e342d 100644 --- a/routing/pedestrian_directions.cpp +++ b/routing/pedestrian_directions.cpp @@ -64,10 +64,17 @@ bool PedestrianDirectionsEngine::Generate(RoadGraphBase const & graph, CalculateTurns(graph, routeEdges, turns, cancellable); - segments.reserve(routeEdges.size()); - for (Edge const & e : routeEdges) - segments.push_back(ConvertEdgeToSegment(*m_numMwmIds, e)); - + if (graph.IsRouteSegmentsImplemented()) + { + segments = graph.GetRouteSegments(); + } + else + { + segments.reserve(routeEdges.size()); + for (Edge const & e : routeEdges) + segments.push_back(ConvertEdgeToSegment(*m_numMwmIds, e)); + } + return true; } diff --git a/routing/road_graph.cpp b/routing/road_graph.cpp index af70d082d3..9155437efc 100644 --- a/routing/road_graph.cpp +++ b/routing/road_graph.cpp @@ -11,9 +11,11 @@ #include "base/math.hpp" #include "base/stl_helpers.hpp" -#include "std/algorithm.hpp" -#include "std/limits.hpp" -#include "std/sstream.hpp" +#include +#include +#include + +using namespace std; namespace routing { @@ -297,13 +299,17 @@ IRoadGraph::RoadInfo MakeRoadInfoForTesting(bool bidirectional, double speedKMPH return ri; } // RoadGraphBase ------------------------------------------------------------------ -bool RoadGraphBase::IsRouteEdgesImplemented() const -{ - return false; -} +bool RoadGraphBase::IsRouteEdgesImplemented() const { return false; } + +bool RoadGraphBase::IsRouteSegmentsImplemented() const { return false; } void RoadGraphBase::GetRouteEdges(TEdgeVector & routeEdges) const { NOTIMPLEMENTED() } + +vector const & RoadGraphBase::GetRouteSegments() const +{ + NOTIMPLEMENTED() +} } // namespace routing diff --git a/routing/road_graph.hpp b/routing/road_graph.hpp index 25c6799934..d32573347b 100644 --- a/routing/road_graph.hpp +++ b/routing/road_graph.hpp @@ -1,5 +1,7 @@ #pragma once +#include "routing/segment.hpp" + #include "geometry/point2d.hpp" #include "base/string_utils.hpp" @@ -7,9 +9,9 @@ #include "indexer/feature_altitude.hpp" #include "indexer/feature_data.hpp" -#include "std/initializer_list.hpp" -#include "std/map.hpp" -#include "std/vector.hpp" +#include +#include +#include namespace routing { @@ -130,9 +132,13 @@ public: /// @return Types for specified junction virtual void GetJunctionTypes(Junction const & junction, feature::TypesHolder & types) const = 0; + // TODO: remove IsRouteEdgesImplemented and IsRouteSegmentsImplemented as soon as we get rid of + // IRoadGraph and RoadGraphRouter virtual bool IsRouteEdgesImplemented() const; + virtual bool IsRouteSegmentsImplemented() const; virtual void GetRouteEdges(TEdgeVector & routeEdges) const; + virtual std::vector const & GetRouteSegments() const; }; class IRoadGraph : public RoadGraphBase @@ -155,7 +161,7 @@ public: { RoadInfo(); RoadInfo(RoadInfo && ri); - RoadInfo(bool bidirectional, double speedKMPH, initializer_list const & points); + RoadInfo(bool bidirectional, double speedKMPH, std::initializer_list const & points); RoadInfo(RoadInfo const &) = default; RoadInfo & operator=(RoadInfo const &) = default; @@ -296,7 +302,7 @@ public: void GetFakeIngoingEdges(Junction const & junction, TEdgeVector & edges) const; private: - void AddEdge(Junction const & j, Edge const & e, map & edges); + void AddEdge(Junction const & j, Edge const & e, std::map & edges); template void ForEachFakeEdge(Fn && fn) @@ -316,14 +322,14 @@ private: /// \note |m_fakeIngoingEdges| and |m_fakeOutgoingEdges| map junctions to sorted vectors. /// Items to these maps should be inserted with AddEdge() method only. - map m_fakeIngoingEdges; - map m_fakeOutgoingEdges; + std::map m_fakeIngoingEdges; + std::map m_fakeOutgoingEdges; }; string DebugPrint(IRoadGraph::Mode mode); IRoadGraph::RoadInfo MakeRoadInfoForTesting(bool bidirectional, double speedKMPH, - initializer_list const & points); + std::initializer_list const & points); inline void JunctionsToPoints(vector const & junctions, vector & points) {