From 2bc9bf11918092df7fede99a39e4176a535d0d6b Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Fri, 2 Oct 2015 15:32:59 +0300 Subject: [PATCH] Reduce speedcam geometry index reading. --- routing/routing_session.cpp | 29 ++++++++++++++--------------- routing/routing_session.hpp | 12 ++++++++++-- routing/speed_camera.cpp | 1 - 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index a89acb5311..a00e116fd1 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -41,21 +41,12 @@ double constexpr kInvalidSpeedCameraDistance = -1; namespace routing { -struct SpeedCameraRestriction -{ - uint32_t m_index; // Index of a polyline point where camera is located. - uint8_t m_maxSpeedKmH; // Maximum speed allowed by the camera. - - SpeedCameraRestriction(uint32_t index, uint8_t maxSpeed) : m_index(index), m_maxSpeedKmH(maxSpeed) {} -}; - RoutingSession::RoutingSession() : m_router(nullptr), m_route(string()), m_state(RoutingNotActive), m_endPoint(m2::PointD::Zero()), m_lastWarnedSpeedCameraIndex(0), - m_lastCheckedCameraIndex(0), m_speedWarningSignal(false), m_passedDistanceOnRouteMeters(0.0) { @@ -144,7 +135,7 @@ void RoutingSession::Reset() m_passedDistanceOnRouteMeters = 0.0; m_lastWarnedSpeedCameraIndex = 0; - m_lastCheckedCameraIndex = 0; + m_lastCheckedCamera = SpeedCameraRestriction(); m_speedWarningSignal = false; } @@ -354,7 +345,7 @@ void RoutingSession::AssignRoute(Route & route, IRouter::ResultCode e) route.SetRoutingSettings(m_routingSettings); m_route.Swap(route); m_lastWarnedSpeedCameraIndex = 0; - m_lastCheckedCameraIndex = 0; + m_lastCheckedCamera = SpeedCameraRestriction(); } void RoutingSession::SetRouter(unique_ptr && router, @@ -437,18 +428,26 @@ string RoutingSession::GetTurnNotificationsLocale() const double RoutingSession::GetDistanceToCurrentCamM(SpeedCameraRestriction & camera, Index const & index) { auto const & m_poly = m_route.GetFollowedPolyline(); - size_t const currentIndex = max(m_poly.GetCurrentIter().m_ind, m_lastCheckedCameraIndex); + auto const & currentIter = m_poly.GetCurrentIter(); + if (currentIter.m_ind < m_lastCheckedCamera.m_index && + m_lastCheckedCamera.m_index < m_poly.GetPolyline().GetSize()) + { + camera = m_lastCheckedCamera; + return m_poly.GetDistanceM(currentIter, m_poly.GetIterToIndex(camera.m_index)); + } + size_t const currentIndex = max(static_cast(currentIter.m_ind), + static_cast(m_lastCheckedCamera.m_index) + 1); for (size_t i = currentIndex; i < m_poly.GetPolyline().GetSize(); ++i) { uint8_t speed = CheckCameraInPoint(m_poly.GetPolyline().GetPoint(i), index); if (speed != kNoSpeedCamera) { camera = SpeedCameraRestriction(static_cast(i), speed); - m_lastCheckedCameraIndex = i; - return m_poly.GetDistanceM(m_poly.GetCurrentIter(), m_poly.GetIterToIndex(i)); + m_lastCheckedCamera = camera; + return m_poly.GetDistanceM(currentIter, m_poly.GetIterToIndex(i)); } } - m_lastCheckedCameraIndex = m_poly.GetPolyline().GetSize(); + m_lastCheckedCamera.m_index = m_poly.GetPolyline().GetSize(); return kInvalidSpeedCameraDistance; } } // namespace routing diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 35ed0fe38f..880a66e790 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -14,6 +14,7 @@ #include "base/deferred_task.hpp" #include "base/mutex.hpp" +#include "std/limits.hpp" #include "std/unique_ptr.hpp" namespace location @@ -23,7 +24,14 @@ class RouteMatchingInfo; namespace routing { -struct SpeedCameraRestriction; +struct SpeedCameraRestriction +{ + uint32_t m_index; // Index of a polyline point where camera is located. + uint8_t m_maxSpeedKmH; // Maximum speed allowed by the camera. + + SpeedCameraRestriction(uint32_t index, uint8_t maxSpeed) : m_index(index), m_maxSpeedKmH(maxSpeed) {} + SpeedCameraRestriction() : m_index(0), m_maxSpeedKmH(numeric_limits::max()) {} +}; class RoutingSession { @@ -132,7 +140,7 @@ private: State m_state; m2::PointD m_endPoint; size_t m_lastWarnedSpeedCameraIndex; - size_t m_lastCheckedCameraIndex; + SpeedCameraRestriction m_lastCheckedCamera; // TODO (ldragunov) Rewrite UI interop to message queue and avoid mutable. /// This field is mutable because it's modified in a constant getter. Note that the notification /// about camera will be sent at most once. diff --git a/routing/speed_camera.cpp b/routing/speed_camera.cpp index ba679770b7..5127ff023c 100644 --- a/routing/speed_camera.cpp +++ b/routing/speed_camera.cpp @@ -50,7 +50,6 @@ uint8_t CheckCameraInPoint(m2::PointD const & point, Index const & index) if (!ftypes::IsSpeedCamChecker::Instance()(hl)) return; - ft.ParseGeometry(FeatureType::BEST_GEOMETRY); if (my::AlmostEqualAbs(ft.GetCenter().x, point.x, kCoordinateEqualityDelta) && my::AlmostEqualAbs(ft.GetCenter().y, point.y, kCoordinateEqualityDelta)) speedLimit = ReadCameraRestriction(ft);