diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-06-15 12:53:01 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:59:33 +0300 |
commit | e5c29ede54a4df86579b1b0933ea97ee7e7ca83f (patch) | |
tree | 589c488aa201ebcbf6a6a0b41fc275c8317f59ff /routing | |
parent | 1cb6ec2128e85e85f8e327b14a55a8b2c072f6e1 (diff) |
Distance form the start of the route for every turn in mercator units was added.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/routing_tests/turns_generator_test.cpp | 9 | ||||
-rw-r--r-- | routing/turns.cpp | 6 | ||||
-rw-r--r-- | routing/turns.hpp | 8 | ||||
-rw-r--r-- | routing/turns_generator.cpp | 50 | ||||
-rw-r--r-- | routing/turns_generator.hpp | 3 |
5 files changed, 60 insertions, 16 deletions
diff --git a/routing/routing_tests/turns_generator_test.cpp b/routing/routing_tests/turns_generator_test.cpp index cce2f1087d..6ef4ccb72f 100644 --- a/routing/routing_tests/turns_generator_test.cpp +++ b/routing/routing_tests/turns_generator_test.cpp @@ -373,4 +373,13 @@ UNIT_TEST(TestIntermediateDirection) TEST_EQUAL(IntermediateDirection(-90.), TurnDirection::TurnLeft, ()); TEST_EQUAL(IntermediateDirection(-170.), TurnDirection::TurnSharpLeft, ()); } + +UNIT_TEST(TestCalculateMercatorDistanceAlongRoute) +{ + vector<m2::PointD> const points = {{0., 0.}, {0., 1.}, {0., 1.}, {1., 1.}}; + + TEST_EQUAL(CalculateMercatorDistanceAlongRoute(0, points.size(), points), 2., ()); + TEST_EQUAL(CalculateMercatorDistanceAlongRoute(1, 1, points), 0., ()); + TEST_EQUAL(CalculateMercatorDistanceAlongRoute(1, 2, points), 0., ()); +} } // namespace diff --git a/routing/turns.cpp b/routing/turns.cpp index 922a29b47a..c2b1b90e4d 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -53,7 +53,7 @@ namespace turns bool TurnGeom::operator==(TurnGeom const & other) const { return m_indexInRoute == other.m_indexInRoute && m_turnIndex == other.m_turnIndex - && m_points == other.m_points; + && m_mercatorDistance == other.m_mercatorDistance && m_points == other.m_points; } bool SingleLaneInfo::operator==(SingleLaneInfo const & other) const @@ -222,7 +222,9 @@ string DebugPrint(TurnGeom const & turnGeom) { stringstream out; out << "[ TurnGeom: m_indexInRoute = " << turnGeom.m_indexInRoute - << ", m_turnIndex = " << turnGeom.m_turnIndex << " ]" << endl; + << ", m_turnIndex = " << turnGeom.m_turnIndex + << ", m_mercatorDistance = " << turnGeom.m_mercatorDistance + << " ]" << endl; return out.str(); } diff --git a/routing/turns.hpp b/routing/turns.hpp index e985c6595b..2d2e1eaff2 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -91,9 +91,10 @@ string DebugPrint(LaneWay const l); struct TurnGeom { - TurnGeom(uint32_t indexInRoute, uint32_t turnIndex, - vector<m2::PointD>::const_iterator b, vector<m2::PointD>::const_iterator e) : - m_indexInRoute(indexInRoute), m_turnIndex(turnIndex), m_points(b, e) + TurnGeom(uint32_t indexInRoute, uint32_t turnIndex, double mercatorDistance, + vector<m2::PointD>::const_iterator b, vector<m2::PointD>::const_iterator e) + : m_indexInRoute(indexInRoute), m_turnIndex(turnIndex), + m_mercatorDistance(mercatorDistance), m_points(b, e) { } @@ -101,6 +102,7 @@ struct TurnGeom uint32_t m_indexInRoute; uint32_t m_turnIndex; + double m_mercatorDistance; vector<m2::PointD> m_points; }; diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index cd2dd68630..77c23eddc4 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -508,6 +508,21 @@ vector<SingleLaneInfo> GetLanesInfo(NodeID node, RoutingMapping const & routingM return lanes; } +double CalculateMercatorDistanceAlongRoute(uint32_t startPoint, uint32_t endPoint, vector<m2::PointD> const & points) +{ + ASSERT_LESS_OR_EQUAL(endPoint, points.size(), ()); + ASSERT_LESS_OR_EQUAL(startPoint, endPoint, ()); + + if (startPoint == endPoint) + return 0.; + + double mercatorDistanceBetweenTurns = 0; + for (uint32_t i = startPoint + 1; i != endPoint; ++i) + mercatorDistanceBetweenTurns += points[i - 1].Length(points[i]); + + return mercatorDistanceBetweenTurns; +} + void CalculateTurnGeometry(vector<m2::PointD> const & points, Route::TTurns const & turnsDir, TTurnsGeom & turnsGeom) { @@ -519,21 +534,34 @@ void CalculateTurnGeometry(vector<m2::PointD> const & points, Route::TTurns cons // kNumPointsAfterPivot is greater because there are half body and the arrow after the pivot point uint32_t constexpr kNumPointsAfterPivot = kNumPointsBeforePivot + 10; - for (TurnItem const & t : turnsDir) + /// mercatorDistance is a distance in mercator units from the start of the route. + double mercatorDistance = 0; + + auto const turnsDirEnd = turnsDir.end(); + for (auto i = turnsDir.begin(); i != turnsDirEnd; ++i) { - ASSERT_LESS(t.m_index, kNumPoints, ()); - if (t.m_index == 0 || t.m_index == (kNumPoints - 1)) + TurnItem const & currentTurn = *i; + ASSERT_LESS(currentTurn.m_index, kNumPoints, ()); + + uint32_t formerTurnIndex = 0; + if (i != turnsDir.begin()) + formerTurnIndex = (i - 1)->m_index; + + double const mercatorDistanceBetweenTurns = + CalculateMercatorDistanceAlongRoute(formerTurnIndex, currentTurn.m_index, points); + mercatorDistance += mercatorDistanceBetweenTurns; + + if (currentTurn.m_index == 0 || currentTurn.m_index == (kNumPoints - 1)) continue; - uint32_t const fromIndex = (t.m_index <= kNumPointsBeforePivot) ? 0 : t.m_index - kNumPointsBeforePivot; - uint32_t toIndex = 0; - if (t.m_index + kNumPointsAfterPivot >= kNumPoints || t.m_index + kNumPointsAfterPivot < t.m_index) - toIndex = kNumPoints; - else - toIndex = t.m_index + kNumPointsAfterPivot; + uint32_t const fromIndex = (currentTurn.m_index <= kNumPointsBeforePivot) ? + 0 : currentTurn.m_index - kNumPointsBeforePivot; + uint32_t const nextPossibleIndex = currentTurn.m_index + kNumPointsAfterPivot; + uint32_t const toIndex = (nextPossibleIndex >= kNumPoints) ? kNumPoints : nextPossibleIndex; + + uint32_t const turnIndex = min(currentTurn.m_index, kNumPointsBeforePivot); - uint32_t const turnIndex = min(t.m_index, kNumPointsBeforePivot); - turnsGeom.emplace_back(t.m_index, turnIndex, points.begin() + fromIndex, + turnsGeom.emplace_back(currentTurn.m_index, turnIndex, mercatorDistance, points.begin() + fromIndex, points.begin() + toIndex); } return; diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index fbf80fa1c9..d33aa229e2 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -58,6 +58,9 @@ struct TurnInfo size_t GetLastSegmentPointIndex(pair<size_t, size_t> const & p); vector<SingleLaneInfo> GetLanesInfo(NodeID node, RoutingMapping const & routingMapping, TGetIndexFunction GetIndex, Index const & index); + +double CalculateMercatorDistanceAlongRoute(uint32_t startPoint, + uint32_t endPoint, vector<m2::PointD> const & points); /*! * \brief Returns geometry for all the turns. It means that for every turn CalculateTurnGeometry |