Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/location.hpp7
-rw-r--r--routing/routing_tests/turns_sound_test.cpp105
-rw-r--r--routing/turns_sound.cpp45
-rw-r--r--routing/turns_sound_settings.cpp11
-rw-r--r--routing/turns_sound_settings.hpp10
5 files changed, 137 insertions, 41 deletions
diff --git a/platform/location.hpp b/platform/location.hpp
index 868299f057..d6dd544b52 100644
--- a/platform/location.hpp
+++ b/platform/location.hpp
@@ -94,6 +94,13 @@ namespace location
class FollowingInfo
{
public:
+ FollowingInfo()
+ : m_turn(routing::turns::TurnDirection::NoTurn),
+ m_exitNum(0),
+ m_time(0)
+ {
+ }
+
// SingleLaneInfoClient is used for passing information about a lane to client platforms such as
// Android, iOS and so on.
struct SingleLaneInfoClient
diff --git a/routing/routing_tests/turns_sound_test.cpp b/routing/routing_tests/turns_sound_test.cpp
index b0db9277fe..d47af5c2b3 100644
--- a/routing/routing_tests/turns_sound_test.cpp
+++ b/routing/routing_tests/turns_sound_test.cpp
@@ -118,12 +118,10 @@ UNIT_TEST(TurnsSoundMetersTest)
// So we start playing the first notification when the distance till the turn is less
// then 20 seconds * 30 meters per seconds + 100 meters = 700 meters.
turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 699. /* distanceToTurnMeters */);
- TEST_EQUAL(followInfo.m_turnNotifications.size(), 1, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_distanceUnits, 600, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_exitNum, 0, ());
- TEST(!followInfo.m_turnNotifications[0].m_useThenInsteadOfDistance, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_turnDir, TurnDirection::TurnRight, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_lengthUnits, LengthUnits::Meters, ());
+ vector<routing::turns::sound::Notification> const expectedNotification1 = {
+ {600 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::TurnRight, LengthUnits::Meters}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ());
// 650 meters till the turn. No sound notifications is required.
followInfo.m_turnNotifications.clear();
@@ -142,12 +140,10 @@ UNIT_TEST(TurnsSoundMetersTest)
// 99 meters till the turn. It's time to pronounce the second voice notification.
turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */);
- TEST_EQUAL(followInfo.m_turnNotifications.size(), 1, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_distanceUnits, 0, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_exitNum, 0, ());
- TEST(!followInfo.m_turnNotifications[0].m_useThenInsteadOfDistance, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_turnDir, TurnDirection::TurnRight, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_lengthUnits, LengthUnits::Meters, ());
+ vector<routing::turns::sound::Notification> const expectedNotification2 = {
+ {0 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::TurnRight, LengthUnits::Meters}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ());
// 99 meters till the turn again. No sound notifications is required.
followInfo.m_turnNotifications.clear();
@@ -166,6 +162,71 @@ UNIT_TEST(TurnsSoundMetersTest)
TEST(turnSound.IsEnabled(), ());
}
+// Test case:
+// - Two turns;
+// - They are close to each other;
+// So the first notification of the second turn shall be skipped.
+UNIT_TEST(TurnsSoundMetersTwoTurnsTest)
+{
+ TurnsSound turnSound;
+ turnSound.Enable(true);
+ turnSound.SetSettings(settingsMeters);
+ turnSound.Reset();
+ turnSound.SetSpeedMetersPerSecond(35.);
+
+ TurnItem turnItem1(5 /* idx */, TurnDirection::TurnSharpRight);
+ FollowingInfo followInfo;
+
+ ASSERT(followInfo.m_turnNotifications.empty(), ());
+
+ // Starting nearing the first turn.
+ // 800 meters till the turn. No sound notifications is required.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 800. /* distanceToTurnMeters */);
+ TEST(followInfo.m_turnNotifications.empty(), ());
+
+ // 700 meters till the turn. It's time to pronounce the first voice notification.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 700. /* distanceToTurnMeters */);
+ vector<routing::turns::sound::Notification> const expectedNotification1 = {
+ {700 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::TurnSharpRight, LengthUnits::Meters}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ());
+
+ turnSound.SetSpeedMetersPerSecond(32.);
+
+ // 150 meters till the turn. No sound notifications is required.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 150. /* distanceToTurnMeters */);
+ TEST(followInfo.m_turnNotifications.empty(), ());
+
+ // 99 meters till the turn. It's time to pronounce the second voice notification.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 99. /* distanceToTurnMeters */);
+ vector<routing::turns::sound::Notification> const expectedNotification2 = {
+ {0 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::TurnSharpRight, LengthUnits::Meters}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ());
+
+ turnSound.SetSpeedMetersPerSecond(10.);
+
+ // 0 meters till the turn. No sound notifications is required.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 0. /* distanceToTurnMeters */);
+ TEST(followInfo.m_turnNotifications.empty(), ());
+
+ TurnItem turnItem2(11 /* idx */, TurnDirection::EnterRoundAbout, 2 /* exitNum */);
+
+ // Starting nearing the second turn.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem2, 60. /* distanceToTurnMeters */);
+ TEST(followInfo.m_turnNotifications.empty(), ());
+
+ // 40 meters till the second turn. It's time to pronounce the second voice notification
+ // without the first one.
+ turnSound.UpdateRouteFollowingInfo(followInfo, turnItem2, 40. /* distanceToTurnMeters */);
+ vector<routing::turns::sound::Notification> const expectedNotification3 = {
+ {0 /* m_distanceUnits */, 2 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::EnterRoundAbout, LengthUnits::Meters}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification3, ());
+
+ TEST(turnSound.IsEnabled(), ());
+}
+
UNIT_TEST(TurnsSoundFeetTest)
{
TurnsSound turnSound;
@@ -195,12 +256,10 @@ UNIT_TEST(TurnsSoundFeetTest)
// So we start playing the first notification when the distance till the turn is less
// then 20 seconds * 30 meters per seconds + 100 meters = 700 meters.
turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 699. /* distanceToTurnMeters */);
- TEST_EQUAL(followInfo.m_turnNotifications.size(), 1, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_distanceUnits, 2000, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_exitNum, 3, ());
- TEST(!followInfo.m_turnNotifications[0].m_useThenInsteadOfDistance, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_turnDir, TurnDirection::EnterRoundAbout, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_lengthUnits, LengthUnits::Feet, ());
+ vector<routing::turns::sound::Notification> const expectedNotification1 = {
+ {2000 /* m_distanceUnits */, 3 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::EnterRoundAbout, LengthUnits::Feet}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ());
// 650 meters till the turn. No sound notifications is required.
followInfo.m_turnNotifications.clear();
@@ -217,12 +276,10 @@ UNIT_TEST(TurnsSoundFeetTest)
// 99 meters till the turn. It's time to pronounce the second voice notification.
turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */);
- TEST_EQUAL(followInfo.m_turnNotifications.size(), 1, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_distanceUnits, 0, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_exitNum, 3, ());
- TEST(!followInfo.m_turnNotifications[0].m_useThenInsteadOfDistance, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_turnDir, TurnDirection::EnterRoundAbout, ());
- TEST_EQUAL(followInfo.m_turnNotifications[0].m_lengthUnits, LengthUnits::Feet, ());
+ vector<routing::turns::sound::Notification> const expectedNotification2 = {
+ {0 /* m_distanceUnits */, 3 /* m_exitNum */, false /* m_useThenInsteadOfDistance */,
+ TurnDirection::EnterRoundAbout, LengthUnits::Feet}};
+ TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ());
// 99 meters till the turn again. No sound notifications is required.
followInfo.m_turnNotifications.clear();
diff --git a/routing/turns_sound.cpp b/routing/turns_sound.cpp
index d6cac98ec6..288db3908d 100644
--- a/routing/turns_sound.cpp
+++ b/routing/turns_sound.cpp
@@ -51,27 +51,38 @@ void TurnsSound::UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnIt
if (m_nextNotificationProgress == PronouncedNotification::Nothing)
{
- double const currentSpeedUntisPerSecond =
- m_settings.ConvertMetersPerSecondToUnitsPerSecond(m_speedMetersPerSecond);
- double const turnNotificationDistUnits =
- m_settings.ComputeTurnDistance(currentSpeedUntisPerSecond);
- uint32_t const turnNotificationDistMeters =
- m_settings.ConvertUnitsToMeters(turnNotificationDistUnits) + distanceToPronounceNotificationMeters;
-
- if (distanceToTurnMeters < turnNotificationDistMeters)
+ if (distanceToTurnMeters > kMaxStartBeforeMeters)
{
- // First turn sound notification.
- uint32_t const distToPronounce =
- m_settings.RoundByPresetSoundedDistancesUnits(turnNotificationDistUnits);
- info.m_turnNotifications.emplace_back(distToPronounce, turn.m_exitNum, false, turn.m_turn,
- m_settings.GetLengthUnits());
- // @TODO(vbykoianko) Check if there's a turn immediately after the current turn.
- // If so add an extra item to info.m_turnNotifications with "then parameter".
+ double const currentSpeedUntisPerSecond =
+ m_settings.ConvertMetersPerSecondToUnitsPerSecond(m_speedMetersPerSecond);
+ double const turnNotificationDistUnits =
+ m_settings.ComputeTurnDistance(currentSpeedUntisPerSecond);
+ uint32_t const turnNotificationDistMeters =
+ m_settings.ConvertUnitsToMeters(turnNotificationDistUnits) + distanceToPronounceNotificationMeters;
+
+ if (distanceToTurnMeters < turnNotificationDistMeters)
+ {
+ // First turn sound notification.
+ uint32_t const distToPronounce =
+ m_settings.RoundByPresetSoundedDistancesUnits(turnNotificationDistUnits);
+ info.m_turnNotifications.emplace_back(distToPronounce, turn.m_exitNum, false, turn.m_turn,
+ m_settings.GetLengthUnits());
+ // @TODO(vbykoianko) Check if there's a turn immediately after the current turn.
+ // If so add an extra item to info.m_turnNotifications with "then parameter".
+ m_nextNotificationProgress = PronouncedNotification::First;
+ }
+ }
+ else
+ {
+ // The first notification has not been pronounced but the distance to the turn is too short.
+ // It happens if one turn follows shortly behind another one.
m_nextNotificationProgress = PronouncedNotification::First;
}
+ return;
}
- else if (m_nextNotificationProgress == PronouncedNotification::First &&
- distanceToTurnMeters < distanceToPronounceNotificationMeters)
+
+ if (m_nextNotificationProgress == PronouncedNotification::First &&
+ distanceToTurnMeters < distanceToPronounceNotificationMeters)
{
info.m_turnNotifications.emplace_back(0, turn.m_exitNum, false, turn.m_turn,
m_settings.GetLengthUnits());
diff --git a/routing/turns_sound_settings.cpp b/routing/turns_sound_settings.cpp
index ba78ba6b7f..223235bf64 100644
--- a/routing/turns_sound_settings.cpp
+++ b/routing/turns_sound_settings.cpp
@@ -93,6 +93,17 @@ string DebugPrint(LengthUnits const & lengthUnits)
out << "Unknown LengthUnits value: " << static_cast<int>(lengthUnits);
return out.str();
}
+
+string DebugPrint(Notification const & notification)
+{
+ stringstream out;
+ out << "Notification [ m_distanceUnits == " << notification.m_distanceUnits
+ << ", m_exitNum == " << notification.m_exitNum
+ << ", m_useThenInsteadOfDistance == " << notification.m_useThenInsteadOfDistance
+ << ", m_turnDir == " << DebugPrint(notification.m_turnDir)
+ << ", m_lengthUnits == " << DebugPrint(notification.m_lengthUnits) << " ]" << endl;
+ return out.str();
+}
} // namespace sound
} // namespace turns
} // namespace routing
diff --git a/routing/turns_sound_settings.hpp b/routing/turns_sound_settings.hpp
index 79a815c3fb..a6d6493608 100644
--- a/routing/turns_sound_settings.hpp
+++ b/routing/turns_sound_settings.hpp
@@ -92,8 +92,18 @@ struct Notification
m_lengthUnits(lengthUnits)
{
}
+ bool operator==(Notification const & rhv) const
+ {
+ return m_distanceUnits == rhv.m_distanceUnits && m_exitNum == rhv.m_exitNum &&
+ m_useThenInsteadOfDistance == rhv.m_useThenInsteadOfDistance &&
+ m_turnDir == rhv.m_turnDir && m_lengthUnits == rhv.m_lengthUnits;
+ }
+
inline bool IsValid() const { return m_lengthUnits != LengthUnits::Undefined; }
};
+
+string DebugPrint(Notification const & turnGeom);
+
} // namespace sound
} // namespace turns
} // namespace routing