diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-06-15 16:10:45 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:59:34 +0300 |
commit | 6fa1a4fca3fb041fb6e2a91d28b649dadc2e372e (patch) | |
tree | d3f13c4139b6084a24999c01178eb50c0122690f /routing | |
parent | e5c29ede54a4df86579b1b0933ea97ee7e7ca83f (diff) |
Correction after Levs comments
Diffstat (limited to 'routing')
-rw-r--r-- | routing/osrm_router.cpp | 7 | ||||
-rw-r--r-- | routing/routing_tests/turns_generator_test.cpp | 7 | ||||
-rw-r--r-- | routing/turns.cpp | 5 | ||||
-rw-r--r-- | routing/turns.hpp | 2 | ||||
-rw-r--r-- | routing/turns_generator.cpp | 40 | ||||
-rw-r--r-- | routing/turns_generator.hpp | 3 |
6 files changed, 31 insertions, 33 deletions
diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 1f4372508a..93a4375f65 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -522,6 +522,13 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & } } Points.insert(Points.end(), mwmPoints.begin(), mwmPoints.end()); + + if (!TurnsGeom.empty()) + { + double const mercatorLength = TurnsGeom.back().m_mercatorDistance; + for (auto & turnGeom : mwmTurnsGeom) + turnGeom.m_mercatorDistance += mercatorLength; + } TurnsGeom.insert(TurnsGeom.end(), mwmTurnsGeom.begin(), mwmTurnsGeom.end()); } diff --git a/routing/routing_tests/turns_generator_test.cpp b/routing/routing_tests/turns_generator_test.cpp index 6ef4ccb72f..23179a47af 100644 --- a/routing/routing_tests/turns_generator_test.cpp +++ b/routing/routing_tests/turns_generator_test.cpp @@ -378,8 +378,9 @@ 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., ()); + TEST_EQUAL(CalculateMercatorDistanceAlongPath(0, points.size() - 1, points), 2., ()); + TEST_EQUAL(CalculateMercatorDistanceAlongPath(1, 1, points), 0., ()); + TEST_EQUAL(CalculateMercatorDistanceAlongPath(1, 2, points), 0., ()); + TEST_EQUAL(CalculateMercatorDistanceAlongPath(0, 1, points), 1., ()); } } // namespace diff --git a/routing/turns.cpp b/routing/turns.cpp index c2b1b90e4d..28b9001b38 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -50,11 +50,6 @@ namespace routing { namespace turns { -bool TurnGeom::operator==(TurnGeom const & other) const -{ - return m_indexInRoute == other.m_indexInRoute && m_turnIndex == other.m_turnIndex - && m_mercatorDistance == other.m_mercatorDistance && m_points == other.m_points; -} bool SingleLaneInfo::operator==(SingleLaneInfo const & other) const { diff --git a/routing/turns.hpp b/routing/turns.hpp index 2d2e1eaff2..4f0073050e 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -98,8 +98,6 @@ struct TurnGeom { } - bool operator==(TurnGeom const & other) const; - uint32_t m_indexInRoute; uint32_t m_turnIndex; double m_mercatorDistance; diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index 77c23eddc4..3f2f21e0e1 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -508,17 +508,15 @@ vector<SingleLaneInfo> GetLanesInfo(NodeID node, RoutingMapping const & routingM return lanes; } -double CalculateMercatorDistanceAlongRoute(uint32_t startPoint, uint32_t endPoint, vector<m2::PointD> const & points) +double CalculateMercatorDistanceAlongPath(uint32_t startPointIndex, uint32_t endPointIndex, + vector<m2::PointD> const & points) { - ASSERT_LESS_OR_EQUAL(endPoint, points.size(), ()); - ASSERT_LESS_OR_EQUAL(startPoint, endPoint, ()); - - if (startPoint == endPoint) - return 0.; + ASSERT_LESS(endPointIndex, points.size(), ()); + ASSERT_LESS_OR_EQUAL(startPointIndex, endPointIndex, ()); double mercatorDistanceBetweenTurns = 0; - for (uint32_t i = startPoint + 1; i != endPoint; ++i) - mercatorDistanceBetweenTurns += points[i - 1].Length(points[i]); + for (uint32_t i = startPointIndex; i != endPointIndex; ++i) + mercatorDistanceBetweenTurns += points[i].Length(points[i + 1]); return mercatorDistanceBetweenTurns; } @@ -538,30 +536,28 @@ void CalculateTurnGeometry(vector<m2::PointD> const & points, Route::TTurns cons double mercatorDistance = 0; auto const turnsDirEnd = turnsDir.end(); - for (auto i = turnsDir.begin(); i != turnsDirEnd; ++i) + for (auto currentTurn = turnsDir.begin(); currentTurn != turnsDirEnd; ++currentTurn) { - TurnItem const & currentTurn = *i; - ASSERT_LESS(currentTurn.m_index, kNumPoints, ()); + ASSERT_LESS(currentTurn->m_index, kNumPoints, ()); uint32_t formerTurnIndex = 0; - if (i != turnsDir.begin()) - formerTurnIndex = (i - 1)->m_index; + if (currentTurn != turnsDir.begin()) + formerTurnIndex = (currentTurn - 1)->m_index; double const mercatorDistanceBetweenTurns = - CalculateMercatorDistanceAlongRoute(formerTurnIndex, currentTurn.m_index, points); + CalculateMercatorDistanceAlongPath(formerTurnIndex, currentTurn->m_index, points); mercatorDistance += mercatorDistanceBetweenTurns; - if (currentTurn.m_index == 0 || currentTurn.m_index == (kNumPoints - 1)) + if (currentTurn->m_index == 0 || currentTurn->m_index == (kNumPoints - 1)) continue; - 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 fromIndex = (currentTurn->m_index <= kNumPointsBeforePivot) ? + 0 : currentTurn->m_index - kNumPointsBeforePivot; + uint32_t const nextPossibleIndex = currentTurn->m_index + kNumPointsAfterPivot; + uint32_t const toIndex = min(static_cast<uint32_t>(kNumPoints), nextPossibleIndex); + uint32_t const turnIndex = min(currentTurn->m_index, kNumPointsBeforePivot); - turnsGeom.emplace_back(currentTurn.m_index, turnIndex, mercatorDistance, 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 d33aa229e2..519c17b7c5 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -58,7 +58,8 @@ 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); - + +// Returns the distance in meractor units for the path of points for the range [startPointIndex, endPointIndex]. double CalculateMercatorDistanceAlongRoute(uint32_t startPoint, uint32_t endPoint, vector<m2::PointD> const & points); |