refactor of post-processing
- moves collapse into a dedicated set of functions / files - make collapse scenarios distinct (slight performance cost) - reduce verbosity for short name segments (now actually working, was supposed to do so before)
This commit is contained in:
committed by
Patrick Niklaus
parent
8d83c3adbb
commit
6c3390f14d
@@ -5,13 +5,13 @@
|
||||
#include "engine/guidance/assemble_steps.hpp"
|
||||
#include "engine/guidance/lane_processing.hpp"
|
||||
|
||||
#include "engine/guidance/collapsing_utility.hpp"
|
||||
#include "util/bearing.hpp"
|
||||
#include "util/guidance/name_announcements.hpp"
|
||||
#include "util/guidance/turn_lanes.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
#include <boost/range/algorithm_ext/erase.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -20,9 +20,6 @@
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
using TurnInstruction = osrm::extractor::guidance::TurnInstruction;
|
||||
namespace TurnType = osrm::extractor::guidance::TurnType;
|
||||
namespace DirectionModifier = osrm::extractor::guidance::DirectionModifier;
|
||||
using osrm::util::angularDeviation;
|
||||
using osrm::extractor::guidance::getTurnDirection;
|
||||
using osrm::extractor::guidance::hasRampType;
|
||||
@@ -38,67 +35,6 @@ namespace guidance
|
||||
|
||||
namespace
|
||||
{
|
||||
const constexpr std::size_t MIN_END_OF_ROAD_INTERSECTIONS = std::size_t{2};
|
||||
const constexpr double MAX_COLLAPSE_DISTANCE = 30;
|
||||
|
||||
// check if at least one of the turns is actually a maneuver
|
||||
inline bool hasManeuver(const RouteStep &first, const RouteStep &second)
|
||||
{
|
||||
return (first.maneuver.instruction.type != TurnType::Suppressed ||
|
||||
second.maneuver.instruction.type != TurnType::Suppressed) &&
|
||||
(first.maneuver.instruction.type != TurnType::NoTurn &&
|
||||
second.maneuver.instruction.type != TurnType::NoTurn);
|
||||
}
|
||||
|
||||
inline bool choiceless(const RouteStep &step, const RouteStep &previous)
|
||||
{
|
||||
// if the next turn is choiceless, we consider longer turn roads collapsable than usually
|
||||
// accepted. We might need to improve this to find out whether we merge onto a through-street.
|
||||
BOOST_ASSERT(!step.intersections.empty());
|
||||
const auto is_without_choice = previous.distance < 4 * MAX_COLLAPSE_DISTANCE &&
|
||||
1 >= std::count(step.intersections.front().entry.begin(),
|
||||
step.intersections.front().entry.end(),
|
||||
true);
|
||||
|
||||
return is_without_choice && step.maneuver.instruction.type != TurnType::EndOfRoad;
|
||||
}
|
||||
|
||||
// List of types that can be collapsed, if all other restrictions pass
|
||||
bool isCollapsableInstruction(const TurnInstruction instruction)
|
||||
{
|
||||
return instruction.type == TurnType::NewName ||
|
||||
(instruction.type == TurnType::Suppressed &&
|
||||
instruction.direction_modifier == DirectionModifier::Straight) ||
|
||||
(instruction.type == TurnType::Turn &&
|
||||
instruction.direction_modifier == DirectionModifier::Straight) ||
|
||||
(instruction.type == TurnType::Continue &&
|
||||
instruction.direction_modifier == DirectionModifier::Straight) ||
|
||||
(instruction.type == TurnType::Merge);
|
||||
}
|
||||
|
||||
bool compatible(const RouteStep &lhs, const RouteStep &rhs) { return lhs.mode == rhs.mode; }
|
||||
|
||||
// Checks if name change happens the user wants to know about.
|
||||
// Treats e.g. "Name (Ref)" -> "Name" changes still as same name.
|
||||
bool isNoticeableNameChange(const RouteStep &lhs, const RouteStep &rhs)
|
||||
{
|
||||
// TODO: rotary_name is not handled at the moment.
|
||||
return util::guidance::requiresNameAnnounced(
|
||||
lhs.name, lhs.ref, lhs.pronunciation, rhs.name, rhs.ref, rhs.pronunciation);
|
||||
}
|
||||
|
||||
double nameSegmentLength(std::size_t at, const std::vector<RouteStep> &steps)
|
||||
{
|
||||
BOOST_ASSERT(at < steps.size());
|
||||
|
||||
double result = steps[at].distance;
|
||||
while (at + 1 < steps.size() && !isNoticeableNameChange(steps[at], steps[at + 1]))
|
||||
{
|
||||
at += 1;
|
||||
result += steps[at].distance;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void fixFinalRoundabout(std::vector<RouteStep> &steps)
|
||||
{
|
||||
@@ -282,588 +218,8 @@ void closeOffRoundabout(const bool on_roundabout,
|
||||
}
|
||||
}
|
||||
|
||||
bool bearingsAreReversed(const double bearing_in, const double bearing_out)
|
||||
{
|
||||
// Nearly perfectly reversed angles have a difference close to 180 degrees (straight)
|
||||
const double left_turn_angle = [&]() {
|
||||
if (0 <= bearing_out && bearing_out <= bearing_in)
|
||||
return bearing_in - bearing_out;
|
||||
return bearing_in + 360 - bearing_out;
|
||||
}();
|
||||
return angularDeviation(left_turn_angle, 180) <= 35;
|
||||
}
|
||||
|
||||
bool isLinkroad(const RouteStep &pre_link_step,
|
||||
const RouteStep &link_step,
|
||||
const RouteStep &post_link_step)
|
||||
{
|
||||
const constexpr double MAX_LINK_ROAD_LENGTH = 60.0;
|
||||
return link_step.distance <= MAX_LINK_ROAD_LENGTH && link_step.name_id == EMPTY_NAMEID &&
|
||||
pre_link_step.name_id != EMPTY_NAMEID && post_link_step.name_id != EMPTY_NAMEID;
|
||||
}
|
||||
|
||||
bool isUTurn(const RouteStep &in_step, const RouteStep &out_step, const RouteStep &pre_in_step)
|
||||
{
|
||||
const bool is_possible_candidate =
|
||||
in_step.distance <= MAX_COLLAPSE_DISTANCE || choiceless(out_step, in_step) ||
|
||||
(isLinkroad(pre_in_step, in_step, out_step) && out_step.name_id != EMPTY_NAMEID &&
|
||||
pre_in_step.name_id != EMPTY_NAMEID && !isNoticeableNameChange(pre_in_step, out_step));
|
||||
const bool takes_u_turn = bearingsAreReversed(
|
||||
util::bearing::reverse(
|
||||
in_step.intersections.front().bearings[in_step.intersections.front().in]),
|
||||
out_step.intersections.front().bearings[out_step.intersections.front().out]);
|
||||
|
||||
return is_possible_candidate && takes_u_turn && compatible(in_step, out_step);
|
||||
}
|
||||
|
||||
double findTotalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_step)
|
||||
{
|
||||
const auto exit_intersection = exit_step.intersections.front();
|
||||
const auto exit_step_exit_bearing = exit_intersection.bearings[exit_intersection.out];
|
||||
const auto exit_step_entry_bearing =
|
||||
util::bearing::reverse(exit_intersection.bearings[exit_intersection.in]);
|
||||
|
||||
const auto entry_intersection = entry_step.intersections.front();
|
||||
const auto entry_step_entry_bearing =
|
||||
util::bearing::reverse(entry_intersection.bearings[entry_intersection.in]);
|
||||
const auto entry_step_exit_bearing = entry_intersection.bearings[entry_intersection.out];
|
||||
|
||||
const auto exit_angle =
|
||||
util::bearing::angleBetween(exit_step_entry_bearing, exit_step_exit_bearing);
|
||||
const auto entry_angle =
|
||||
util::bearing::angleBetween(entry_step_entry_bearing, entry_step_exit_bearing);
|
||||
|
||||
const double total_angle =
|
||||
util::bearing::angleBetween(entry_step_entry_bearing, exit_step_exit_bearing);
|
||||
// We allow for minor deviations from a straight line
|
||||
if (((entry_step.distance < MAX_COLLAPSE_DISTANCE && exit_step.intersections.size() == 1) ||
|
||||
(entry_angle <= 185 && exit_angle <= 185) || (entry_angle >= 175 && exit_angle >= 175)) &&
|
||||
angularDeviation(total_angle, 180) > 20)
|
||||
{
|
||||
// both angles are in the same direction, the total turn gets increased
|
||||
//
|
||||
// a ---- b
|
||||
// \
|
||||
// c
|
||||
// |
|
||||
// d
|
||||
//
|
||||
// Will be considered just like
|
||||
// a -----b
|
||||
// |
|
||||
// c
|
||||
// |
|
||||
// d
|
||||
return total_angle;
|
||||
}
|
||||
else
|
||||
{
|
||||
// to prevent ignoring angles like
|
||||
// a -- b
|
||||
// |
|
||||
// c -- d
|
||||
// We don't combine both turn angles here but keep the very first turn angle.
|
||||
// We choose the first one, since we consider the first maneuver in a merge range the
|
||||
// important one
|
||||
return entry_angle;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t getPreviousIndex(std::size_t index, const std::vector<RouteStep> &steps)
|
||||
{
|
||||
BOOST_ASSERT(index > 0);
|
||||
BOOST_ASSERT(index < steps.size());
|
||||
--index;
|
||||
while (index > 0 && steps[index].maneuver.instruction.type == TurnType::NoTurn)
|
||||
--index;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void collapseUTurn(std::vector<RouteStep> &steps,
|
||||
const std::size_t two_back_index,
|
||||
const std::size_t one_back_index,
|
||||
const std::size_t step_index)
|
||||
{
|
||||
BOOST_ASSERT(two_back_index < steps.size());
|
||||
BOOST_ASSERT(step_index < steps.size());
|
||||
BOOST_ASSERT(one_back_index < steps.size());
|
||||
const auto ¤t_step = steps[step_index];
|
||||
|
||||
// the simple case is a u-turn that changes directly into the in-name again
|
||||
const bool direct_u_turn = !isNoticeableNameChange(steps[two_back_index], current_step);
|
||||
|
||||
// however, we might also deal with a dual-collapse scenario in which we have to
|
||||
// additionall collapse a name-change as well
|
||||
const auto next_step_index = step_index + 1;
|
||||
const bool continues_with_name_change =
|
||||
(next_step_index < steps.size()) && compatible(steps[step_index], steps[next_step_index]) &&
|
||||
((steps[next_step_index].maneuver.instruction.type == TurnType::UseLane &&
|
||||
steps[next_step_index].maneuver.instruction.direction_modifier ==
|
||||
DirectionModifier::Straight) ||
|
||||
isCollapsableInstruction(steps[next_step_index].maneuver.instruction));
|
||||
const bool u_turn_with_name_change =
|
||||
continues_with_name_change && steps[next_step_index].name_id != EMPTY_NAMEID &&
|
||||
!isNoticeableNameChange(steps[two_back_index], steps[next_step_index]);
|
||||
|
||||
if (direct_u_turn || u_turn_with_name_change)
|
||||
{
|
||||
steps[one_back_index].ElongateBy(steps[step_index]);
|
||||
steps[step_index].Invalidate();
|
||||
if (u_turn_with_name_change)
|
||||
{
|
||||
BOOST_ASSERT_MSG(compatible(steps[one_back_index], steps[next_step_index]),
|
||||
"Compatibility should be transitive");
|
||||
steps[one_back_index].ElongateBy(steps[next_step_index]);
|
||||
steps[next_step_index].Invalidate(); // will be skipped due to the
|
||||
// continue statement at the
|
||||
// beginning of this function
|
||||
}
|
||||
steps[one_back_index].AdaptStepSignage(steps[two_back_index]);
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Continue;
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier = DirectionModifier::UTurn;
|
||||
}
|
||||
}
|
||||
|
||||
void collapseTurnAt(std::vector<RouteStep> &steps,
|
||||
const std::size_t two_back_index,
|
||||
const std::size_t one_back_index,
|
||||
const std::size_t step_index)
|
||||
{
|
||||
BOOST_ASSERT(step_index < steps.size());
|
||||
BOOST_ASSERT(one_back_index < steps.size());
|
||||
const auto ¤t_step = steps[step_index];
|
||||
const auto &one_back_step = steps[one_back_index];
|
||||
// Don't collapse roundabouts
|
||||
if (entersRoundabout(current_step.maneuver.instruction) ||
|
||||
entersRoundabout(one_back_step.maneuver.instruction))
|
||||
return;
|
||||
|
||||
// This function assumes driving on the right hand side of the streat
|
||||
BOOST_ASSERT(!one_back_step.intersections.empty() && !current_step.intersections.empty());
|
||||
|
||||
if (!hasManeuver(one_back_step, current_step))
|
||||
return;
|
||||
|
||||
// A maneuver is preceded by a name change if the instruction just before can be collapsed
|
||||
// normally or the instruction itself is collapsable and does not actually present a choice
|
||||
const auto maneuverPrecededByNameChange = [](const RouteStep &turning_point,
|
||||
const RouteStep &possible_name_change_location,
|
||||
const RouteStep &preceeding_step) {
|
||||
// the check against merge is a workaround for motorways
|
||||
if (possible_name_change_location.maneuver.instruction.type == TurnType::Merge ||
|
||||
!compatible(possible_name_change_location, preceeding_step))
|
||||
return false;
|
||||
|
||||
return collapsable(possible_name_change_location, turning_point) ||
|
||||
(isCollapsableInstruction(possible_name_change_location.maneuver.instruction) &&
|
||||
choiceless(possible_name_change_location, preceeding_step));
|
||||
};
|
||||
|
||||
// check if the actual turn we wan't to announce is delayed. This situation describes a turn
|
||||
// that is expressed by two turns,
|
||||
const auto isDelayedTurn = [](
|
||||
const RouteStep &opening_turn, const RouteStep &finishing_turn, const RouteStep &pre_turn) {
|
||||
// only possible if both are compatible
|
||||
if (!compatible(opening_turn, finishing_turn))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
const auto is_short_and_collapsable =
|
||||
opening_turn.distance <= MAX_COLLAPSE_DISTANCE &&
|
||||
isCollapsableInstruction(finishing_turn.maneuver.instruction);
|
||||
|
||||
const auto without_choice = choiceless(finishing_turn, opening_turn);
|
||||
|
||||
const auto is_not_too_long_and_choiceless =
|
||||
opening_turn.distance <= 2 * MAX_COLLAPSE_DISTANCE && without_choice;
|
||||
|
||||
// for ramps we allow longer stretches, since they are often on some major brides/large
|
||||
// roads. A combined distance of of 4 intersections would be to long for a normal
|
||||
// collapse. In case of a ramp though, we also account for situations that have the ramp
|
||||
// tagged late
|
||||
const auto is_delayed_turn_onto_a_ramp =
|
||||
opening_turn.distance <= 4 * MAX_COLLAPSE_DISTANCE && without_choice &&
|
||||
hasRampType(finishing_turn.maneuver.instruction);
|
||||
|
||||
const auto linkroad = isLinkroad(pre_turn, opening_turn, finishing_turn);
|
||||
|
||||
return !hasRampType(opening_turn.maneuver.instruction) &&
|
||||
(is_short_and_collapsable || is_not_too_long_and_choiceless || linkroad ||
|
||||
is_delayed_turn_onto_a_ramp);
|
||||
}
|
||||
};
|
||||
|
||||
// Handle possible u-turns
|
||||
if (isUTurn(one_back_step, current_step, steps[two_back_index]))
|
||||
collapseUTurn(steps, two_back_index, one_back_index, step_index);
|
||||
// Very Short New Name that will be suppressed. Turn location remains at current_step
|
||||
else if (maneuverPrecededByNameChange(current_step, one_back_step, steps[two_back_index]))
|
||||
{
|
||||
BOOST_ASSERT(two_back_index < steps.size());
|
||||
BOOST_ASSERT(!one_back_step.intersections.empty());
|
||||
if (TurnType::Merge == current_step.maneuver.instruction.type)
|
||||
{
|
||||
steps[step_index].maneuver.instruction.direction_modifier =
|
||||
mirrorDirectionModifier(steps[step_index].maneuver.instruction.direction_modifier);
|
||||
steps[step_index].maneuver.instruction.type = TurnType::Turn;
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool continue_or_suppressed =
|
||||
(TurnType::Continue == current_step.maneuver.instruction.type ||
|
||||
(TurnType::Suppressed == current_step.maneuver.instruction.type &&
|
||||
current_step.maneuver.instruction.direction_modifier !=
|
||||
DirectionModifier::Straight));
|
||||
|
||||
const bool turning_name =
|
||||
(TurnType::NewName == current_step.maneuver.instruction.type &&
|
||||
current_step.maneuver.instruction.direction_modifier !=
|
||||
DirectionModifier::Straight &&
|
||||
one_back_step.intersections.front().bearings.size() > 2);
|
||||
|
||||
if (continue_or_suppressed)
|
||||
steps[step_index].maneuver.instruction.type = TurnType::Turn;
|
||||
else if (turning_name)
|
||||
steps[step_index].maneuver.instruction.type = TurnType::Turn;
|
||||
else if (TurnType::UseLane == current_step.maneuver.instruction.type &&
|
||||
current_step.maneuver.instruction.direction_modifier !=
|
||||
DirectionModifier::Straight &&
|
||||
one_back_step.intersections.front().bearings.size() > 2)
|
||||
steps[step_index].maneuver.instruction.type = TurnType::Turn;
|
||||
|
||||
// A new name with a continue/turning suppressed/name requires the adaption of the
|
||||
// direction modifier. The combination of the in-bearing and the out bearing gives the
|
||||
// new modifier for the turn
|
||||
if (continue_or_suppressed || turning_name)
|
||||
{
|
||||
const auto in_bearing = [](const RouteStep &step) {
|
||||
return util::bearing::reverse(
|
||||
step.intersections.front().bearings[step.intersections.front().in]);
|
||||
};
|
||||
const auto out_bearing = [](const RouteStep &step) {
|
||||
return step.intersections.front().bearings[step.intersections.front().out];
|
||||
};
|
||||
|
||||
const auto first_angle = util::bearing::angleBetween(in_bearing(one_back_step),
|
||||
out_bearing(one_back_step));
|
||||
const auto second_angle = util::bearing::angleBetween(in_bearing(current_step),
|
||||
out_bearing(current_step));
|
||||
const auto bearing_turn_angle = util::bearing::angleBetween(
|
||||
in_bearing(one_back_step), out_bearing(current_step));
|
||||
|
||||
// When looking at an intersection, some angles, even though present, feel more like
|
||||
// a straight turn. This happens most often at segregated intersections.
|
||||
// We consider two cases
|
||||
// I) a shift in the road:
|
||||
//
|
||||
// a g h
|
||||
// . | |
|
||||
// b ---- c
|
||||
// | | .
|
||||
// f e d
|
||||
//
|
||||
// Where a-d technicall continues straight, even though the shift models it as a
|
||||
// slight left and a slight right turn.
|
||||
//
|
||||
// II) A curved road
|
||||
//
|
||||
// g h
|
||||
// | |
|
||||
// b ---- c
|
||||
// . | | .
|
||||
// a f e d
|
||||
//
|
||||
// where a-d is a curve passing by an intersection.
|
||||
//
|
||||
// We distinguish this case from other bearings though where the interpretation as
|
||||
// straight would end up disguising turns.
|
||||
|
||||
// check if there is another similar turn next to the turn itself
|
||||
const auto hasSimilarAngle = [&](const std::size_t index,
|
||||
const std::vector<short> &bearings) {
|
||||
return (angularDeviation(bearings[index],
|
||||
bearings[(index + 1) % bearings.size()]) <
|
||||
extractor::guidance::NARROW_TURN_ANGLE) ||
|
||||
(angularDeviation(
|
||||
bearings[index],
|
||||
bearings[(index + bearings.size() - 1) % bearings.size()]) <
|
||||
extractor::guidance::NARROW_TURN_ANGLE);
|
||||
};
|
||||
|
||||
const auto is_shift_or_curve = [&]() -> bool {
|
||||
// since we move an intersection modifier from a slight turn to a straight, we
|
||||
// need to make sure that there is not a similar angle which could prevent this
|
||||
// perception of angles to be true.
|
||||
if (hasSimilarAngle(one_back_step.intersections.front().in,
|
||||
one_back_step.intersections.front().bearings) ||
|
||||
hasSimilarAngle(current_step.intersections.front().out,
|
||||
current_step.intersections.front().bearings))
|
||||
return false;
|
||||
|
||||
// Check if we are on a potential curve, both angles go in the same direction
|
||||
if (angularDeviation(first_angle, second_angle) <
|
||||
extractor::guidance::FUZZY_ANGLE_DIFFERENCE)
|
||||
{
|
||||
// We limit perceptive angles to narrow turns. If the total turn is going to
|
||||
// be not-narrow, we assume it to be more than a simple curve.
|
||||
return angularDeviation(bearing_turn_angle,
|
||||
extractor::guidance::STRAIGHT_ANGLE) <
|
||||
extractor::guidance::NARROW_TURN_ANGLE;
|
||||
}
|
||||
// if one of the angles is a left turn and the other one is a right turn, we
|
||||
// nearly reverse the angle
|
||||
else if ((first_angle > extractor::guidance::STRAIGHT_ANGLE) !=
|
||||
(second_angle > extractor::guidance::STRAIGHT_ANGLE))
|
||||
{
|
||||
// since we are not in a curve, we can check for a shift. If we are going
|
||||
// nearly straight, we call it a shift.
|
||||
return angularDeviation(bearing_turn_angle,
|
||||
extractor::guidance::STRAIGHT_ANGLE) <
|
||||
extractor::guidance::NARROW_TURN_ANGLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}();
|
||||
|
||||
// if the angles continue similar, it looks like we might be in a normal curve
|
||||
if (is_shift_or_curve)
|
||||
steps[step_index].maneuver.instruction.direction_modifier =
|
||||
DirectionModifier::Straight;
|
||||
else
|
||||
steps[step_index].maneuver.instruction.direction_modifier =
|
||||
getTurnDirection(bearing_turn_angle);
|
||||
|
||||
// if the total direction of this turn is now straight, we can keep it suppressed/as
|
||||
// a new name. Else we have to interpret it as a turn.
|
||||
if (!is_shift_or_curve)
|
||||
steps[step_index].maneuver.instruction.type = TurnType::Turn;
|
||||
else
|
||||
steps[step_index].maneuver.instruction.type = TurnType::NewName;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto total_angle = findTotalTurnAngle(steps[one_back_index], current_step);
|
||||
steps[step_index].maneuver.instruction.direction_modifier =
|
||||
getTurnDirection(total_angle);
|
||||
}
|
||||
}
|
||||
|
||||
steps[two_back_index].ElongateBy(one_back_step);
|
||||
// If the previous instruction asked to continue, the name change will have to
|
||||
// be changed into a turn
|
||||
steps[one_back_index].Invalidate();
|
||||
}
|
||||
// very short segment after turn, turn location remains at one_back_step
|
||||
else if (isDelayedTurn(
|
||||
one_back_step, current_step, steps[two_back_index])) // checks for compatibility
|
||||
{
|
||||
steps[one_back_index].ElongateBy(steps[step_index]);
|
||||
// TODO check for lanes (https://github.com/Project-OSRM/osrm-backend/issues/2553)
|
||||
if (TurnType::Continue == one_back_step.maneuver.instruction.type &&
|
||||
isNoticeableNameChange(steps[two_back_index], current_step))
|
||||
{
|
||||
if (current_step.maneuver.instruction.type == TurnType::OnRamp ||
|
||||
current_step.maneuver.instruction.type == TurnType::OffRamp)
|
||||
steps[one_back_index].maneuver.instruction.type =
|
||||
current_step.maneuver.instruction.type;
|
||||
else
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Turn;
|
||||
}
|
||||
else if (TurnType::Turn == one_back_step.maneuver.instruction.type &&
|
||||
!isNoticeableNameChange(steps[two_back_index], current_step))
|
||||
{
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Continue;
|
||||
|
||||
const auto getBearing = [](bool in, const RouteStep &step) {
|
||||
const auto index =
|
||||
in ? step.intersections.front().in : step.intersections.front().out;
|
||||
return step.intersections.front().bearings[index];
|
||||
};
|
||||
|
||||
// If we Merge onto the same street, we end up with a u-turn in some cases
|
||||
if (bearingsAreReversed(util::bearing::reverse(getBearing(true, one_back_step)),
|
||||
getBearing(false, current_step)))
|
||||
{
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier =
|
||||
DirectionModifier::UTurn;
|
||||
}
|
||||
steps[one_back_index].AdaptStepSignage(current_step);
|
||||
}
|
||||
else if (TurnType::NewName == one_back_step.maneuver.instruction.type ||
|
||||
(TurnType::NewName == current_step.maneuver.instruction.type &&
|
||||
steps[one_back_index].maneuver.instruction.type == TurnType::Suppressed))
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Turn;
|
||||
|
||||
if (TurnType::Merge == one_back_step.maneuver.instruction.type &&
|
||||
current_step.maneuver.instruction.type !=
|
||||
TurnType::Suppressed) // This suppressed is a check for highways. We might
|
||||
// need a highway-suppressed to get the turn onto a
|
||||
// highway...
|
||||
{
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier = mirrorDirectionModifier(
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier);
|
||||
}
|
||||
// on non merge-types, we check for a combined turn angle
|
||||
else if (TurnType::Merge != one_back_step.maneuver.instruction.type)
|
||||
{
|
||||
const auto combined_angle = findTotalTurnAngle(one_back_step, current_step);
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier =
|
||||
getTurnDirection(combined_angle);
|
||||
}
|
||||
|
||||
steps[one_back_index].name = current_step.name;
|
||||
steps[one_back_index].name_id = current_step.name_id;
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
else if (TurnType::Suppressed == current_step.maneuver.instruction.type &&
|
||||
!isNoticeableNameChange(one_back_step, current_step) &&
|
||||
compatible(one_back_step, current_step))
|
||||
{
|
||||
steps[one_back_index].ElongateBy(current_step);
|
||||
const auto angle = findTotalTurnAngle(one_back_step, current_step);
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier = getTurnDirection(angle);
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
else if (TurnType::Turn == one_back_step.maneuver.instruction.type &&
|
||||
TurnType::OnRamp == current_step.maneuver.instruction.type &&
|
||||
compatible(one_back_step, current_step))
|
||||
{
|
||||
// turning onto a ramp makes the first turn into a ramp
|
||||
steps[one_back_index].ElongateBy(current_step);
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::OnRamp;
|
||||
const auto angle = findTotalTurnAngle(one_back_step, current_step);
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier = getTurnDirection(angle);
|
||||
|
||||
steps[one_back_index].AdaptStepSignage(current_step);
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
// Staggered intersection are very short zig-zags of a few meters.
|
||||
// We do not want to announce these short left-rights or right-lefts:
|
||||
//
|
||||
// * -> b a -> *
|
||||
// | or | becomes a -> b
|
||||
// a -> * * -> b
|
||||
//
|
||||
bool isStaggeredIntersection(const std::vector<RouteStep> &steps,
|
||||
const std::size_t ¤t_index,
|
||||
const std::size_t &previous_index)
|
||||
{
|
||||
const RouteStep previous = steps[previous_index];
|
||||
const RouteStep current = steps[current_index];
|
||||
|
||||
// don't touch roundabouts
|
||||
if (entersRoundabout(previous.maneuver.instruction) ||
|
||||
entersRoundabout(current.maneuver.instruction))
|
||||
return false;
|
||||
// Base decision on distance since the zig-zag is a visual clue.
|
||||
// If adjusted, make sure to check validity of the is_right/is_left classification below
|
||||
const constexpr auto MAX_STAGGERED_DISTANCE = 3; // debatable, but keep short to be on safe side
|
||||
|
||||
const auto angle = [](const RouteStep &step) {
|
||||
const auto &intersection = step.intersections.front();
|
||||
const auto entry_bearing = intersection.bearings[intersection.in];
|
||||
const auto exit_bearing = intersection.bearings[intersection.out];
|
||||
return util::bearing::angleBetween(entry_bearing, exit_bearing);
|
||||
};
|
||||
|
||||
// Instead of using turn modifiers (e.g. as in isRightTurn) we want to be more strict here.
|
||||
// We do not want to trigger e.g. on sharp uturn'ish turns or going straight "turns".
|
||||
// Therefore we use the turn angle to derive 90 degree'ish right / left turns.
|
||||
// This more closely resembles what we understand as Staggered Intersection.
|
||||
// We have to be careful in cases with larger MAX_STAGGERED_DISTANCE values. If the distance
|
||||
// gets large, sharper angles might be not obvious enough to consider them a staggered
|
||||
// intersection. We might need to consider making the decision here dependent on the actual turn
|
||||
// angle taken. To do so, we could scale the angle-limits by a factor depending on the distance
|
||||
// between the turns.
|
||||
const auto is_right = [](const double angle) { return angle > 45 && angle < 135; };
|
||||
const auto is_left = [](const double angle) { return angle > 225 && angle < 315; };
|
||||
|
||||
const auto left_right = is_left(angle(previous)) && is_right(angle(current));
|
||||
const auto right_left = is_right(angle(previous)) && is_left(angle(current));
|
||||
|
||||
// A RouteStep holds distance/duration from the maneuver to the subsequent step.
|
||||
// We are only interested in the distance between the first and the second.
|
||||
const auto is_short = previous.distance < MAX_STAGGERED_DISTANCE;
|
||||
|
||||
auto intermediary_mode_change = false;
|
||||
if (current_index > 1)
|
||||
{
|
||||
const auto &two_back_index = getPreviousIndex(previous_index, steps);
|
||||
const auto two_back_step = steps[two_back_index];
|
||||
intermediary_mode_change =
|
||||
two_back_step.mode == current.mode && previous.mode != current.mode;
|
||||
}
|
||||
|
||||
// previous step maneuver intersections should be length 1 to indicate that
|
||||
// there are no intersections between the two potentially collapsible turns
|
||||
const auto no_intermediary_intersections = previous.intersections.size() == 1;
|
||||
|
||||
return is_short && (left_right || right_left) && !intermediary_mode_change &&
|
||||
no_intermediary_intersections;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// A check whether two instructions can be treated as one. This is only the case for very short
|
||||
// maneuvers that can, in some form, be seen as one. Lookahead of one step.
|
||||
bool collapsable(const RouteStep &step, const RouteStep &next)
|
||||
{
|
||||
const auto is_short_step = step.distance < MAX_COLLAPSE_DISTANCE;
|
||||
const auto instruction_can_be_collapsed = isCollapsableInstruction(step.maneuver.instruction);
|
||||
|
||||
const auto is_use_lane = step.maneuver.instruction.type == TurnType::UseLane;
|
||||
const auto lanes_dont_change =
|
||||
step.intersections.front().lanes == next.intersections.front().lanes;
|
||||
|
||||
if (is_short_step && instruction_can_be_collapsed)
|
||||
return true;
|
||||
|
||||
// Prevent collapsing away important lane change steps
|
||||
if (is_short_step && is_use_lane && lanes_dont_change)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Post processing can invalidate some instructions. For example StayOnRoundabout
|
||||
// is turned into exit counts. These instructions are removed by the following function
|
||||
|
||||
std::vector<RouteStep> removeNoTurnInstructions(std::vector<RouteStep> steps)
|
||||
{
|
||||
// finally clean up the post-processed instructions.
|
||||
// Remove all invalid instructions from the set of instructions.
|
||||
// An instruction is invalid, if its NO_TURN and has WaypointType::None.
|
||||
// Two valid NO_TURNs exist in each leg in the form of Depart/Arrive
|
||||
|
||||
// keep valid instructions
|
||||
const auto not_is_valid = [](const RouteStep &step) {
|
||||
return step.maneuver.instruction == TurnInstruction::NO_TURN() &&
|
||||
step.maneuver.waypoint_type == WaypointType::None;
|
||||
};
|
||||
|
||||
boost::remove_erase_if(steps, not_is_valid);
|
||||
|
||||
// the steps should still include depart and arrive at least
|
||||
BOOST_ASSERT(steps.size() >= 2);
|
||||
|
||||
BOOST_ASSERT(steps.front().intersections.size() >= 1);
|
||||
BOOST_ASSERT(steps.front().intersections.front().bearings.size() == 1);
|
||||
BOOST_ASSERT(steps.front().intersections.front().entry.size() == 1);
|
||||
BOOST_ASSERT(steps.front().maneuver.waypoint_type == WaypointType::Depart);
|
||||
|
||||
BOOST_ASSERT(steps.back().intersections.size() == 1);
|
||||
BOOST_ASSERT(steps.back().intersections.front().bearings.size() == 1);
|
||||
BOOST_ASSERT(steps.back().intersections.front().entry.size() == 1);
|
||||
BOOST_ASSERT(steps.back().maneuver.waypoint_type == WaypointType::Arrive);
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
// Every Step Maneuver consists of the information until the turn.
|
||||
// This list contains a set of instructions, called silent, which should
|
||||
// not be part of the final output.
|
||||
@@ -942,259 +298,6 @@ std::vector<RouteStep> postProcess(std::vector<RouteStep> steps)
|
||||
return removeNoTurnInstructions(std::move(steps));
|
||||
}
|
||||
|
||||
// Post Processing to collapse unnecessary sets of combined instructions into a single one
|
||||
std::vector<RouteStep> collapseTurns(std::vector<RouteStep> steps)
|
||||
{
|
||||
if (steps.size() <= 2)
|
||||
return steps;
|
||||
|
||||
const auto getPreviousNameIndex = [&steps](std::size_t index) {
|
||||
BOOST_ASSERT(index > 0);
|
||||
BOOST_ASSERT(index < steps.size());
|
||||
--index; // make sure to skip the current name
|
||||
while (index > 0 && steps[index].name_id == EMPTY_NAMEID)
|
||||
{
|
||||
--index;
|
||||
}
|
||||
return index;
|
||||
};
|
||||
|
||||
// a series of turns is only possible to collapse if its only name changes and suppressed turns.
|
||||
const auto canCollapseAll = [&steps](std::size_t index, const std::size_t end_index) {
|
||||
BOOST_ASSERT(end_index <= steps.size());
|
||||
if (!compatible(steps[index], steps[index + 1]))
|
||||
return false;
|
||||
++index;
|
||||
for (; index < end_index; ++index)
|
||||
{
|
||||
if (steps[index].maneuver.instruction.type != TurnType::Suppressed &&
|
||||
steps[index].maneuver.instruction.type != TurnType::NewName)
|
||||
return false;
|
||||
if (index + 1 < end_index && !compatible(steps[index], steps[index + 1]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// first and last instructions are waypoints that cannot be collapsed
|
||||
for (std::size_t step_index = 1; step_index + 1 < steps.size(); ++step_index)
|
||||
{
|
||||
const auto ¤t_step = steps[step_index];
|
||||
const auto next_step_index = step_index + 1;
|
||||
const auto one_back_index = getPreviousIndex(step_index, steps);
|
||||
|
||||
BOOST_ASSERT(one_back_index < steps.size());
|
||||
|
||||
const auto &one_back_step = steps[one_back_index];
|
||||
if (hasRoundaboutType(current_step.maneuver.instruction) ||
|
||||
hasRoundaboutType(one_back_step.maneuver.instruction))
|
||||
continue;
|
||||
|
||||
if (!hasManeuver(one_back_step, current_step))
|
||||
continue;
|
||||
|
||||
// how long has a name change to be so that we announce it, even as a bridge?
|
||||
const constexpr auto name_segment_cutoff_length = 100;
|
||||
const auto isBasicNameChange = [](const RouteStep &step) {
|
||||
return step.intersections.size() == 1 &&
|
||||
step.intersections.front().bearings.size() == 2 &&
|
||||
DirectionModifier::Straight == step.maneuver.instruction.direction_modifier;
|
||||
};
|
||||
|
||||
// Handle sliproads from motorways in urban areas, save from modifying depart, since
|
||||
// TurnType::Sliproad != TurnType::NoTurn
|
||||
if (one_back_step.maneuver.instruction.type == TurnType::Sliproad)
|
||||
{
|
||||
if (current_step.maneuver.instruction.type == TurnType::Suppressed &&
|
||||
compatible(one_back_step, current_step) && current_step.intersections.size() == 1 &&
|
||||
current_step.intersections.front().entry.size() == 2)
|
||||
{
|
||||
// Traffic light on the sliproad, the road itself will be handled in the next
|
||||
// iteration, when one-back-index again points to the sliproad.
|
||||
steps[one_back_index].ElongateBy(steps[step_index]);
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle possible u-turns between highways that look like slip-roads
|
||||
if (steps[getPreviousIndex(one_back_index, steps)].name_id ==
|
||||
steps[step_index].name_id &&
|
||||
steps[step_index].name_id != EMPTY_NAMEID)
|
||||
{
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Turn;
|
||||
}
|
||||
if (compatible(one_back_step, current_step))
|
||||
{
|
||||
// Turn Types in the response depend on whether we find the same road name
|
||||
// (sliproad indcating a u-turn) or if we are turning onto a different road, in
|
||||
// which case we use a turn.
|
||||
if (!isNoticeableNameChange(steps[getPreviousIndex(one_back_index, steps)],
|
||||
current_step) &&
|
||||
current_step.name_id != EMPTY_NAMEID)
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Continue;
|
||||
else
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Turn;
|
||||
|
||||
steps[one_back_index].ElongateBy(steps[step_index]);
|
||||
|
||||
steps[one_back_index].AdaptStepSignage(steps[step_index]);
|
||||
// the turn lanes for this turn are on the sliproad itself, so we have to
|
||||
// remember them
|
||||
steps[one_back_index].intersections.front().lanes =
|
||||
current_step.intersections.front().lanes;
|
||||
steps[one_back_index].intersections.front().lane_description =
|
||||
current_step.intersections.front().lane_description;
|
||||
|
||||
const auto angle = findTotalTurnAngle(one_back_step, current_step);
|
||||
steps[one_back_index].maneuver.instruction.direction_modifier =
|
||||
getTurnDirection(angle);
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// the sliproad turn is incompatible. So we handle it as a turn
|
||||
steps[one_back_index].maneuver.instruction.type = TurnType::Turn;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Due to empty segments, we can get name-changes from A->A
|
||||
// These have to be handled in post-processing
|
||||
else if (isCollapsableInstruction(current_step.maneuver.instruction) &&
|
||||
current_step.maneuver.instruction.type != TurnType::Suppressed &&
|
||||
!isNoticeableNameChange(steps[getPreviousNameIndex(step_index)], current_step) &&
|
||||
// canCollapseAll is also checking for compatible(step,step+1) for all indices
|
||||
canCollapseAll(getPreviousNameIndex(step_index), next_step_index))
|
||||
{
|
||||
BOOST_ASSERT(step_index > 0);
|
||||
const std::size_t last_available_name_index = getPreviousNameIndex(step_index);
|
||||
|
||||
for (std::size_t index = last_available_name_index + 1; index <= step_index; ++index)
|
||||
{
|
||||
steps[last_available_name_index].ElongateBy(steps[index]);
|
||||
steps[index].Invalidate();
|
||||
}
|
||||
}
|
||||
// If we look at two consecutive name changes, we can check for a name oscillation.
|
||||
// A name oscillation changes from name A shortly to name B and back to A.
|
||||
// In these cases, the name change will be suppressed.
|
||||
else if (one_back_index > 0 && compatible(current_step, one_back_step) &&
|
||||
((isCollapsableInstruction(current_step.maneuver.instruction) &&
|
||||
isCollapsableInstruction(one_back_step.maneuver.instruction)) ||
|
||||
isStaggeredIntersection(steps, step_index, one_back_index)))
|
||||
{
|
||||
const auto two_back_index = getPreviousIndex(one_back_index, steps);
|
||||
BOOST_ASSERT(two_back_index < steps.size());
|
||||
// valid, since one_back is collapsable or a turn and therefore not depart:
|
||||
if (!isNoticeableNameChange(steps[two_back_index], current_step))
|
||||
{
|
||||
if (compatible(one_back_step, steps[two_back_index]))
|
||||
{
|
||||
steps[two_back_index]
|
||||
.ElongateBy(steps[one_back_index])
|
||||
.ElongateBy(steps[step_index]);
|
||||
steps[one_back_index].Invalidate();
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
// TODO discuss: we could think about changing the new-name to a pure notification
|
||||
// about mode changes
|
||||
}
|
||||
else if (nameSegmentLength(one_back_index, steps) < name_segment_cutoff_length &&
|
||||
isBasicNameChange(one_back_step) && isBasicNameChange(current_step))
|
||||
{
|
||||
if (compatible(steps[two_back_index], steps[one_back_index]))
|
||||
{
|
||||
steps[two_back_index].ElongateBy(steps[one_back_index]);
|
||||
steps[one_back_index].Invalidate();
|
||||
if (nameSegmentLength(step_index, steps) < name_segment_cutoff_length &&
|
||||
compatible(steps[two_back_index], steps[step_index]))
|
||||
{
|
||||
steps[two_back_index].ElongateBy(steps[step_index]);
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (step_index + 2 < steps.size() &&
|
||||
current_step.maneuver.instruction.type == TurnType::NewName &&
|
||||
steps[next_step_index].maneuver.instruction.type == TurnType::NewName &&
|
||||
!isNoticeableNameChange(one_back_step, steps[next_step_index]))
|
||||
{
|
||||
if (compatible(steps[step_index], steps[next_step_index]))
|
||||
{
|
||||
// if we are crossing an intersection and go immediately after into a name
|
||||
// change,
|
||||
// we don't wan't to collapse the initial intersection.
|
||||
// a - b ---BRIDGE -- c
|
||||
steps[one_back_index]
|
||||
.ElongateBy(steps[step_index])
|
||||
.ElongateBy(steps[next_step_index]);
|
||||
steps[step_index].Invalidate();
|
||||
steps[next_step_index].Invalidate();
|
||||
}
|
||||
}
|
||||
else if (choiceless(current_step, one_back_step) ||
|
||||
one_back_step.distance <= MAX_COLLAPSE_DISTANCE)
|
||||
{
|
||||
// check for one of the multiple collapse scenarios and, if possible, collapse the
|
||||
// turn
|
||||
const auto two_back_index = getPreviousIndex(one_back_index, steps);
|
||||
BOOST_ASSERT(two_back_index < steps.size());
|
||||
collapseTurnAt(steps, two_back_index, one_back_index, step_index);
|
||||
}
|
||||
}
|
||||
else if (one_back_index > 0 &&
|
||||
(one_back_step.distance <= MAX_COLLAPSE_DISTANCE ||
|
||||
choiceless(current_step, one_back_step) ||
|
||||
isLinkroad(
|
||||
steps[getPreviousIndex(one_back_index, steps)], one_back_step, current_step)))
|
||||
{
|
||||
// check for one of the multiple collapse scenarios and, if possible, collapse the turn
|
||||
const auto two_back_index = getPreviousIndex(one_back_index, steps);
|
||||
BOOST_ASSERT(two_back_index < steps.size());
|
||||
// all turns that are handled lower down are also compatible
|
||||
collapseTurnAt(steps, two_back_index, one_back_index, step_index);
|
||||
}
|
||||
|
||||
if (steps[step_index].maneuver.instruction.type == TurnType::Turn)
|
||||
{
|
||||
const auto u_turn_one_back_index = getPreviousIndex(step_index, steps);
|
||||
if (u_turn_one_back_index > 0)
|
||||
{
|
||||
const auto u_turn_two_back_index = getPreviousIndex(u_turn_one_back_index, steps);
|
||||
if (isUTurn(steps[u_turn_one_back_index],
|
||||
steps[step_index],
|
||||
steps[u_turn_two_back_index]))
|
||||
{
|
||||
collapseUTurn(steps, u_turn_two_back_index, u_turn_one_back_index, step_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle final sliproad
|
||||
if (steps.size() >= 3 &&
|
||||
steps[getPreviousIndex(steps.size() - 1, steps)].maneuver.instruction.type ==
|
||||
TurnType::Sliproad)
|
||||
{
|
||||
steps[getPreviousIndex(steps.size() - 1, steps)].maneuver.instruction.type = TurnType::Turn;
|
||||
}
|
||||
|
||||
BOOST_ASSERT(steps.front().intersections.size() >= 1);
|
||||
BOOST_ASSERT(steps.front().intersections.front().bearings.size() == 1);
|
||||
BOOST_ASSERT(steps.front().intersections.front().entry.size() == 1);
|
||||
BOOST_ASSERT(steps.front().maneuver.waypoint_type == WaypointType::Depart);
|
||||
|
||||
BOOST_ASSERT(steps.back().intersections.size() == 1);
|
||||
BOOST_ASSERT(steps.back().intersections.front().bearings.size() == 1);
|
||||
BOOST_ASSERT(steps.back().intersections.front().entry.size() == 1);
|
||||
BOOST_ASSERT(steps.back().maneuver.waypoint_type == WaypointType::Arrive);
|
||||
|
||||
return removeNoTurnInstructions(std::move(steps));
|
||||
}
|
||||
|
||||
// Doing this step in post-processing provides a few challenges we cannot overcome.
|
||||
// The removal of an initial step imposes some copy overhead in the steps, moving all later
|
||||
// steps to the front. In addition, we cannot reduce the travel time that is accumulated at a
|
||||
@@ -1483,7 +586,7 @@ std::vector<RouteStep> buildIntersections(std::vector<RouteStep> steps)
|
||||
const auto instruction = step.maneuver.instruction;
|
||||
if (instruction.type == TurnType::Suppressed)
|
||||
{
|
||||
BOOST_ASSERT(compatible(steps[last_valid_instruction], step));
|
||||
BOOST_ASSERT(steps[last_valid_instruction].mode == step.mode);
|
||||
// count intersections. We cannot use exit, since intersections can follow directly
|
||||
// after a roundabout
|
||||
steps[last_valid_instruction].ElongateBy(step);
|
||||
@@ -1514,51 +617,6 @@ std::vector<RouteStep> buildIntersections(std::vector<RouteStep> steps)
|
||||
return removeNoTurnInstructions(std::move(steps));
|
||||
}
|
||||
|
||||
// `useLane` steps are only returned on `straight` maneuvers when there
|
||||
// are surrounding lanes also tagged as `straight`. If there are no other `straight`
|
||||
// lanes, it is not an ambiguous maneuver, and we can collapse the `useLane` step.
|
||||
std::vector<RouteStep> collapseUseLane(std::vector<RouteStep> steps)
|
||||
{
|
||||
const auto containsTag = [](const extractor::guidance::TurnLaneType::Mask mask,
|
||||
const extractor::guidance::TurnLaneType::Mask tag) {
|
||||
return (mask & tag) != extractor::guidance::TurnLaneType::empty;
|
||||
};
|
||||
|
||||
const auto canCollapseUseLane = [containsTag](const RouteStep &step) {
|
||||
// the lane description is given left to right, lanes are counted from the right.
|
||||
// Therefore we access the lane description using the reverse iterator
|
||||
|
||||
auto right_most_lanes = step.LanesToTheRight();
|
||||
if (!right_most_lanes.empty() && containsTag(right_most_lanes.front(),
|
||||
(extractor::guidance::TurnLaneType::straight |
|
||||
extractor::guidance::TurnLaneType::none)))
|
||||
return false;
|
||||
|
||||
auto left_most_lanes = step.LanesToTheLeft();
|
||||
if (!left_most_lanes.empty() && containsTag(left_most_lanes.back(),
|
||||
(extractor::guidance::TurnLaneType::straight |
|
||||
extractor::guidance::TurnLaneType::none)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
for (std::size_t step_index = 1; step_index < steps.size(); ++step_index)
|
||||
{
|
||||
const auto &step = steps[step_index];
|
||||
if (step.maneuver.instruction.type == TurnType::UseLane && canCollapseUseLane(step))
|
||||
{
|
||||
const auto previous = getPreviousIndex(step_index, steps);
|
||||
if (compatible(steps[previous], step))
|
||||
{
|
||||
steps[previous].ElongateBy(steps[step_index]);
|
||||
steps[step_index].Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
return removeNoTurnInstructions(std::move(steps));
|
||||
}
|
||||
|
||||
} // namespace guidance
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
Reference in New Issue
Block a user