2016-04-18 07:41:19 -04:00
|
|
|
#ifndef OSRM_ENGINE_GUIDANCE_TOOLKIT_HPP_
|
|
|
|
#define OSRM_ENGINE_GUIDANCE_TOOLKIT_HPP_
|
2016-03-01 16:30:31 -05:00
|
|
|
|
|
|
|
#include "extractor/guidance/turn_instruction.hpp"
|
2016-06-30 06:10:48 -04:00
|
|
|
#include "engine/guidance/route_step.hpp"
|
2016-03-01 16:30:31 -05:00
|
|
|
#include "util/bearing.hpp"
|
2016-06-30 06:10:48 -04:00
|
|
|
#include "util/guidance/toolkit.hpp"
|
2016-03-01 16:30:31 -05:00
|
|
|
|
2016-04-14 04:41:56 -04:00
|
|
|
#include <algorithm>
|
2016-06-30 06:10:48 -04:00
|
|
|
#include <iterator>
|
|
|
|
#include <utility>
|
2016-04-14 04:41:56 -04:00
|
|
|
|
2016-03-01 16:30:31 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
namespace guidance
|
|
|
|
{
|
|
|
|
|
2016-07-01 05:34:44 -04:00
|
|
|
using util::guidance::entersRoundabout;
|
|
|
|
using util::guidance::leavesRoundabout;
|
|
|
|
using util::guidance::staysOnRoundabout;
|
|
|
|
|
2016-03-01 16:30:31 -05:00
|
|
|
// Silent Turn Instructions are not to be mentioned to the outside world but
|
|
|
|
inline bool isSilent(const extractor::guidance::TurnInstruction instruction)
|
|
|
|
{
|
2016-03-03 09:36:03 -05:00
|
|
|
return instruction.type == extractor::guidance::TurnType::NoTurn ||
|
|
|
|
instruction.type == extractor::guidance::TurnType::Suppressed ||
|
2016-03-01 16:30:31 -05:00
|
|
|
instruction.type == extractor::guidance::TurnType::StayOnRoundabout;
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:26:07 -04:00
|
|
|
inline extractor::guidance::DirectionModifier::Enum angleToDirectionModifier(const double bearing)
|
2016-03-01 16:30:31 -05:00
|
|
|
{
|
|
|
|
if (bearing < 135)
|
|
|
|
{
|
|
|
|
return extractor::guidance::DirectionModifier::Right;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bearing <= 225)
|
|
|
|
{
|
|
|
|
return extractor::guidance::DirectionModifier::Straight;
|
|
|
|
}
|
|
|
|
return extractor::guidance::DirectionModifier::Left;
|
|
|
|
}
|
|
|
|
|
2016-06-30 06:10:48 -04:00
|
|
|
// Runs fn on RouteStep sub-ranges determined to be roundabouts.
|
|
|
|
// The function fn is getting called with a roundabout range as in: [enter, .., leave].
|
|
|
|
//
|
|
|
|
// The following situations are taken care for (i.e. we discard them):
|
|
|
|
// - partial roundabout: enter without exit or exit without enter
|
|
|
|
// - data issues: no roundabout, exit before enter
|
|
|
|
template <typename Iter, typename Fn> inline Fn forEachRoundabout(Iter first, Iter last, Fn fn)
|
|
|
|
{
|
|
|
|
while (first != last)
|
|
|
|
{
|
|
|
|
const auto enter = std::find_if(first, last, [](const RouteStep &step) {
|
|
|
|
return entersRoundabout(step.maneuver.instruction);
|
|
|
|
});
|
|
|
|
|
|
|
|
// enter has to come before leave, otherwise: faulty data / partial roundabout, skip those
|
|
|
|
const auto leave = std::find_if(enter, last, [](const RouteStep &step) {
|
|
|
|
return leavesRoundabout(step.maneuver.instruction);
|
|
|
|
});
|
|
|
|
|
|
|
|
// No roundabouts, or partial one (like start / end inside a roundabout)
|
|
|
|
if (enter == last || leave == last)
|
|
|
|
break;
|
|
|
|
|
|
|
|
(void)fn(std::make_pair(enter, leave));
|
|
|
|
|
|
|
|
// Skip to first step after the currently handled enter / leave pair
|
|
|
|
first = std::next(leave);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2016-03-01 16:30:31 -05:00
|
|
|
} // namespace guidance
|
|
|
|
} // namespace engine
|
|
|
|
} // namespace osrm
|
|
|
|
|
2016-04-18 07:41:19 -04:00
|
|
|
#endif /* OSRM_ENGINE_GUIDANCE_TOOLKIT_HPP_ */
|