diff --git a/base/base_tests/stl_helpers_test.cpp b/base/base_tests/stl_helpers_test.cpp index f42e8ac4df..af47c7e5fb 100644 --- a/base/base_tests/stl_helpers_test.cpp +++ b/base/base_tests/stl_helpers_test.cpp @@ -78,10 +78,10 @@ UNIT_TEST(EqualsBy) UNIT_TEST(SortUnique) { { - vector v = {1, 2, 1, 4, 3, 5, 2, 7, 1}; - my::SortUnique(v); + vector actual = {1, 2, 1, 4, 3, 5, 2, 7, 1}; + my::SortUnique(actual); vector const expected = {1, 2, 3, 4, 5, 7}; - TEST_EQUAL(v, expected, ()); + TEST_EQUAL(actual, expected, ()); } { using TValue = int; diff --git a/routing/road_graph.cpp b/routing/road_graph.cpp index 31ef1db95f..271e258e63 100644 --- a/routing/road_graph.cpp +++ b/routing/road_graph.cpp @@ -158,33 +158,20 @@ IRoadGraph::RoadInfo::RoadInfo(bool bidirectional, double speedKMPH, initializer // IRoadGraph::CrossOutgoingLoader --------------------------------------------- void IRoadGraph::CrossOutgoingLoader::LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo) { - ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t i, m2::PointD const & p) + ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t segId, m2::PointD const & endPoint, bool forward) { - ASSERT_LESS(i, roadInfo.m_points.size() - 1, ()); - m_edges.emplace_back(featureId, true /* forward */, i, p, roadInfo.m_points[i + 1]); - }, - [&featureId, &roadInfo, this](size_t i, m2::PointD const & p) - { - ASSERT_LESS(i, roadInfo.m_points.size(), ()); - if (roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag) - m_edges.emplace_back(featureId, false /* forward */, i - 1, p, roadInfo.m_points[i - 1]); + if (forward || roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag) + m_edges.emplace_back(featureId, forward, segId, m_cross, endPoint); }); } // IRoadGraph::CrossIngoingLoader ---------------------------------------------- void IRoadGraph::CrossIngoingLoader::LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo) { - ForEachEdge(roadInfo, - [&featureId, &roadInfo, this](size_t i, m2::PointD const & p) + ForEachEdge(roadInfo, [&featureId, &roadInfo, this](size_t segId, m2::PointD const & endPoint, bool forward) { - ASSERT_LESS(i, roadInfo.m_points.size() - 1, ()); - if (roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag) - m_edges.emplace_back(featureId, false /* forward */, i, roadInfo.m_points[i + 1], p); - }, - [&featureId, &roadInfo, this](size_t i, m2::PointD const & p) - { - ASSERT_LESS(i, roadInfo.m_points.size() , ()); - m_edges.emplace_back(featureId, true /* forward */, i - 1, roadInfo.m_points[i - 1], p); + if (!forward || roadInfo.m_bidirectional || m_mode == IRoadGraph::Mode::IgnoreOnewayTag) + m_edges.emplace_back(featureId, !forward, segId, endPoint, m_cross); }); } diff --git a/routing/road_graph.hpp b/routing/road_graph.hpp index f5fdf160c7..e97a9cb0f2 100644 --- a/routing/road_graph.hpp +++ b/routing/road_graph.hpp @@ -125,27 +125,27 @@ public: virtual void LoadEdges(FeatureID const & featureId, RoadInfo const & roadInfo) = 0; protected: - template - void ForEachEdge(RoadInfo const & roadInfo, THeadFn && headFn, TTailFn && tailFn) + template + void ForEachEdge(RoadInfo const & roadInfo, TFn && fn) { for (size_t i = 0; i < roadInfo.m_points.size(); ++i) { - m2::PointD const & p = roadInfo.m_points[i]; - - if (!my::AlmostEqualAbs(m_cross, p, kPointsEqualEpsilon)) + if (!my::AlmostEqualAbs(m_cross, roadInfo.m_points[i], kPointsEqualEpsilon)) continue; - if (i > 0) - { - // p - // o------------>o - tailFn(i, p); - } if (i < roadInfo.m_points.size() - 1) { - // p - // o------------>o - headFn(i, p); + // Head of the edge. + // m_cross + // o------------>o + fn(i, roadInfo.m_points[i + 1], true /* forward */); + } + if (i > 0) + { + // Tail of the edge. + // m_cross + // o------------>o + fn(i - 1, roadInfo.m_points[i - 1], false /* backward */); } } }