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

turns_sound_settings.cpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c24102a8089a7bae0184a2a8659df8da6e9ca95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "routing/turns_sound_settings.hpp"

#include "platform/measurement_utils.hpp"

#include "base/string_utils.hpp"

#include "std/algorithm.hpp"

using namespace measurement_utils;

namespace routing
{
namespace turns
{
namespace sound
{
void Settings::SetState(uint32_t notificationTimeSeconds, uint32_t minNotificationDistanceUnits,
                        uint32_t maxNotificationDistanceUnits,
                        vector<uint32_t> const & soundedDistancesUnits,
                        measurement_utils::Units lengthUnits)
{
  m_timeSeconds = notificationTimeSeconds;
  m_minDistanceUnits = minNotificationDistanceUnits;
  m_maxDistanceUnits = maxNotificationDistanceUnits;
  m_soundedDistancesUnits = soundedDistancesUnits;
  m_lengthUnits = lengthUnits;
}

bool Settings::IsValid() const
{
  return m_minDistanceUnits <= m_maxDistanceUnits &&
         !m_soundedDistancesUnits.empty() &&
         is_sorted(m_soundedDistancesUnits.cbegin(), m_soundedDistancesUnits.cend());
}

uint32_t Settings::ComputeTurnDistanceM(double speedMetersPerSecond) const
{
  ASSERT(IsValid(), ());

  double const turnNotificationDistanceM = m_timeSeconds * speedMetersPerSecond;
  return static_cast<uint32_t>(my::clamp(turnNotificationDistanceM,
                                         ConvertUnitsToMeters(m_minDistanceUnits),
                                         ConvertUnitsToMeters(m_maxDistanceUnits)));
}

bool Settings::TooCloseForFisrtNotification(double distToTurnMeters) const
{
  return m_minDistToSayNotificationMeters >= distToTurnMeters;
}

uint32_t Settings::RoundByPresetSoundedDistancesUnits(uint32_t turnNotificationUnits) const
{
  ASSERT(IsValid(), ());

  auto it = upper_bound(m_soundedDistancesUnits.cbegin(), m_soundedDistancesUnits.cend(),
                        turnNotificationUnits, less_equal<uint32_t>());
  // Rounding up the result.
  if (it != m_soundedDistancesUnits.cend())
    return *it;

  ASSERT(false, ("m_soundedDistancesUnits shall contain bigger values."));
  return m_soundedDistancesUnits.empty() ? 0 : m_soundedDistancesUnits.back();
}

double Settings::ConvertMetersPerSecondToUnitsPerSecond(double speedInMetersPerSecond) const
{
  switch (m_lengthUnits)
  {
  case Units::Metric: return speedInMetersPerSecond;
  case Units::Imperial: return MetersToFeet(speedInMetersPerSecond);
  }

  ASSERT(false, ("m_lengthUnits is equal to unknown value."));
  return 0.;
}

double Settings::ConvertUnitsToMeters(double distanceInUnits) const
{
  switch (m_lengthUnits)
  {
  case Units::Metric: return distanceInUnits;
  case Units::Imperial: return FeetToMeters(distanceInUnits);
  }

  ASSERT(false, ());
  return 0.;
}

double Settings::ConvertMetersToUnits(double distanceInMeters) const
{
  switch (m_lengthUnits)
  {
  case Units::Metric: return distanceInMeters;
  case Units::Imperial: return MetersToFeet(distanceInMeters);
  }

  ASSERT(false, ());
  return 0.;
}

uint32_t Settings::ComputeDistToPronounceDistM(double speedMetersPerSecond) const
{
  ASSERT_LESS_OR_EQUAL(0, speedMetersPerSecond, ());
  uint32_t const startBeforeMeters =
      static_cast<uint32_t>(speedMetersPerSecond * m_startBeforeSeconds);
  return my::clamp(startBeforeMeters, m_minStartBeforeMeters, m_maxStartBeforeMeters);
}

string DebugPrint(Notification const & notification)
{
  string units;
  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();
}

VecPairDist const & GetAllSoundedDistMeters()
{
  // The vector below has to be sorted. It is checked in unit test GetAllSoundedDistMetersTest
  static VecPairDist const inst = {{50, "in_50_meters"},
                                   {100, "in_100_meters"},
                                   {200, "in_200_meters"},
                                   {250, "in_250_meters"},
                                   {300, "in_300_meters"},
                                   {400, "in_400_meters"},
                                   {500, "in_500_meters"},
                                   {600, "in_600_meters"},
                                   {700, "in_700_meters"},
                                   {750, "in_750_meters"},
                                   {800, "in_800_meters"},
                                   {900, "in_900_meters"},
                                   {1000, "in_1_kilometer"},
                                   {1500, "in_1_5_kilometers"},
                                   {2000, "in_2_kilometers"},
                                   {2500, "in_2_5_kilometers"},
                                   {3000, "in_3_kilometers"}};
  return inst;
}

VecPairDist const & GetAllSoundedDistFeet()
{
  // The vector below has to be sorted. It is checked in unit test GetAllSoundedDistFeet
  static VecPairDist const inst = {{50, "in_50_feet"},
                                   {100, "in_100_feet"},
                                   {200, "in_200_feet"},
                                   {300, "in_300_feet"},
                                   {400, "in_400_feet"},
                                   {500, "in_500_feet"},
                                   {600, "in_600_feet"},
                                   {700, "in_700_feet"},
                                   {800, "in_800_feet"},
                                   {900, "in_900_feet"},
                                   {1000, "in_1000_feet"},
                                   {1500, "in_1500_feet"},
                                   {2000, "in_2000_feet"},
                                   {2500, "in_2500_feet"},
                                   {3000, "in_3000_feet"},
                                   {3500, "in_3500_feet"},
                                   {4000, "in_4000_feet"},
                                   {4500, "in_4500_feet"},
                                   {5000, "in_5000_feet"},
                                   {5280, "in_1_mile"},
                                   {7920, "in_1_5_miles"},
                                   {10560, "in_2_miles"}};
  return inst;
}

vector<uint32_t> const & GetSoundedDistMeters()
{
  // The vector has to be sorted. Besides that any of its elements has to be contained in
  // the vector which GetAllSoundedDistMeters() returns.
  // It is checked in the unit test GetSoundedDistMeters.
  static vector<uint32_t> const inst = {200, 300, 400, 500, 600, 700, 800, 900, 1000, 1500, 2000};
  return inst;
}

vector<uint32_t> const & GetSoundedDistFeet()
{
  // The vector has to be sorted. Besides that any of its elements has to be contained in
  // the vector which GetAllSoundedDistFeet() returns.
  // It is checked in the unit test GetSoundedDistFeet.
  static vector<uint32_t> const inst = {500,  600,  700,  800,  900, 1000,
                                        1500, 2000, 3000, 4000, 5000};
  return inst;
}
}  // namespace sound
}  // namespace turns
}  // namespace routing