MCPcopy Create free account
hub / github.com/comaps/comaps / ClosestValidMacro

Method ClosestValidMacro

libs/routing_common/maxspeed_conversion.cpp:273–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273SpeedInUnits MaxspeedConverter::ClosestValidMacro(SpeedInUnits const & speed) const
274{
275 auto it = m_speedToMacro.lower_bound(speed);
276 if (it == m_speedToMacro.end())
277 {
278 --it;
279 }
280 else if (speed == it->first)
281 {
282 return speed;
283 }
284 else if (it != m_speedToMacro.begin())
285 {
286 auto it2 = it;
287 --it2;
288
289 ASSERT(speed.GetUnits() == it->first.GetUnits() || speed.GetUnits() == it2->first.GetUnits(), ());
290 auto const Diff = [&speed](SpeedInUnits const & rhs)
291 {
292 if (speed.GetUnits() != rhs.GetUnits())
293 return std::numeric_limits<int>::max();
294 return abs(int(rhs.GetSpeed()) - int(speed.GetSpeed()));
295 };
296
297 if (Diff(it2->first) < Diff(it->first))
298 it = it2;
299 }
300
301 return it->first;
302}
303
304// static
305MaxspeedConverter const & MaxspeedConverter::Instance()

Callers 2

UNIT_TESTFunction · 0.80

Calls 5

ASSERTFunction · 0.85
endMethod · 0.45
beginMethod · 0.45
GetUnitsMethod · 0.45
GetSpeedMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.64