diff --git a/generator/osm2meta.hpp b/generator/osm2meta.hpp index 0297a29435..b94efcc01a 100644 --- a/generator/osm2meta.hpp +++ b/generator/osm2meta.hpp @@ -125,7 +125,7 @@ protected: string ValidateAndFormat_maxspeed(string const & v) const { - static ftypes::IsSpeedCamChecker const IsSpeedCam; + static ftypes::IsSpeedCamChecker const & IsSpeedCam = ftypes::IsSpeedCamChecker::Instance(); if (!IsSpeedCam(m_params.m_Types)) return string(); diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp index 6a2a98b698..9d985fe0d5 100644 --- a/indexer/ftypes_matcher.hpp +++ b/indexer/ftypes_matcher.hpp @@ -48,9 +48,9 @@ public: class IsSpeedCamChecker : public BaseChecker { -public: IsSpeedCamChecker(); +public: static IsSpeedCamChecker const & Instance(); }; diff --git a/routing/route.cpp b/routing/route.cpp index 856cfb907b..282fc2f1aa 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -1,6 +1,6 @@ #include "route.hpp" -#include "turns_generator.hpp" #include "speed_camera.hpp" +#include "turns_generator.hpp" #include "indexer/mercator.hpp" diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 8045f1ab83..c6cf6e413c 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -32,7 +32,7 @@ double constexpr kSpeedCameraMinimalWarningMeters = 200.; // Seconds to warning user before speed camera for driving with current speed. double constexpr kSpeedCameraWarningSeconds = 30; -double constexpr kMpsToKmh = 3600. / 1000.; +double constexpr kKmhToMps = 1000. / 3600.; } // namespace namespace routing @@ -179,7 +179,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(m2::PointD const double const camDistance = m_route.GetCurrentCam(cam, index); if (Route::kInvalidSpeedCameraDistance != camDistance && camDistance < warningDistanceM) { - if (cam.m_index > m_lastWarnedSpeedCamera && info.m_speed > cam.m_maxSpeed * kMpsToKmh) + if (cam.m_index > m_lastWarnedSpeedCamera && info.m_speed > cam.m_maxSpeed * kKmhToMps) { m_speedWarningSignal = true; m_lastWarnedSpeedCamera = cam.m_index; diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index ab12c7214d..858c922f81 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -127,8 +127,8 @@ private: m2::PointD m_endPoint; size_t m_lastWarnedSpeedCamera; // TODO (ldragunov) Rewrite UI interop to message queue and avoid mutable. - /// It is mutable, because a speed warning ring must be only one time per camera. So we need - /// to modify it in a getter. + /// This field is mutable because it's modified in a constant getter. Note that the notification + /// about camera will be sent at most once. mutable bool m_speedWarningSignal; mutable threads::Mutex m_routeSessionMutex; diff --git a/routing/speed_camera.cpp b/routing/speed_camera.cpp index 099dc39f81..76248b0fcd 100644 --- a/routing/speed_camera.cpp +++ b/routing/speed_camera.cpp @@ -5,20 +5,22 @@ #include "indexer/index.hpp" #include "indexer/scales.hpp" +#include "coding/read_write_utils.hpp" #include "coding/reader.hpp" #include "coding/writer.hpp" -#include "coding/read_write_utils.hpp" #include "base/string_utils.hpp" namespace { -double constexpr kMwmReadingRadiusMeters = 2.0; +double constexpr kCameraCheckRadiusMeters = 2.0; } // namespace namespace routing { -uint8_t ReadCamRestriction(FeatureType & ft) +uint8_t const kNoSpeedCamera = numeric_limits::max(); + +uint8_t ReadCameraRestriction(FeatureType & ft) { using feature::Metadata; ft.ParseMetadata(); @@ -46,11 +48,12 @@ uint8_t CheckCameraInPoint(m2::PointD const & point, Index const & index) ft.ParseGeometry(FeatureType::BEST_GEOMETRY); if (ft.GetCenter() == point) - speedLimit = ReadCamRestriction(ft); + speedLimit = ReadCameraRestriction(ft); }; index.ForEachInRect(f, - MercatorBounds::RectByCenterXYAndSizeInMeters(point, kMwmReadingRadiusMeters), + MercatorBounds::RectByCenterXYAndSizeInMeters(point, + kCameraCheckRadiusMeters), scales::GetUpperScale()); return speedLimit; } diff --git a/routing/speed_camera.hpp b/routing/speed_camera.hpp index 693048d231..ec0135adf6 100644 --- a/routing/speed_camera.hpp +++ b/routing/speed_camera.hpp @@ -10,6 +10,6 @@ class Index; namespace routing { -uint8_t constexpr kNoSpeedCamera = numeric_limits::max(); +extern uint8_t const kNoSpeedCamera; uint8_t CheckCameraInPoint(m2::PointD const & point, Index const & index); } // namespace routing