diff options
author | Mikhail Gorbushin <m.gorbushin@corp.mail.ru> | 2018-11-27 17:55:30 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2018-11-30 20:04:40 +0300 |
commit | 9634c310b13f4f743dc41356ece0dc46b8aabe88 (patch) | |
tree | fe8bdb696337fdf5478c7a5d8471ee45ba212b48 | |
parent | 894a39e5479b367b6ef37838d5cb21d74551e2a5 (diff) |
[routing] Speed Cameras review fixes
-rw-r--r-- | android/jni/com/mapswithme/maps/Framework.cpp | 9 | ||||
-rw-r--r-- | geometry/point2d.hpp | 2 | ||||
-rw-r--r-- | indexer/classificator.cpp | 6 | ||||
-rw-r--r-- | iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm | 2 | ||||
-rw-r--r-- | iphone/Maps/UI/Settings/MWMSettingsViewController.mm | 2 | ||||
-rw-r--r-- | iphone/Maps/UI/Settings/MWMSpeedCamSettingsController.mm | 2 | ||||
-rw-r--r-- | map/framework.hpp | 2 | ||||
-rw-r--r-- | map/routing_manager.cpp | 22 | ||||
-rw-r--r-- | routing/routing_callbacks.hpp | 4 | ||||
-rw-r--r-- | routing/routing_integration_tests/CMakeLists.txt | 18 | ||||
-rw-r--r-- | routing/routing_integration_tests/speed_camera_notifications_tests.cpp | 66 | ||||
-rw-r--r-- | routing/routing_session.cpp | 5 | ||||
-rw-r--r-- | routing/routing_session.hpp | 2 | ||||
-rw-r--r-- | routing/speed_camera.cpp | 13 | ||||
-rw-r--r-- | routing/speed_camera.hpp | 4 | ||||
-rw-r--r-- | routing/speed_camera_manager.cpp | 196 | ||||
-rw-r--r-- | routing/speed_camera_manager.hpp | 50 |
17 files changed, 218 insertions, 187 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index ea11736c32..3ef6f71102 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1112,7 +1112,7 @@ Java_com_mapswithme_maps_Framework_nativeSetSpeedCamManagerMode(JNIEnv * env, jc JNIEXPORT jboolean JNICALL Java_com_mapswithme_maps_Framework_nativeShouldPlayWarningSignal(JNIEnv * env, jclass) { - return frm()->GetRoutingManager().GetSpeedCamManager().ShouldPlayWarningSignal(); + return frm()->GetRoutingManager().GetSpeedCamManager().ShouldPlayBeepSignal(); } JNIEXPORT jint JNICALL @@ -1124,11 +1124,8 @@ Java_com_mapswithme_maps_Framework_nativeGetSpeedCamManagerMode(JNIEnv * env, jc JNIEXPORT jboolean JNICALL Java_com_mapswithme_maps_Framework_nativeIsSpeedLimitExceeded(JNIEnv * env, jclass) { - auto fr = frm(); - if (!fr->GetRoutingManager().IsRoutingActive()) - return false; - - return fr->GetRoutingManager().IsSpeedLimitExceeded(); + auto const & rm = frm()->GetRoutingManager(); + return rm.IsRoutingActive() ? rm.IsSpeedLimitExceeded() : false; } JNIEXPORT jobject JNICALL diff --git a/geometry/point2d.hpp b/geometry/point2d.hpp index 9d0fc638e1..778587a45e 100644 --- a/geometry/point2d.hpp +++ b/geometry/point2d.hpp @@ -8,6 +8,7 @@ #include <array> #include <cmath> #include <functional> +#include <limits> #include <sstream> #include <typeinfo> @@ -31,6 +32,7 @@ public: } static Point<T> Zero() { return Point<T>(0, 0); } + static Point<T> Max() { return Point<T>(std::numeric_limits<T>::max(), std::numeric_limits<T>::max());} bool EqualDxDy(Point<T> const & p, T eps) const { diff --git a/indexer/classificator.cpp b/indexer/classificator.cpp index 4a629b4503..280f7ebd0d 100644 --- a/indexer/classificator.cpp +++ b/indexer/classificator.cpp @@ -407,12 +407,6 @@ uint32_t Classificator::GetTypeByPath(vector<string> const & path) const uint32_t Classificator::GetTypeByPath(initializer_list<char const *> const & lst) const { - LOG(LINFO, ("===========[START]========")); - for (auto item : lst) - { - LOG(LINFO, (item)); - } - LOG(LINFO, ("===========[END]========")); uint32_t const type = GetTypeByPathImpl(lst.begin(), lst.end()); ASSERT_NOT_EQUAL(type, 0, (lst)); return type; diff --git a/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm b/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm index 62a0ca1fdd..aed0cc94cc 100644 --- a/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm +++ b/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm @@ -279,7 +279,7 @@ using Observers = NSHashTable<Observer>; - (void)playWarningSound { - if (!GetFramework().GetRoutingManager().GetSpeedCamManager().MakeBeepSignal()) + if (!GetFramework().GetRoutingManager().GetSpeedCamManager().ShouldPlayBeepSignal()) return; [self.audioPlayer play]; diff --git a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm index 2dd874029f..3b48c46ab3 100644 --- a/iphone/Maps/UI/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/UI/Settings/MWMSettingsViewController.mm @@ -214,7 +214,7 @@ extern NSString * const kAlohalyticsTapEventKey; info = L(@"speedcam_option_never"); break; case SpeedCameraManagerMode::MaxValue: - CHECK(false, ()); + CHECK(false, ("Unexpected mode SpeedCameraManagerMode::MaxValue.")); break; } diff --git a/iphone/Maps/UI/Settings/MWMSpeedCamSettingsController.mm b/iphone/Maps/UI/Settings/MWMSpeedCamSettingsController.mm index 8cadd60a02..449e19bc11 100644 --- a/iphone/Maps/UI/Settings/MWMSpeedCamSettingsController.mm +++ b/iphone/Maps/UI/Settings/MWMSpeedCamSettingsController.mm @@ -38,7 +38,7 @@ using namespace routing; _selectedCell = self.neverCell; break; case SpeedCameraManagerMode::MaxValue: - CHECK(false, ()); + CHECK(false, ("Invalid SpeedCameraManagerMode.")); break; } diff --git a/map/framework.hpp b/map/framework.hpp index bc72ecc3b4..40493529ff 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -671,7 +671,7 @@ private: /// @returns true if command was handled by drape. bool ParseDrapeDebugCommand(string const & query); - /// This function can be used for enabling some experimental features. + /// This function can be used for enabling some experimental features for routing. bool ParseRoutingDebugCommand(search::SearchParams const & params); void FillFeatureInfo(FeatureID const & fid, place_page::Info & info) const; diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index ff14f35e39..87f8d3fb11 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -12,6 +12,7 @@ #include "routing/online_absent_fetcher.hpp" #include "routing/route.hpp" #include "routing/routing_helpers.hpp" +#include "routing/speed_camera.hpp" #include "routing_common/num_mwm_id.hpp" @@ -34,6 +35,7 @@ #include "platform/socket.hpp" #include "base/scope_guard.hpp" +#include "base/string_utils.hpp" #include "3party/Alohalytics/src/alohalytics.h" #include "3party/jansson/myjansson.hpp" @@ -271,15 +273,26 @@ RoutingManager::RoutingManager(Callbacks && callbacks, Delegate & delegate) }); }); - m_routingSession.SetSpeedCamShowCallback([this](m2::PointD const & point) + m_routingSession.SetSpeedCamShowCallback([this](m2::PointD const & point, double cameraSpeedKmPH) { - GetPlatform().RunTask(Platform::Thread::Gui, [this, point]() + GetPlatform().RunTask(Platform::Thread::Gui, [this, point, cameraSpeedKmPH]() { auto editSession = m_bmManager->GetEditSession(); auto mark = editSession.CreateUserMark<SpeedCameraMark>(point); - // TODO (@gmoryes) change speed - mark->SetTitle("80"); + mark->SetIndex(0); + if (cameraSpeedKmPH == SpeedCameraOnRoute::kNoSpeedInfo) + return; + + double speed = cameraSpeedKmPH; + measurement_utils::Units units = measurement_utils::Units::Metric; + if (!settings::Get(settings::kMeasurementUnits, units)) + units = measurement_utils::Units::Metric; + + if (units == measurement_utils::Units::Imperial) + speed = measurement_utils::KmphToMph(cameraSpeedKmPH); + + mark->SetTitle(strings::to_string(static_cast<int>(speed + 0.5))); }); }); @@ -444,6 +457,7 @@ void RoutingManager::RemoveRoute(bool deactivateFollowing) GetPlatform().RunTask(Platform::Thread::Gui, [this, deactivateFollowing]() { m_bmManager->GetEditSession().ClearGroup(UserMark::Type::TRANSIT); + m_bmManager->GetEditSession().ClearGroup(UserMark::Type::SPEED_CAM); if (deactivateFollowing) SetPointsFollowingMode(false /* enabled */); diff --git a/routing/routing_callbacks.hpp b/routing/routing_callbacks.hpp index 6eef860d8d..264bc9b438 100644 --- a/routing/routing_callbacks.hpp +++ b/routing/routing_callbacks.hpp @@ -1,7 +1,5 @@ #pragma once -#include "indexer/feature_decl.hpp" - #include "geometry/point2d.hpp" #include "base/assert.hpp" @@ -50,7 +48,7 @@ using ReadyCallbackOwnership = std::function<void(std::shared_ptr<Route>, Router using RemoveRouteCallback = std::function<void(RouterResultCode)>; using RouteCallback = std::function<void(Route const &)>; using RoutingStatisticsCallback = std::function<void(std::map<std::string, std::string> const &)>; -using SpeedCameraShowCallback = std::function<void(m2::PointD const & point)>; +using SpeedCameraShowCallback = std::function<void(m2::PointD const & point, double cameraSpeedKmPH)>; using SpeedCameraClearCallback = std::function<void()>; inline std::string DebugPrint(RouterResultCode code) diff --git a/routing/routing_integration_tests/CMakeLists.txt b/routing/routing_integration_tests/CMakeLists.txt index 58cc350482..b6ab0bb996 100644 --- a/routing/routing_integration_tests/CMakeLists.txt +++ b/routing/routing_integration_tests/CMakeLists.txt @@ -9,18 +9,18 @@ project(routing_integration_tests) set( SRC - #bicycle_route_test.cpp - #bicycle_turn_test.cpp - #get_altitude_test.cpp - #online_cross_tests.cpp - #pedestrian_route_test.cpp - #road_graph_tests.cpp - #route_test.cpp + bicycle_route_test.cpp + bicycle_turn_test.cpp + get_altitude_test.cpp + online_cross_tests.cpp + pedestrian_route_test.cpp + road_graph_tests.cpp + route_test.cpp routing_test_tools.cpp routing_test_tools.hpp speed_camera_notifications_tests.cpp - #street_names_test.cpp - #turn_test.cpp + street_names_test.cpp + turn_test.cpp ) omim_add_test(${PROJECT_NAME} ${SRC}) diff --git a/routing/routing_integration_tests/speed_camera_notifications_tests.cpp b/routing/routing_integration_tests/speed_camera_notifications_tests.cpp index 95178a4eb3..c5eb74cfa8 100644 --- a/routing/routing_integration_tests/speed_camera_notifications_tests.cpp +++ b/routing/routing_integration_tests/speed_camera_notifications_tests.cpp @@ -85,7 +85,7 @@ bool CheckVoiceNotification(RoutingSession & routingSession) bool CheckBeepSignal(RoutingSession & routingSession) { - return routingSession.GetSpeedCamManager().ShouldPlayWarningSignal(); + return routingSession.GetSpeedCamManager().ShouldPlayBeepSignal(); } bool CheckZone(RoutingSession & routingSession, double speedKmPH, SpeedCameraManager::Interval interval) @@ -93,9 +93,9 @@ bool CheckZone(RoutingSession & routingSession, double speedKmPH, SpeedCameraMan SpeedCameraOnRoute const & closestCamera = routingSession.GetSpeedCamManager().GetClosestCamForTests(); CHECK(closestCamera.IsValid(), ("No speed camera found.")); - double speedMpS = routing::KMPH2MPS(speedKmPH); - double passedDist = routingSession.GetRouteForTests()->GetCurrentDistanceFromBeginMeters(); - double distToCamera = closestCamera.m_distFromBeginMeters - passedDist; + double const speedMpS = routing::KMPH2MPS(speedKmPH); + double const passedDist = routingSession.GetRouteForTests()->GetCurrentDistanceFromBeginMeters(); + double const distToCamera = closestCamera.m_distFromBeginMeters - passedDist; return interval == SpeedCameraManager::GetIntervalByDistToCam(distToCamera, speedMpS); } @@ -111,7 +111,7 @@ bool NoCameraFound(RoutingSession & routingSession) // Expected: Beep signal. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_1) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -121,7 +121,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_1) mode); { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.68126, 37.53551}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::ImpactZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -135,7 +135,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_1) // Expected: Beep signal. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_2) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -145,7 +145,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_2) mode); { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.74505, 37.61384}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::ImpactZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -159,7 +159,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_2) // Expected: Beep signal. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_3) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -170,7 +170,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_3) // No danger here. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.76766, 37.59260}, speedKmPH, routingSession); TEST(NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -179,7 +179,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_3) // Exceed speed limit in beep zone. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.76589, 37.58999}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::BeepSignalZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -196,7 +196,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_3) // Expected: Beep signal. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_4) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -206,14 +206,14 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_4) mode); { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.65647, 37.53643}, speedKmPH, routingSession); TEST(NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); TEST(!CheckBeepSignal(routingSession), ()); } { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.65671, 37.53236}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::ImpactZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -227,7 +227,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_4) // Expected: Voice notification. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_5) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -238,7 +238,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_5) // No danger here. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.76766, 37.59260}, speedKmPH, routingSession); TEST(NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -247,7 +247,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_5) // Exceed speed limit before beep zone. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.7660589, 37.5907827}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::VoiceNotificationZone), ()); TEST(CheckVoiceNotification(routingSession), ()); @@ -261,7 +261,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_5) // Expected: Voice notification, after it beep signal. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_6) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -272,7 +272,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_6) // Exceed speed limit before beep zone. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.7660589, 37.5907827}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::VoiceNotificationZone), ()); TEST(CheckVoiceNotification(routingSession), ()); @@ -281,7 +281,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_6) // Need intermediate ChangePosition to calculate passedDistance correctly. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.7656051, 37.5901564}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::VoiceNotificationZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -290,7 +290,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_6) // Exceed speed limit in beep zone. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.7654092, 37.5898876}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::BeepSignalZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -305,7 +305,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_6) // Expected: Voice notification, after it beep signal. UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_7) { - std::vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; + vector<SpeedCameraManagerMode> modes = {SpeedCameraManagerMode::Auto, SpeedCameraManagerMode::Always}; for (auto const mode : modes) { RoutingSession routingSession; @@ -316,7 +316,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_7) // Exceed speed limit before beep zone. { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.7659465, 37.590631}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::VoiceNotificationZone), ()); TEST(CheckVoiceNotification(routingSession), ()); @@ -325,7 +325,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_7) // Need intermediate ChangePosition to calculate passedDistance correctly. { - double speedKmPH = 60.0; + double const speedKmPH = 60.0; ChangePosition({55.7657867, 37.5904073}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::VoiceNotificationZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -334,7 +334,7 @@ UNIT_TEST(SpeedCameraNotification_AutoAlwaysMode_7) // No exceed speed limit in beep zone. { - double speedKmPH = 40.0; + double const speedKmPH = 40.0; ChangePosition({55.7656548, 37.5902138}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::BeepSignalZone), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -358,7 +358,7 @@ UNIT_TEST(SpeedCameraNotification_AlwaysMode_1) SpeedCameraManagerMode::Always); { - double speedKmPH = 40.0; + double const speedKmPH = 40.0; ChangePosition({55.7647619, 37.5890578}, speedKmPH, routingSession); TEST(CheckZone(routingSession, speedKmPH, SpeedCameraManager::Interval::ImpactZone), ()); TEST(CheckVoiceNotification(routingSession), ()); @@ -382,7 +382,7 @@ UNIT_TEST(SpeedCameraNotification_AutoMode_1) SpeedCameraManagerMode::Auto); { - double speedKmPH = 40.0; + double const speedKmPH = 40.0; ChangePosition({55.7647619, 37.5890578}, speedKmPH, routingSession); TEST(NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); @@ -401,25 +401,25 @@ UNIT_TEST(SpeedCameraNotification_NeverMode_1) SpeedCameraManagerMode::Never); { - double speedKmPH = 100.0; + double const speedKmPH = 100.0; ChangePosition({55.7647619, 37.5890578}, speedKmPH, routingSession); - TEST(NoCameraFound(routingSession), ()); + TEST(!NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); TEST(!CheckBeepSignal(routingSession), ()); } { - double speedKmPH = 200.0; + double const speedKmPH = 200.0; ChangePosition({55.7644126, 37.5886567}, speedKmPH, routingSession); - TEST(NoCameraFound(routingSession), ()); + TEST(!NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); TEST(!CheckBeepSignal(routingSession), ()); } { - double speedKmPH = 300.0; + double const speedKmPH = 300.0; ChangePosition({55.7633558, 37.587675}, speedKmPH, routingSession); - TEST(NoCameraFound(routingSession), ()); + TEST(!NoCameraFound(routingSession), ()); TEST(!CheckVoiceNotification(routingSession), ()); TEST(!CheckBeepSignal(routingSession), ()); } diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 4653e8062b..73a94b844e 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -135,7 +135,7 @@ void RoutingSession::RemoveRoute() m_moveAwayCounter = 0; m_turnNotificationsMgr.Reset(); - m_route = std::make_shared<Route>(string() /* router */, 0 /* route id */); + m_route = make_shared<Route>(string() /* router */, 0 /* route id */); m_speedCameraManager.Reset(); m_speedCameraManager.SetRoute(m_route); } @@ -288,8 +288,7 @@ RoutingSession::State RoutingSession::OnLocationPositionChanged(GpsInfo const & { SetState(OnRoute); - if (m_speedCameraManager.Enable()) - m_speedCameraManager.OnLocationPositionChanged(info); + m_speedCameraManager.OnLocationPositionChanged(info); } if (m_userCurrentPositionValid) diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 0099f27aad..1d3afd7a77 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -182,7 +182,7 @@ public: void AssignRouteForTesting(std::shared_ptr<Route> route, RouterResultCode e) { AssignRoute(route, e); } - bool IsSpeedLimitExceeded() const { return true; } + bool IsSpeedLimitExceeded() const { return m_speedCameraManager.IsSpeedLimitExceeded(); } SpeedCameraManager & GetSpeedCamManager() { return m_speedCameraManager; } std::shared_ptr<Route> GetRouteForTests() { return m_route; } diff --git a/routing/speed_camera.cpp b/routing/speed_camera.cpp index 9f807d92d3..f82a95e1a5 100644 --- a/routing/speed_camera.cpp +++ b/routing/speed_camera.cpp @@ -1,18 +1,19 @@ #include "routing/speed_camera.hpp" -#include "routing/routing_helpers.hpp" -#include "routing/speed_camera_manager.hpp" -#include "speed_camera.hpp" - namespace routing { bool SpeedCameraOnRoute::IsValid() const { - return m_position != m2::PointD::Zero(); + return m_position != m2::PointD::Max(); } void SpeedCameraOnRoute::Invalidate() { - m_position = m2::PointD::Zero(); + m_position = m2::PointD::Max(); +} + +bool SpeedCameraOnRoute::NoSpeed() const +{ + return m_maxSpeedKmH == kNoSpeedInfo; } } // namespace routing diff --git a/routing/speed_camera.hpp b/routing/speed_camera.hpp index c9436cabb0..9638679384 100644 --- a/routing/speed_camera.hpp +++ b/routing/speed_camera.hpp @@ -18,13 +18,13 @@ struct SpeedCameraOnRoute static uint8_t constexpr kNoSpeedInfo = std::numeric_limits<uint8_t>::max(); - bool NoSpeed() const { return m_maxSpeedKmH == kNoSpeedInfo; } + bool NoSpeed() const; bool IsValid() const; void Invalidate(); double m_distFromBeginMeters = 0.0; // Distance from beginning of route to current camera. uint8_t m_maxSpeedKmH = kNoSpeedInfo; // Maximum speed allowed by the camera. - m2::PointD m_position; // Equals m2::PointD::Zero() by default. + m2::PointD m_position = m2::PointD::Max(); }; } // namespace routing diff --git a/routing/speed_camera_manager.cpp b/routing/speed_camera_manager.cpp index 47ec037be6..2c454c8d27 100644 --- a/routing/speed_camera_manager.cpp +++ b/routing/speed_camera_manager.cpp @@ -3,7 +3,6 @@ #include "routing/speed_camera.hpp" #include "speed_camera_manager.hpp" - namespace routing { std::string const SpeedCameraManager::kSpeedCamModeKey = "speed_cam_mode"; @@ -14,49 +13,30 @@ SpeedCameraManager::SpeedCameraManager(turns::sound::NotificationManager & notif Reset(); uint32_t mode = 0; - if (settings::Get(kSpeedCamModeKey, mode) && - mode < static_cast<int>(SpeedCameraManagerMode::MaxValue)) + if (settings::Get(kSpeedCamModeKey, mode)) { + CHECK_LESS(mode, static_cast<int>(SpeedCameraManagerMode::MaxValue), ("Invalid speedcam mode.")); m_mode = static_cast<SpeedCameraManagerMode>(mode); } - else - { - m_mode = SpeedCameraManagerMode::Auto; - } - - //tmp code - m_mode = SpeedCameraManagerMode::Auto; - //end tmp code } //static SpeedCameraManager::Interval SpeedCameraManager::GetIntervalByDistToCam(double distanceToCameraMeters, double speedMpS) { - Interval interval; if (distanceToCameraMeters < kInfluenceZoneMeters) - { - interval = Interval::ImpactZone; - } - else - { - double beepDist = kBeepSignalTime * speedMpS; - if (distanceToCameraMeters < kInfluenceZoneMeters + beepDist) - interval = Interval::BeepSignalZone; - else - interval = Interval::VoiceNotificationZone; - } + return Interval::ImpactZone; + + double const beepDist = kBeepSignalTime * speedMpS; + if (distanceToCameraMeters < kInfluenceZoneMeters + beepDist) + return Interval::BeepSignalZone; - return interval; + return Interval::VoiceNotificationZone; } void SpeedCameraManager::OnLocationPositionChanged(location::GpsInfo const & info) { CHECK_THREAD_CHECKER(m_threadChecker, ()); - - if (!Enable()) - return; - CHECK(!m_route.expired(), ()); auto const passedDistanceMeters = m_route.lock()->GetCurrentDistanceFromBeginMeters(); @@ -65,8 +45,15 @@ void SpeedCameraManager::OnLocationPositionChanged(location::GpsInfo const & inf FindCamerasOnRouteAndCache(passedDistanceMeters); double distFromCurrentPosAndClosestCam = -1.0; + m_speedLimitExceeded = false; if (m_closestCamera.IsValid()) + { distFromCurrentPosAndClosestCam = m_closestCamera.m_distFromBeginMeters - passedDistanceMeters; + if (distFromCurrentPosAndClosestCam < -kInfluenceZoneMeters) + m_closestCamera.Invalidate(); + else + m_speedLimitExceeded = IsSpeedHigh(distFromCurrentPosAndClosestCam, info.m_speedMpS, m_closestCamera); + } // Step 2. Check cached cameras. Do it only after pass through closest camera. if (!m_cachedSpeedCameras.empty() && distFromCurrentPosAndClosestCam < 0) @@ -99,16 +86,16 @@ void SpeedCameraManager::OnLocationPositionChanged(location::GpsInfo const & inf SetNotificationFlags(passedDistanceMeters, info.m_speedMpS, m_closestCamera); // Step 3. Check UI camera (stop or not stop to highlight it). - if (m_currentHighlightedCamera.IsValid()) - { - auto const distToCameraMeters = - m_currentHighlightedCamera.m_distFromBeginMeters - passedDistanceMeters; + if (!m_currentHighlightedCamera.IsValid()) + return; - if (IsHighlightedCameraExpired(distToCameraMeters)) - { - m_speedCamClearCallback(); - m_currentHighlightedCamera.Invalidate(); - } + auto const distToCameraMeters = + m_currentHighlightedCamera.m_distFromBeginMeters - passedDistanceMeters; + + if (IsHighlightedCameraExpired(distToCameraMeters)) + { + m_speedCamClearCallback(); + m_currentHighlightedCamera.Invalidate(); } } @@ -127,7 +114,7 @@ void SpeedCameraManager::GenerateNotifications(std::vector<std::string> & notifi } } -bool SpeedCameraManager::ShouldPlayWarningSignal() +bool SpeedCameraManager::ShouldPlayBeepSignal() { CHECK_THREAD_CHECKER(m_threadChecker, ()); @@ -148,6 +135,7 @@ void SpeedCameraManager::ResetNotifications() { m_makeVoiceSignal = false; m_makeBeepSignal = false; + m_speedLimitExceeded = false; m_beepSignalCounter = 0; m_voiceSignalCounter = 0; } @@ -157,15 +145,23 @@ void SpeedCameraManager::Reset() CHECK_THREAD_CHECKER(m_threadChecker, ()); m_closestCamera.Invalidate(); + m_currentHighlightedCamera.Invalidate(); m_firstNotCheckedSpeedCameraIndex = 1; ResetNotifications(); m_speedCamClearCallback(); m_cachedSpeedCameras = std::queue<SpeedCameraOnRoute>(); } +bool SpeedCameraManager::IsSpeedLimitExceeded() const +{ + if (!m_closestCamera.IsValid()) + return false; + + return m_speedLimitExceeded; +} + void SpeedCameraManager::FindCamerasOnRouteAndCache(double passedDistanceMeters) { - CHECK(Enable(), ("Speed camera manager is off.")); CHECK(!m_route.expired(), ()); auto const & segments = m_route.lock()->GetRouteSegments(); @@ -208,6 +204,15 @@ void SpeedCameraManager::FindCamerasOnRouteAndCache(double passedDistanceMeters) m_firstNotCheckedSpeedCameraIndex = firstNotChecked; } +void SpeedCameraManager::PassCameraToUI(SpeedCameraOnRoute const & camera) +{ + // Clear previous speed cam in UI. + m_speedCamClearCallback(); + + m_currentHighlightedCamera = camera; + m_speedCamShowCallback(camera.m_position, camera.m_maxSpeedKmH); +} + bool SpeedCameraManager::IsSpeedHigh(double distanceToCameraMeters, double speedMpS, SpeedCameraOnRoute const & camera) const { @@ -216,6 +221,14 @@ bool SpeedCameraManager::IsSpeedHigh(double distanceToCameraMeters, double speed double const distToDangerousZone = distanceToCameraMeters - kInfluenceZoneMeters; + if (distToDangerousZone < 0) + { + if (distToDangerousZone < -kInfluenceZoneMeters) + return false; + + return speedMpS > routing::KMPH2MPS(camera.m_maxSpeedKmH); + } + if (speedMpS < routing::KMPH2MPS(camera.m_maxSpeedKmH)) return false; @@ -233,74 +246,75 @@ bool SpeedCameraManager::IsSpeedHigh(double distanceToCameraMeters, double speed return distToDangerousZone < distanceNeedsToSlowDown + kDistanceEpsilonMeters; } -bool SpeedCameraManager::SetNotificationFlags(double passedDistanceMeters, double speedMpS, +void SpeedCameraManager::SetNotificationFlags(double passedDistanceMeters, double speedMpS, SpeedCameraOnRoute const & camera) { - CHECK(m_mode != SpeedCameraManagerMode::Never, - ("This method should use only in Auto and Always mode.")); + if (!Enable()) + return; auto const distToCameraMeters = camera.m_distFromBeginMeters - passedDistanceMeters; Interval interval = SpeedCameraManager::GetIntervalByDistToCam(distToCameraMeters, speedMpS); switch (interval) { - case Interval::ImpactZone: + case Interval::ImpactZone: + { + if (IsSpeedHigh(distToCameraMeters, speedMpS, camera)) { - if (IsSpeedHigh(distToCameraMeters, speedMpS, camera)) - { - m_makeBeepSignal = true; - return true; - } - - // If we did voice notification, and didn't beep signal in |BeepSignalZone|, let's do it now. - if (m_voiceSignalCounter > 0 && m_beepSignalCounter == 0) - { - m_makeBeepSignal = true; - return true; - } - - if (m_mode == SpeedCameraManagerMode::Always) - { - m_makeVoiceSignal = true; - return true; - } - - return false; + m_makeBeepSignal = true; + return; } - case Interval::BeepSignalZone: + + // If we did voice notification, and didn't beep signal in |BeepSignalZone|, let's do it now. + // Only for Auto mode. + if (m_voiceSignalCounter > 0 && m_beepSignalCounter == 0 && + m_mode == SpeedCameraManagerMode::Auto) { - // If we exceeding speed limit, in |BeepSignalZone|, we should make "beep" signal. - if (IsSpeedHigh(distToCameraMeters, speedMpS, camera)) - { - m_makeBeepSignal = true; - return true; - } + m_makeBeepSignal = true; + return; + } - // If we did voice notification, we should do "beep" signal before |ImpactZone|. - if (m_voiceSignalCounter > 0) - { - m_makeBeepSignal = true; - return true; - } + if (m_mode == SpeedCameraManagerMode::Always) + { + m_makeVoiceSignal = true; + return; + } - return false; + return; + } + case Interval::BeepSignalZone: + { + // If we exceeding speed limit, in |BeepSignalZone|, we should make "beep" signal. + if (IsSpeedHigh(distToCameraMeters, speedMpS, camera)) + { + m_makeBeepSignal = true; + return; } - case Interval::VoiceNotificationZone: + + // If we did voice notification, we should do "beep" signal before |ImpactZone|. + if (m_voiceSignalCounter > 0) { - // If we exceeding speed limit, in |VoiceNotificationZone|, we should make "voice" - // notification. - if (IsSpeedHigh(distToCameraMeters, speedMpS, camera)) - { - m_makeVoiceSignal = true; - return true; - } + m_makeBeepSignal = true; + return; + } - return false; + return; + } + case Interval::VoiceNotificationZone: + { + // If we exceeding speed limit, in |VoiceNotificationZone|, we should make "voice" + // notification. + if (IsSpeedHigh(distToCameraMeters, speedMpS, camera)) + { + m_makeVoiceSignal = true; + return; } + + return; + } } - CHECK_SWITCH(); - return false; + UNREACHABLE(); } bool SpeedCameraManager::NeedUpdateClosestCamera(double distanceToCameraMeters, double speedMpS, @@ -334,4 +348,10 @@ bool SpeedCameraManager::NeedChangeHighlightedCamera(double distToCameraMeters, return false; } + +void SpeedCameraManager::SetMode(SpeedCameraManagerMode mode) +{ + m_mode = mode; + settings::Set(kSpeedCamModeKey, static_cast<int>(mode)); +} } // namespace routing diff --git a/routing/speed_camera_manager.hpp b/routing/speed_camera_manager.hpp index 24a6fc73fa..53441f5d54 100644 --- a/routing/speed_camera_manager.hpp +++ b/routing/speed_camera_manager.hpp @@ -30,14 +30,25 @@ enum class SpeedCameraManagerMode MaxValue }; +// This class represents manager for speed cameras. On each changing of position +// called the |OnLocationPositionChanged()| method, that finds cameras on the following +// route and cache them. +// We use next system of notifications: +// 3 Modes: +// 1) Auto - default +// 2) Always +// 3) Never +// In |Auto| mode we warn about cameras only if user has a risk of exceeding speed limit. +// In |Always| mode we warn about cameras no matter user exceed speed limit or not. +// In |Never| we just cache cameras for highlighting in UI (in |Auto|, |Always| make highlighting too). +// +// Also we use different notifications for different zones, see |enum class Interval| for more details. class SpeedCameraManager { public: static std::string const kSpeedCamModeKey; - SpeedCameraManager() = delete; - explicit SpeedCameraManager(turns::sound::NotificationManager & notificationManager); - ~SpeedCameraManager() { m_speedCamClearCallback(); } + explicit SpeedCameraManager(turns::sound::NotificationManager & notificationManager); enum class Interval { @@ -69,21 +80,19 @@ public: void OnLocationPositionChanged(location::GpsInfo const & info); + // See comments in |enum class Interval| + /// \brief |GenerateNotifications| about |VoiceNotificationZone| void GenerateNotifications(std::vector<std::string> & notifications); - bool ShouldPlayWarningSignal(); + /// \bried |ShouldPlayBeepSignal| about |BeepSignalZone| + bool ShouldPlayBeepSignal(); void ResetNotifications(); void Reset(); - void SetMode(SpeedCameraManagerMode mode) - { - m_mode = mode; - settings::Set(kSpeedCamModeKey, static_cast<int>(mode)); - } - + void SetMode(SpeedCameraManagerMode mode); SpeedCameraManagerMode GetMode() const { return m_mode; } - SpeedCameraOnRoute const & GetClosestCamForTests() const { return m_closestCamera; } + bool IsSpeedLimitExceeded() const; private: // According to https://en.wikibooks.org/wiki/Physics_Study_Guide/Frictional_coefficients @@ -126,16 +135,9 @@ private: void FindCamerasOnRouteAndCache(double passedDistanceMeters); - void PassCameraToUI(SpeedCameraOnRoute const & camera) - { - // Clear previous speed cam in UI. - m_speedCamClearCallback(); - - m_currentHighlightedCamera = camera; - m_speedCamShowCallback(camera.m_position); - } + void PassCameraToUI(SpeedCameraOnRoute const & camera); - bool SetNotificationFlags(double passedDistanceMeters, double speedMpS, SpeedCameraOnRoute const & camera); + void SetNotificationFlags(double passedDistanceMeters, double speedMpS, SpeedCameraOnRoute const & camera); bool IsSpeedHigh(double distanceToCameraMeters, double speedMpS, SpeedCameraOnRoute const & camera) const; bool NeedUpdateClosestCamera(double distanceToCameraMeters, double speedMpS, SpeedCameraOnRoute const & camera); bool NeedChangeHighlightedCamera(double distToCameraMeters, bool needUpdateClosestCamera) const; @@ -150,6 +152,9 @@ private: bool m_makeBeepSignal; bool m_makeVoiceSignal; + // Flag if we exceed speed limit now. + bool m_speedLimitExceeded; + // Queue of speedCams, that we have found, but they are too far, to make warning about them. std::queue<SpeedCameraOnRoute> m_cachedSpeedCameras; @@ -160,10 +165,11 @@ private: std::weak_ptr<Route> m_route; turns::sound::NotificationManager & m_notificationManager; - SpeedCameraShowCallback m_speedCamShowCallback = [](m2::PointD const & /* point */) {}; + SpeedCameraShowCallback m_speedCamShowCallback = [](m2::PointD const & /* point */, + double /* cameraSpeedKmPH */) {}; SpeedCameraClearCallback m_speedCamClearCallback = []() {}; - SpeedCameraManagerMode m_mode; + SpeedCameraManagerMode m_mode = SpeedCameraManagerMode::Auto; DECLARE_THREAD_CHECKER(m_threadChecker); }; |