From d84b17f6d37baedf871321f61f3dd44c021fc4ae Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Mon, 17 Aug 2015 13:23:41 +0300 Subject: [PATCH] [routing] Get current direction point enchancement. --- map/framework.cpp | 1 - routing/base/followed_polyline.cpp | 14 ++++++++++++++ routing/base/followed_polyline.hpp | 9 +++++---- routing/route.cpp | 4 ++-- routing/routing_tests/followed_polyline_test.cpp | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index 991ac587cf..1dfd0838fd 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2244,7 +2244,6 @@ void Framework::InsertRoute(Route const & route) return; } - double mercatorDistance = 0; vector turnsDistances; if (m_currentRouterType == RouterType::Vehicle) { diff --git a/routing/base/followed_polyline.cpp b/routing/base/followed_polyline.cpp index 19d9ae9ee1..5ffda53d0c 100644 --- a/routing/base/followed_polyline.cpp +++ b/routing/base/followed_polyline.cpp @@ -151,4 +151,18 @@ double FollowedPolyline::GetMercatorDistanceFromBegin() const return distance; } + +void FollowedPolyline::GetCurrentDirectionPoint(m2::PointD & pt, double toleranceM) const +{ + ASSERT(IsValid(), ()); + size_t currentIndex = min(m_current.m_ind + 1, m_poly.GetSize() - 1); + m2::PointD point = m_poly.GetPoint(currentIndex); + for (; currentIndex < m_poly.GetSize() - 1; point = m_poly.GetPoint(++currentIndex)) + { + if (MercatorBounds::DistanceOnEarth(point, m_current.m_pt) > toleranceM) + break; + } + + pt = point; +} } // namespace routing diff --git a/routing/base/followed_polyline.hpp b/routing/base/followed_polyline.hpp index 911892fcfc..89fdb1d4e1 100644 --- a/routing/base/followed_polyline.hpp +++ b/routing/base/followed_polyline.hpp @@ -26,10 +26,11 @@ public: double GetMercatorDistanceFromBegin() const; - void GetCurrentDirectionPoint(m2::PointD & pt) const - { - pt = m_poly.GetPoint(min(m_current.m_ind + 1, m_poly.GetSize() - 1)); - } + /*! \brief Return next navigation point for direction widgets. + * Returns first geomety point from the polyline after your location if it is farther then + * toleranceM. + */ + void GetCurrentDirectionPoint(m2::PointD & pt, double toleranceM) const; struct Iter { diff --git a/routing/route.cpp b/routing/route.cpp index 82a96c6dca..c59b6248b3 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -173,9 +173,9 @@ void Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn void Route::GetCurrentDirectionPoint(m2::PointD & pt) const { if (m_routingSettings.m_keepPedestrianInfo) - m_simplifiedPoly.GetCurrentDirectionPoint(pt); + m_simplifiedPoly.GetCurrentDirectionPoint(pt, kOnEndToleranceM); else - m_poly.GetCurrentDirectionPoint(pt); + m_poly.GetCurrentDirectionPoint(pt, kOnEndToleranceM); } bool Route::MoveIterator(location::GpsInfo const & info) const diff --git a/routing/routing_tests/followed_polyline_test.cpp b/routing/routing_tests/followed_polyline_test.cpp index abb7da1858..d534584fb7 100644 --- a/routing/routing_tests/followed_polyline_test.cpp +++ b/routing/routing_tests/followed_polyline_test.cpp @@ -83,4 +83,19 @@ UNIT_TEST(FollowedPolylineDistanceCalculationTest) kTestDirectedPolyline.Back()); ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance)); } + +UNIT_TEST(FollowdPolylineDirectionTest) +{ + m2::PolylineD testPolyline({{0, 0}, {1.00003, 0}, {1.00003, 1}}); + FollowedPolyline polyline(testPolyline.Begin(), testPolyline.End()); + TEST_EQUAL(polyline.GetCurrentIter().m_ind, 0, ()); + m2::PointD directionPoint; + polyline.GetCurrentDirectionPoint(directionPoint, 20); + TEST_EQUAL(directionPoint, testPolyline.GetPoint(1), ()); + polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters({1.0, 0}, 2)); + polyline.GetCurrentDirectionPoint(directionPoint, 0.0001); + TEST_EQUAL(directionPoint, testPolyline.GetPoint(1), ()); + polyline.GetCurrentDirectionPoint(directionPoint, 20); + TEST_EQUAL(directionPoint, testPolyline.GetPoint(2), ()); +} } // namespace routing_test