diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index 50bdd16888..1d86df5670 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -29,7 +29,6 @@ set( cross_mwm_graph.hpp cross_mwm_ids.hpp cross_mwm_index_graph.hpp - directions_engine.cpp directions_engine.hpp edge_estimator.cpp edge_estimator.hpp diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index 5822077014..362d52741d 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -164,7 +164,7 @@ BicycleDirectionsEngine::BicycleDirectionsEngine(Index const & index, shared_ptr CHECK(m_numMwmIds, ()); } -bool BicycleDirectionsEngine::Generate(RoadGraphBase const & graph, vector const & path, +bool BicycleDirectionsEngine::Generate(IndexRoadGraph const & graph, vector const & path, my::Cancellable const & cancellable, Route::TTurns & turns, Route::TStreets & streetNames, vector & routeGeometry, vector & segments) @@ -178,15 +178,11 @@ bool BicycleDirectionsEngine::Generate(RoadGraphBase const & graph, vector const & path, + IndexRoadGraph const & graph, vector const & path, IRoadGraph::TEdgeVector const & routeEdges, my::Cancellable const & cancellable) { size_t const pathSize = path.size(); diff --git a/routing/bicycle_directions.hpp b/routing/bicycle_directions.hpp index 897cbbc441..8f223d8323 100644 --- a/routing/bicycle_directions.hpp +++ b/routing/bicycle_directions.hpp @@ -30,7 +30,7 @@ public: BicycleDirectionsEngine(Index const & index, std::shared_ptr numMwmIds); // IDirectionsEngine override: - bool Generate(RoadGraphBase const & graph, vector const & path, + bool Generate(IndexRoadGraph const & graph, vector const & path, my::Cancellable const & cancellable, Route::TTurns & turns, Route::TStreets & streetNames, vector & routeGeometry, vector & segments) override; @@ -44,7 +44,7 @@ private: turns::TurnCandidates & outgoingTurns); /// \brief The method gathers sequence of segments according to IsJoint() method /// and fills |m_adjacentEdges| and |m_pathSegments|. - void FillPathSegmentsAndAdjacentEdgesMap(RoadGraphBase const & graph, + void FillPathSegmentsAndAdjacentEdgesMap(IndexRoadGraph const & graph, std::vector const & path, IRoadGraph::TEdgeVector const & routeEdges, my::Cancellable const & cancellable); diff --git a/routing/directions_engine.cpp b/routing/directions_engine.cpp deleted file mode 100644 index 17503b2cac..0000000000 --- a/routing/directions_engine.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "routing/directions_engine.hpp" - -#include "geometry/mercator.hpp" - -#include "base/assert.hpp" - -namespace routing -{ -bool IDirectionsEngine::ReconstructPath(RoadGraphBase const & graph, vector const & path, - vector & routeEdges, - my::Cancellable const & cancellable) const -{ - routeEdges.clear(); - if (path.size() <= 1) - return false; - - if (graph.IsRouteEdgesImplemented()) - { - graph.GetRouteEdges(routeEdges); - ASSERT_EQUAL(routeEdges.size() + 1, path.size(), ()); - return true; - } - - routeEdges.reserve(path.size() - 1); - - Junction curr = path[0]; - vector currEdges; - for (size_t i = 1; i < path.size(); ++i) - { - if (cancellable.IsCancelled()) - return false; - - Junction const & next = path[i]; - - currEdges.clear(); - graph.GetOutgoingEdges(curr, currEdges); - - bool found = false; - for (auto const & e : currEdges) - { - if (AlmostEqualAbs(e.GetEndJunction(), next)) - { - routeEdges.emplace_back(e); - found = true; - break; - } - } - - if (!found) - { - LOG(LERROR, ("Can't find next edge, curr:", MercatorBounds::ToLatLon(curr.GetPoint()), - ", next:", MercatorBounds::ToLatLon(next.GetPoint()), ", edges size:", - currEdges.size(), ", i:", i)); - return false; - } - - curr = next; - } - - ASSERT_EQUAL(routeEdges.size() + 1, path.size(), ()); - - return true; -} -} // namespace routing diff --git a/routing/directions_engine.hpp b/routing/directions_engine.hpp index 274a5985cc..33d65bda0c 100644 --- a/routing/directions_engine.hpp +++ b/routing/directions_engine.hpp @@ -1,6 +1,6 @@ #pragma once -#include "routing/road_graph.hpp" +#include "routing/index_road_graph.hpp" #include "routing/road_point.hpp" #include "routing/route.hpp" #include "routing/segment.hpp" @@ -18,22 +18,14 @@ class IDirectionsEngine public: virtual ~IDirectionsEngine() = default; - // @TODO(bykoianko) When fields |m_turns|, |m_times|, |m_streets| and |m_traffic| - // are removed from class Route the method Generate() should fill + // @TODO(bykoianko) Method Generate() should fill // vector instead of corresponding arguments. /// \brief Generates all args which are passed by reference. /// \param path is points of the route. It should not be empty. /// \returns true if fields passed by reference are filled correctly and false otherwise. - virtual bool Generate(RoadGraphBase const & graph, vector const & path, + virtual bool Generate(IndexRoadGraph const & graph, vector const & path, my::Cancellable const & cancellable, Route::TTurns & turns, Route::TStreets & streetNames, vector & routeGeometry, vector & segments) = 0; - -protected: - /// \brief constructs route based on |graph| and |path|. Fills |routeEdges| with the route. - /// \returns false in case of any errors while reconstruction, if reconstruction process - /// was cancelled and in case of extremely short paths of 0 or 1 point. Returns true otherwise. - bool ReconstructPath(RoadGraphBase const & graph, std::vector const & path, - std::vector & routeEdges, my::Cancellable const & cancellable) const; }; } // namespace routing diff --git a/routing/index_road_graph.hpp b/routing/index_road_graph.hpp index e425e5efa2..555367bb15 100644 --- a/routing/index_road_graph.hpp +++ b/routing/index_road_graph.hpp @@ -35,7 +35,6 @@ public: private: void GetEdges(Junction const & junction, bool isOutgoing, TEdgeVector & edges) const; - Junction const & GetJunction(Segment const & segment, bool front) const; std::vector const & GetSegments(Junction const & junction, bool isOutgoing) const; Index & m_index; diff --git a/routing/pedestrian_directions.cpp b/routing/pedestrian_directions.cpp index 855f36a202..2631be0a30 100644 --- a/routing/pedestrian_directions.cpp +++ b/routing/pedestrian_directions.cpp @@ -39,7 +39,7 @@ PedestrianDirectionsEngine::PedestrianDirectionsEngine(shared_ptr num { } -bool PedestrianDirectionsEngine::Generate(RoadGraphBase const & graph, +bool PedestrianDirectionsEngine::Generate(IndexRoadGraph const & graph, vector const & path, my::Cancellable const & cancellable, Route::TTurns & turns, Route::TStreets & streetNames, @@ -52,15 +52,11 @@ bool PedestrianDirectionsEngine::Generate(RoadGraphBase const & graph, routeGeometry = path; // Note. According to Route::IsValid() method route of zero or one point is invalid. - if (path.size() < 1) + if (path.size() <= 1) return false; vector routeEdges; - if (!ReconstructPath(graph, path, routeEdges, cancellable)) - { - LOG(LWARNING, ("Can't reconstruct path.")); - return false; - } + graph.GetRouteEdges(routeEdges); CalculateTurns(graph, routeEdges, turns, cancellable); @@ -78,7 +74,7 @@ bool PedestrianDirectionsEngine::Generate(RoadGraphBase const & graph, return true; } -void PedestrianDirectionsEngine::CalculateTurns(RoadGraphBase const & graph, +void PedestrianDirectionsEngine::CalculateTurns(IndexRoadGraph const & graph, vector const & routeEdges, Route::TTurns & turns, my::Cancellable const & cancellable) const diff --git a/routing/pedestrian_directions.hpp b/routing/pedestrian_directions.hpp index 7192ac8587..d772513483 100644 --- a/routing/pedestrian_directions.hpp +++ b/routing/pedestrian_directions.hpp @@ -15,13 +15,13 @@ public: PedestrianDirectionsEngine(std::shared_ptr numMwmIds); // IDirectionsEngine override: - bool Generate(RoadGraphBase const & graph, vector const & path, + bool Generate(IndexRoadGraph const & graph, vector const & path, my::Cancellable const & cancellable, Route::TTurns & turns, Route::TStreets & streetNames, vector & routeGeometry, vector & segments) override; private: - void CalculateTurns(RoadGraphBase const & graph, std::vector const & routeEdges, + void CalculateTurns(IndexRoadGraph const & graph, std::vector const & routeEdges, Route::TTurns & turnsDir, my::Cancellable const & cancellable) const; uint32_t const m_typeSteps; diff --git a/routing/routing_helpers.cpp b/routing/routing_helpers.cpp index fbeb29a25d..295a7ceb69 100644 --- a/routing/routing_helpers.cpp +++ b/routing/routing_helpers.cpp @@ -98,7 +98,7 @@ void FillSegmentInfo(vector const & segments, vector const & } } -void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, +void ReconstructRoute(IDirectionsEngine & engine, IndexRoadGraph const & graph, shared_ptr const & trafficStash, my::Cancellable const & cancellable, vector const & path, Route::TTimes && times, Route & route) diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index 734c442dec..acf92e4f7d 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -1,7 +1,7 @@ #pragma once #include "routing/directions_engine.hpp" -#include "routing/road_graph.hpp" +#include "routing/index_road_graph.hpp" #include "routing/route.hpp" #include "routing/traffic_stash.hpp" @@ -34,7 +34,7 @@ void FillSegmentInfo(std::vector const & segments, std::vector const & trafficStash, std::vector & routeSegment); -void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, +void ReconstructRoute(IDirectionsEngine & engine, IndexRoadGraph const & graph, std::shared_ptr const & trafficStash, my::Cancellable const & cancellable, std::vector const & path, Route::TTimes && times, Route & route);