Use common function for clamping logic for all user-visible bearings.
This commit is contained in:
parent
67ce19cb14
commit
a51ef67db8
@ -40,6 +40,11 @@ util::json::Array coordinateToLonLat(const util::Coordinate coordinate);
|
|||||||
|
|
||||||
std::string modeToString(const extractor::TravelMode mode);
|
std::string modeToString(const extractor::TravelMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that a bearing value is a whole number, and clamped to the range 0-359
|
||||||
|
*/
|
||||||
|
inline double roundAndClampBearing(double bearing) { return std::fmod(std::round(bearing), 360); }
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <unsigned POLYLINE_PRECISION, typename ForwardIter>
|
template <unsigned POLYLINE_PRECISION, typename ForwardIter>
|
||||||
|
@ -192,8 +192,8 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver)
|
|||||||
detail::instructionModifierToString(maneuver.instruction.direction_modifier);
|
detail::instructionModifierToString(maneuver.instruction.direction_modifier);
|
||||||
|
|
||||||
step_maneuver.values["location"] = detail::coordinateToLonLat(maneuver.location);
|
step_maneuver.values["location"] = detail::coordinateToLonLat(maneuver.location);
|
||||||
step_maneuver.values["bearing_before"] = std::fmod(std::round(maneuver.bearing_before), 360);
|
step_maneuver.values["bearing_before"] = detail::roundAndClampBearing(maneuver.bearing_before);
|
||||||
step_maneuver.values["bearing_after"] = std::fmod(std::round(maneuver.bearing_after), 360);
|
step_maneuver.values["bearing_after"] = detail::roundAndClampBearing(maneuver.bearing_after);
|
||||||
if (maneuver.exit != 0)
|
if (maneuver.exit != 0)
|
||||||
step_maneuver.values["exit"] = maneuver.exit;
|
step_maneuver.values["exit"] = maneuver.exit;
|
||||||
|
|
||||||
@ -207,11 +207,10 @@ util::json::Object makeIntersection(const guidance::Intersection &intersection)
|
|||||||
util::json::Array entry;
|
util::json::Array entry;
|
||||||
|
|
||||||
bearings.values.reserve(intersection.bearings.size());
|
bearings.values.reserve(intersection.bearings.size());
|
||||||
std::transform(
|
std::transform(intersection.bearings.begin(),
|
||||||
intersection.bearings.begin(),
|
|
||||||
intersection.bearings.end(),
|
intersection.bearings.end(),
|
||||||
std::back_inserter(bearings.values),
|
std::back_inserter(bearings.values),
|
||||||
[](const double bearing) -> util::json::Value { BOOST_ASSERT(bearing != 360.0); return std::fmod(bearing, 360); });
|
detail::roundAndClampBearing);
|
||||||
|
|
||||||
entry.values.reserve(intersection.entry.size());
|
entry.values.reserve(intersection.entry.size());
|
||||||
std::transform(intersection.entry.begin(),
|
std::transform(intersection.entry.begin(),
|
||||||
|
Loading…
Reference in New Issue
Block a user