From cc7b62615e8c8aabec1d76df6f61d05dda41bd52 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 2 May 2017 17:50:15 +0300 Subject: [PATCH] Review fixes. --- routing/index_graph_starter.hpp | 9 +++-- routing/index_router.cpp | 45 +++++++++++----------- routing/index_router.hpp | 11 ++---- routing/road_graph_router.cpp | 10 ++--- routing/routing_helpers.hpp | 1 - routing/routing_tests/index_graph_test.cpp | 6 ++- 6 files changed, 39 insertions(+), 43 deletions(-) diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index 4741cc5358..93e1edc6e4 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -23,15 +23,16 @@ public: class FakeVertex final { public: - FakeVertex(Segment const & segment, m2::PointD const & point) - : m_segment(segment), m_point(point) - { - } FakeVertex(NumMwmId mwmId, uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point) : m_segment(mwmId, featureId, segmentIdx, true /* forward */), m_point(point) { } + FakeVertex(Segment const & segment, m2::PointD const & point) + : m_segment(segment), m_point(point) + { + } + NumMwmId GetMwmId() const { return m_segment.GetMwmId(); } uint32_t GetFeatureId() const { return m_segment.GetFeatureId(); } m2::PointD const & GetPoint() const { return m_point; } diff --git a/routing/index_router.cpp b/routing/index_router.cpp index c2db21eeca..f8a1c1fb24 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -36,7 +36,7 @@ size_t constexpr kMaxRoadCandidates = 6; float constexpr kProgressInterval = 2; uint32_t constexpr kDrawPointsPeriod = 10; -bool IsDeadEnd(Segment const & segment, bool fromPoint, WorldGraph & worldGraph) +bool IsDeadEnd(Segment const & segment, bool isOutgoing, WorldGraph & worldGraph) { size_t constexpr kDeadEndTestLimit = 50; @@ -44,10 +44,11 @@ bool IsDeadEnd(Segment const & segment, bool fromPoint, WorldGraph & worldGraph) return edge.GetTarget(); }; - // Note. If |fromPoint| == true outgoing edges are looked for. - // If |fromPoint| == false it's the finish. So ingoing edges are looked for. - auto const getOutgoingEdgesFn = [fromPoint](WorldGraph & graph, Segment const & u, vector & edges){ - graph.GetEdgeList(u, fromPoint, false /* isLeap */, edges); + // Note. If |isOutgoing| == true outgoing edges are looked for. + // If |isOutgoing| == false it's the finish. So ingoing edges are looked for. + auto const getOutgoingEdgesFn = [isOutgoing](WorldGraph & graph, Segment const & u, + vector & edges) { + graph.GetEdgeList(u, isOutgoing, false /* isLeap */, edges); }; return !CheckGraphConnectivity(segment, kDeadEndTestLimit, worldGraph, @@ -137,25 +138,27 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, TrafficStash::Guard guard(*m_trafficStash); WorldGraph graph( - make_unique(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn, - m_index, m_indexManager), - IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index), - m_estimator); + make_unique(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn, + m_index, m_indexManager), + IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index), + m_estimator); Edge startEdge; - if (!FindClosestEdge(graph, startFile, startPoint, true /* fromPoint */, startEdge)) + if (!FindClosestEdge(startFile, startPoint, true /* isOutgoing */, graph, startEdge)) return IRouter::StartPointNotFound; Edge finishEdge; - if (!FindClosestEdge(graph, finishFile, finalPoint, false /* fromPoint */, finishEdge)) + if (!FindClosestEdge(finishFile, finalPoint, false /* isOutgoing */, graph, finishEdge)) return IRouter::EndPointNotFound; - IndexGraphStarter::FakeVertex const start(Segment(m_numMwmIds->GetId(startFile), - startEdge.GetFeatureId().m_index, startEdge.GetSegId(), true /* forward */), - startPoint); - IndexGraphStarter::FakeVertex const finish(Segment(m_numMwmIds->GetId(finishFile), - finishEdge.GetFeatureId().m_index, - finishEdge.GetSegId(), true /* forward */), finalPoint); + IndexGraphStarter::FakeVertex const start( + Segment(m_numMwmIds->GetId(startFile), startEdge.GetFeatureId().m_index, startEdge.GetSegId(), + true /* forward */), + startPoint); + IndexGraphStarter::FakeVertex const finish( + Segment(m_numMwmIds->GetId(finishFile), finishEdge.GetFeatureId().m_index, + finishEdge.GetSegId(), true /* forward */), + finalPoint); WorldGraph::Mode mode = WorldGraph::Mode::SingleMwm; if (forSingleMwm) @@ -213,10 +216,8 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, } } -bool IndexRouter::FindClosestEdge(WorldGraph & worldGraph, - platform::CountryFile const & file, - m2::PointD const & point, - bool fromPoint, +bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, + bool isOutgoing, WorldGraph & worldGraph, Edge & closestEdge) const { MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file); @@ -237,7 +238,7 @@ bool IndexRouter::FindClosestEdge(WorldGraph & worldGraph, Edge const & edge = candidates[i].first; Segment const segment(numMwmId, edge.GetFeatureId().m_index, edge.GetSegId(), edge.IsForward()); - if (edge.GetFeatureId().m_mwmId != mwmId || IsDeadEnd(segment, fromPoint, worldGraph)) + if (edge.GetFeatureId().m_mwmId != mwmId || IsDeadEnd(segment, isOutgoing, worldGraph)) continue; m2::DistanceToLineSquare squaredDistance; diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 1bb8c00b40..43875f9352 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -71,13 +71,10 @@ private: RouterDelegate const & delegate, Route & route); /// \brief Finds closest edges which may be considered as start of finish of the route. - /// \param fromPoint == true is |point| is considered as the start of the route. - /// fromPoint == false is |point| is considered as the finish of the route. - bool FindClosestEdge(WorldGraph & worldGraph, - platform::CountryFile const & file, - m2::PointD const & point, - bool fromPoint, - Edge & closestEdge) const; + /// \param isOutgoing == true is |point| is considered as the start of the route. + /// isOutgoing == false is |point| is considered as the finish of the route. + bool FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, + bool isOutgoing, WorldGraph & worldGraph, Edge & closestEdge) const; // Input route may contains 'leaps': shortcut edges from mwm border enter to exit. // ProcessLeaps replaces each leap with calculated route through mwm. IRouter::ResultCode ProcessLeaps(vector const & input, RouterDelegate const & delegate, diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 59371cbc78..97f7ae2bc2 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -81,13 +81,9 @@ void FindClosestEdges(IRoadGraph const & graph, m2::PointD const & point, for (auto const & candidate : candidates) { auto const & edge = candidate.first; - - auto const getVertexByEdgeFn = [](Edge const & edge) { - return edge.GetEndJunction(); - }; - auto const getOutgoingEdgesFn = [](IRoadGraph const & graph, Junction const & u, vector & edges){ - graph.GetOutgoingEdges(u, edges); - }; + auto const getVertexByEdgeFn = [](Edge const & edge) { return edge.GetEndJunction(); }; + auto const getOutgoingEdgesFn = [](IRoadGraph const & graph, Junction const & u, + vector & edges) { graph.GetOutgoingEdges(u, edges); }; if (CheckGraphConnectivity(edge.GetEndJunction(), kTestConnectivityVisitJunctionsLimit, graph, getVertexByEdgeFn, getOutgoingEdgesFn)) diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index 47c08ae4d7..4d5024ffee 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -34,7 +34,6 @@ void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, my::Cancellable const & cancellable, bool hasAltitude, vector & path, Route & route); - /// \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/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 586f2f0b73..1a996fe129 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -200,7 +200,8 @@ UNIT_TEST(FindPathCross) uint32_t expectedLength = 0; if (start.GetFeatureId() == finish.GetFeatureId()) { - expectedLength = AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()) + 1; + expectedLength = + AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()) + 1; } else { @@ -285,7 +286,8 @@ UNIT_TEST(FindPathManhattan) if (start.GetFeatureId() < kCitySize == finish.GetFeatureId() < kCitySize) { - uint32_t segDelta = AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()); + uint32_t segDelta = + AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()); if (segDelta == 0 && start.GetFeatureId() != finish.GetFeatureId()) segDelta = 1; expectedLength += segDelta;