diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index 9bef97fbe9..09be213c8e 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -189,7 +189,7 @@ void FeaturesRoadGraph::FindClosestEdges(m2::RectD const & rect, uint32_t count, IRoadGraph::RoadInfo const & roadInfo = GetCachedRoadInfo(featureId, ft, kInvalidSpeedKMPH); CHECK_EQUAL(roadInfo.m_speedKMPH, kInvalidSpeedKMPH, ()); - finder.AddInformationSource(featureId, roadInfo.m_junctions, roadInfo.m_bidirectional); + finder.AddInformationSource(IRoadGraph::FullRoadInfo(featureId, roadInfo)); }; m_dataSource.ForEachInRect(f, rect, GetStreetReadScale()); @@ -197,8 +197,8 @@ void FeaturesRoadGraph::FindClosestEdges(m2::RectD const & rect, uint32_t count, finder.MakeResult(vicinities, count); } -vector FeaturesRoadGraph::FindRoads( - m2::RectD const & rect, IsGoodFeatureFn const & isGoodFeature) const +vector +FeaturesRoadGraph::FindRoads(m2::RectD const & rect, IsGoodFeatureFn const & isGoodFeature) const { vector roads; auto const f = [&roads, &isGoodFeature, &rect, this](FeatureType & ft) { @@ -209,7 +209,7 @@ vector FeaturesRoadGraph::FindRoads( if (isGoodFeature && !isGoodFeature(featureId)) return; - // DataSource::ForEachInRect() gives not ony features inside |rect| but some other features + // DataSource::ForEachInRect() gives not only features inside |rect| but some other features // which lie close to the rect. Removes all the features which don't cross |rect|. auto const & roadInfo = GetCachedRoadInfo(featureId, ft, kInvalidSpeedKMPH); if (!RectCoversPolyline(roadInfo.m_junctions, rect)) diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp index 2b7b2a900a..a751386dc9 100644 --- a/routing/features_road_graph.hpp +++ b/routing/features_road_graph.hpp @@ -81,7 +81,7 @@ public: void ForEachFeatureClosestToCross(m2::PointD const & cross, ICrossEdgesLoader & edgesLoader) const override; void FindClosestEdges(m2::RectD const & rect, uint32_t count, - std::vector> & vicinities) const override; + std::vector> & vicinities) const override; std::vector FindRoads( m2::RectD const & rect, IsGoodFeatureFn const & isGoodFeature) const override; void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override; diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 66c554f41b..0b555e2c2d 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -829,15 +829,17 @@ 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](IRoadGraph::FullRoadInfo const & r) { - CHECK_GREATER_OR_EQUAL(r.m_roadInfo.m_junctions.size(), 2, ()); + base::EraseIf(roads, [&deadEnds, &worldGraph, this](auto const & fullRoadInfo) { + CHECK_GREATER_OR_EQUAL(fullRoadInfo.m_roadInfo.m_junctions.size(), 2, ()); // Note. Checking if an edge goes to a dead end is a time consumption process. // 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(r.m_featureId, true /* forward */, 0 /* segment id */, - r.m_roadInfo.m_junctions[0], r.m_roadInfo.m_junctions[1])); + auto const segment = GetSegmentByEdge(Edge::MakeReal(fullRoadInfo.m_featureId, true /* forward */, + 0 /* segment id */, + fullRoadInfo.m_roadInfo.m_junctions[0], + fullRoadInfo.m_roadInfo.m_junctions[1])); return IsDeadEndCached(segment, true /* isOutgoing */, false /* useRoutingOptions */, worldGraph, deadEnds); }); @@ -885,8 +887,8 @@ void IndexRouter::RoadsToNearestEdges(m2::PointD const & point, vector> & edgeProj) const { NearestEdgeFinder finder(point, isGood); - for (auto const & r : roads) - finder.AddInformationSource(r.m_featureId, r.m_roadInfo.m_junctions, r.m_roadInfo.m_bidirectional); + for (auto const & road : roads) + finder.AddInformationSource(road); finder.MakeResult(edgeProj, count); } diff --git a/routing/nearest_edge_finder.cpp b/routing/nearest_edge_finder.cpp index 487162535e..0a7e8351e5 100644 --- a/routing/nearest_edge_finder.cpp +++ b/routing/nearest_edge_finder.cpp @@ -15,15 +15,14 @@ NearestEdgeFinder::NearestEdgeFinder(m2::PointD const & point, IsEdgeProjGood co { } -void NearestEdgeFinder::AddInformationSource(FeatureID const & featureId, - IRoadGraph::JunctionVec const & junctions, - bool bidirectional) +void NearestEdgeFinder::AddInformationSource(IRoadGraph::FullRoadInfo const & roadInfo) { - if (!featureId.IsValid()) + if (!roadInfo.m_featureId.IsValid()) return; Candidate res; + auto const & junctions = roadInfo.m_roadInfo.m_junctions; size_t const count = junctions.size(); ASSERT_GREATER(count, 1, ()); for (size_t i = 1; i < count; ++i) @@ -68,10 +67,10 @@ void NearestEdgeFinder::AddInformationSource(FeatureID const & featureId, startAlt + static_cast((endAlt - startAlt) * distFromStartM / segLenM); } - res.m_fid = featureId; + res.m_fid = roadInfo.m_featureId; res.m_segStart = segStart; res.m_segEnd = segEnd; - res.m_bidirectional = bidirectional; + res.m_bidirectional = roadInfo.m_roadInfo.m_bidirectional; ASSERT_NOT_EQUAL(res.m_segStart.GetAltitude(), feature::kInvalidAltitude, ()); ASSERT_NOT_EQUAL(res.m_segEnd.GetAltitude(), feature::kInvalidAltitude, ()); @@ -102,26 +101,20 @@ void NearestEdgeFinder::CandidateToResult(Candidate const & candidate, size_t maxCountFeatures, vector> & res) const { - AddResIf(candidate.m_fid, true /* forward */, candidate.m_segId, - candidate.m_segStart, candidate.m_segEnd, candidate.m_projPoint, maxCountFeatures, res); + AddResIf(candidate, true /* forward */, maxCountFeatures, res); if (candidate.m_bidirectional) - { - AddResIf(candidate.m_fid, false /* forward */, candidate.m_segId, candidate.m_segEnd, - candidate.m_segStart, candidate.m_projPoint, maxCountFeatures, res); - } + AddResIf(candidate, false /* forward */, maxCountFeatures, res); } -void NearestEdgeFinder::AddResIf(FeatureID const & featureId, bool forward, uint32_t segId, - Junction const & startJunction, Junction const & endJunction, - Junction const & projPoint, size_t maxCountFeatures, +void NearestEdgeFinder::AddResIf(Candidate const & candidate, bool forward, size_t maxCountFeatures, vector> & res) const { if (res.size() >= maxCountFeatures) return; - auto const edge = Edge::MakeReal(featureId, forward, segId, startJunction, endJunction); - auto const edgeProj = make_pair(edge, projPoint); + auto const & edge = Edge::MakeReal(candidate.m_fid, forward, candidate.m_segId, candidate.m_segStart, candidate.m_segEnd); + auto const & edgeProj = make_pair(edge, candidate.m_projPoint); if (m_isEdgeProjGood && !m_isEdgeProjGood(edgeProj)) return; diff --git a/routing/nearest_edge_finder.hpp b/routing/nearest_edge_finder.hpp index 9f503099fa..65671489d3 100644 --- a/routing/nearest_edge_finder.hpp +++ b/routing/nearest_edge_finder.hpp @@ -30,8 +30,8 @@ public: inline bool HasCandidates() const { return !m_candidates.empty(); } - void AddInformationSource(FeatureID const & featureId, IRoadGraph::JunctionVec const & junctions, - bool bidirectional); + void AddInformationSource(IRoadGraph::FullRoadInfo const & roadInfo); + void MakeResult(std::vector> & res, size_t maxCountFeatures); @@ -49,9 +49,7 @@ private: bool m_bidirectional = true; }; - void AddResIf(FeatureID const & featureId, bool forward, uint32_t segId, - Junction const & startJunction, Junction const & endJunction, - Junction const & projPoint, size_t maxCountFeatures, + void AddResIf(Candidate const & candidate, bool forward, size_t maxCountFeatures, std::vector> & res) const; void CandidateToResult(Candidate const & candidate, size_t maxCountFeatures, std::vector> & res) const; diff --git a/routing/routing_tests/nearest_edge_finder_tests.cpp b/routing/routing_tests/nearest_edge_finder_tests.cpp index 71e81e05ef..7755967a8b 100644 --- a/routing/routing_tests/nearest_edge_finder_tests.cpp +++ b/routing/routing_tests/nearest_edge_finder_tests.cpp @@ -2,6 +2,7 @@ #include "routing/routing_tests/road_graph_builder.hpp" +#include "routing/road_graph.hpp" #include "routing/nearest_edge_finder.hpp" #include "routing_common/maxspeed_conversion.hpp" @@ -24,7 +25,7 @@ void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount, FeatureID const featureId = MakeTestFeatureID(base::checked_cast(i)); auto const & roadInfo = graph->GetRoadInfo(featureId, {true /* forward */, false /* in city */, Maxspeed()}); - finder.AddInformationSource(featureId, roadInfo.m_junctions, roadInfo.m_bidirectional); + finder.AddInformationSource(IRoadGraph::FullRoadInfo(featureId, roadInfo)); } vector> result;