diff --git a/routing/directions_engine.cpp b/routing/directions_engine.cpp index 0aa6b0e07b..cf20d4faec 100644 --- a/routing/directions_engine.cpp +++ b/routing/directions_engine.cpp @@ -1,5 +1,7 @@ #include "routing/directions_engine.hpp" +#include "geometry/mercator.hpp" + #include "base/assert.hpp" namespace @@ -78,7 +80,12 @@ bool IDirectionsEngine::ReconstructPath(RoadGraphBase const & graph, vector(m_numMwmIds, m_indexManager), IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index), m_estimator); - - if (blockMwmBorders) - graph.CloseBorders(); + graph.SetMode(forSingleMwm ? WorldGraph::Mode::SingleMwm : WorldGraph::Mode::WorldWithLeaps); IndexGraphStarter starter(start, finish, graph); @@ -171,7 +171,7 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute( CHECK_GREATER_OR_EQUAL(segments.size(), routingResult.path.size(), ()); - if (!RedressRoute(segments, delegate, starter, route)) + if (!RedressRoute(segments, delegate, forSingleMwm, starter, route)) return IRouter::InternalError; if (delegate.IsCancelled()) return IRouter::Cancelled; @@ -224,7 +224,7 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector const & input, output.reserve(input.size()); WorldGraph & worldGraph = starter.GetGraph(); - worldGraph.CloseBorders(); + worldGraph.SetMode(WorldGraph::Mode::SingleMwm); for (size_t i = 0; i < input.size(); ++i) { @@ -271,7 +271,7 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector const & input, } bool IndexRouter::RedressRoute(vector const & segments, RouterDelegate const & delegate, - IndexGraphStarter & starter, Route & route) const + bool forSingleMwm, IndexGraphStarter & starter, Route & route) const { vector junctions; size_t const numPoints = IndexGraphStarter::GetRouteNumPoints(segments); @@ -284,7 +284,8 @@ bool IndexRouter::RedressRoute(vector const & segments, RouterDelegate } IndexRoadGraph roadGraph(m_numMwmIds, starter, segments, junctions, m_index); - starter.GetGraph().OpenBorders(); + if (!forSingleMwm) + starter.GetGraph().SetMode(WorldGraph::Mode::WorldWithoutLeaps); CHECK(m_directionsEngine, ()); ReconstructRoute(*m_directionsEngine, roadGraph, m_trafficStash, delegate, junctions, route); diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 50f9ecc7b3..0c71d2647d 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -54,12 +54,12 @@ public: private: IRouter::ResultCode CalculateRoute(string const & startCountry, string const & finishCountry, - bool blockMwmBorders, m2::PointD const & startPoint, + bool forSingleMwm, m2::PointD const & startPoint, m2::PointD const & startDirection, m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route); IRouter::ResultCode DoCalculateRoute(string const & startCountry, string const & finishCountry, - bool blockMwmBorders, m2::PointD const & startPoint, + bool forSingleMwm, m2::PointD const & startPoint, m2::PointD const & startDirection, m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route); @@ -70,7 +70,7 @@ private: IRouter::ResultCode ProcessLeaps(vector const & input, RouterDelegate const & delegate, IndexGraphStarter & starter, vector & output); bool RedressRoute(vector const & segments, RouterDelegate const & delegate, - IndexGraphStarter & starter, Route & route) const; + bool forSingleMwm, IndexGraphStarter & starter, Route & route) const; string const m_name; Index & m_index; diff --git a/routing/world_graph.cpp b/routing/world_graph.cpp index 0546699eb6..a696f00876 100644 --- a/routing/world_graph.cpp +++ b/routing/world_graph.cpp @@ -15,8 +15,9 @@ WorldGraph::WorldGraph(unique_ptr crossMwmGraph, void WorldGraph::GetEdgeList(Segment const & segment, bool isOutgoing, bool isLeap, vector & edges) { - if (m_crossMwmGraph && m_bordersAreOpened && isLeap) + if (isLeap && m_mode == Mode::WorldWithLeaps) { + CHECK(m_crossMwmGraph, ()); if (m_crossMwmGraph->IsTransition(segment, isOutgoing)) GetTwins(segment, isOutgoing, edges); else @@ -27,8 +28,12 @@ void WorldGraph::GetEdgeList(Segment const & segment, bool isOutgoing, bool isLe IndexGraph & indexGraph = GetIndexGraph(segment.GetMwmId()); indexGraph.GetEdgeList(segment, isOutgoing, edges); - if (m_crossMwmGraph && m_bordersAreOpened && m_crossMwmGraph->IsTransition(segment, isOutgoing)) - GetTwins(segment, isOutgoing, edges); + if (m_mode != Mode::SingleMwm) + { + CHECK(m_crossMwmGraph, ()); + if (m_crossMwmGraph->IsTransition(segment, isOutgoing)) + GetTwins(segment, isOutgoing, edges); + } } m2::PointD const & WorldGraph::GetPoint(Segment const & segment, bool front) diff --git a/routing/world_graph.hpp b/routing/world_graph.hpp index 9ff880111b..2b0ca9a002 100644 --- a/routing/world_graph.hpp +++ b/routing/world_graph.hpp @@ -16,6 +16,13 @@ namespace routing class WorldGraph final { public: + enum class Mode + { + SingleMwm, + WorldWithLeaps, + WorldWithoutLeaps, + }; + WorldGraph(std::unique_ptr crossMwmGraph, std::unique_ptr loader, std::shared_ptr estimator); @@ -28,12 +35,9 @@ public: m2::PointD const & GetPoint(Segment const & segment, bool front); RoadGeometry const & GetRoadGeometry(NumMwmId mwmId, uint32_t featureId); - // Disable edges between mwms. - void CloseBorders() { m_bordersAreOpened = false; } - // Enable edges between mwms. - void OpenBorders() { m_bordersAreOpened = true; } // Clear memory used by loaded index graphs. void ClearIndexGraphs() { m_loader->Clear(); } + void SetMode(Mode mode) { m_mode = mode; } private: void GetTwins(Segment const & s, bool isOutgoing, std::vector & edges); @@ -42,6 +46,6 @@ private: std::unique_ptr m_loader; std::shared_ptr m_estimator; std::vector m_twins; - bool m_bordersAreOpened = true; + Mode m_mode = Mode::SingleMwm; }; } // namespace routing