From 329e41da496587fe23a1c9b8d4ace119502b87e8 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 16 Jul 2019 15:28:50 +0300 Subject: [PATCH] [routing] Review fixes. --- routing/index_router.cpp | 26 +++++++------------------- routing/routing_benchmarks/helpers.cpp | 2 +- routing/routing_helpers.hpp | 15 ++++++++------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/routing/index_router.cpp b/routing/index_router.cpp index eb756e3549..e9b4dd7899 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -203,19 +203,7 @@ bool IsDeadEnd(Segment const & segment, bool isOutgoing, WorldGraph & worldGraph // Maximum size (in Segment) of an island in road graph which may be found by the method. size_t constexpr kDeadEndTestLimit = 250; - auto const getVertexByEdgeFn = [](SegmentEdge const & edge) { - return edge.GetTarget(); - }; - - // 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, edges); - }; - - return !CheckGraphConnectivity(segment, kDeadEndTestLimit, worldGraph, visitedSegments, - getVertexByEdgeFn, getOutgoingEdgesFn); + return !CheckGraphConnectivity(segment, isOutgoing, kDeadEndTestLimit, worldGraph, visitedSegments); } } // namespace @@ -824,7 +812,7 @@ void IndexRouter::EraseIfDeadEnd(WorldGraph & worldGraph, // |deadEnds| cache is necessary to minimize number of calls a time consumption IsDeadEnd() method. set deadEnds; base::EraseIf(roads, [&deadEnds, &worldGraph, this](pair const & r) { - auto const & ft = r.first; + auto const & featureId = r.first; auto const & road = r.second; CHECK_GREATER_OR_EQUAL(road.m_junctions.size(), 2, ()); @@ -832,7 +820,7 @@ void IndexRouter::EraseIfDeadEnd(WorldGraph & worldGraph, // So the number of checked edges should be minimized as possible. // Below a heuristic is used. If a first segment of a feature is forward direction is a dead end // all segments of the feature is considered as dead ends. - auto const segment = GetSegmentByEdge(Edge::MakeReal(ft, true /* forward */, 0 /* segment id */, + auto const segment = GetSegmentByEdge(Edge::MakeReal(featureId, true /* forward */, 0 /* segment id */, road.m_junctions[0], road.m_junctions[1])); if (deadEnds.count(segment) != 0) return true; @@ -885,8 +873,8 @@ bool IndexRouter::IsFencedOff(m2::PointD const & point, pair con } void IndexRouter::RoadsToNearestEdges(m2::PointD const & point, - vector> const & roads, - uint32_t count, vector> & edgeProj) const + vector> const & roads, + uint32_t count, vector> & edgeProj) const { NearestEdgeFinder finder(point); for (auto const & r : roads) @@ -978,11 +966,11 @@ bool IndexRouter::FindBestEdges(m2::PointD const & point, MYTHROW(MwmIsNotAliveException, ("Can't get mwm handle for", pointCountryFile)); auto const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(point, closestEdgesRadiusM); - auto const isGood = [this](FeatureID const & fid) { + auto const isGoodFeature = [this](FeatureID const & fid) { auto const & info = fid.m_mwmId.GetInfo(); return m_numMwmIds->ContainsFile(info->GetLocalFile().GetCountryFile()); }; - auto closestRoads = m_roadGraph.FindRoads(rect, isGood); + auto closestRoads = m_roadGraph.FindRoads(rect, isGoodFeature); // Removing all dead ends from |closestRoads|. Then some candidates will be taken from |closestRoads|. // It's necessary to call for all |closestRoads| before IsFencedOff(). If to remove all fenced off diff --git a/routing/routing_benchmarks/helpers.cpp b/routing/routing_benchmarks/helpers.cpp index 008e344051..909141dd3a 100644 --- a/routing/routing_benchmarks/helpers.cpp +++ b/routing/routing_benchmarks/helpers.cpp @@ -142,7 +142,7 @@ void RoutingTest::GetNearestEdges(m2::PointD const & pt, routing::FeaturesRoadGraph graph(m_dataSource, m_mode, CreateModelFactory()); graph.FindClosestEdges(MercatorBounds::RectByCenterXYAndSizeInMeters( pt, routing::FeaturesRoadGraph::kClosestEdgesRadiusM), - 1 /* count */, nullptr /* isGood */, edges); + 1 /* count */, nullptr /* isGoodFeature */, edges); } void TestRouter(routing::IRouter & router, m2::PointD const & startPos, diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index a569b28b70..9d15384582 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -54,11 +54,9 @@ Segment ConvertEdgeToSegment(NumMwmIds const & numMwmIds, Edge const & edge); /// of edges, /// if graph ends before this number is reached then junction is assumed as not connected to the /// world graph. -template -bool CheckGraphConnectivity(typename Graph::Vertex const & start, size_t limit, Graph & graph, - std::set & marked, - GetVertexByEdgeFn && getVertexByEdgeFn, - GetOutgoingEdgesFn && getOutgoingEdgesFn) +template +bool CheckGraphConnectivity(typename Graph::Vertex const & start, bool isOutgoing, size_t limit, + Graph & graph, std::set & marked) { std::queue q; q.push(start); @@ -72,10 +70,13 @@ bool CheckGraphConnectivity(typename Graph::Vertex const & start, size_t limit, q.pop(); edges.clear(); - getOutgoingEdgesFn(graph, u, edges); + + // Note. If |isOutgoing| == true outgoing edges are looked for. + // If |isOutgoing| == false it's the finish. So ingoing edges are looked for. + graph.GetEdgeList(u, isOutgoing, edges); for (auto const & edge : edges) { - auto const & v = getVertexByEdgeFn(edge); + auto const & v = edge.GetTarget(); if (marked.count(v) == 0) { q.push(v);