Upgrade clang-format to version 15 (#6859)

This commit is contained in:
Dennis Luxen
2024-05-06 09:14:46 +02:00
committed by GitHub
parent b503e96a98
commit 7f9d591ab7
156 changed files with 2357 additions and 1894 deletions
+9 -10
View File
@@ -40,22 +40,21 @@ unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometri
std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &leg_geometries,
const bool use_simplification)
{
auto overview_size =
std::accumulate(leg_geometries.begin(),
leg_geometries.end(),
0,
[](const std::size_t sum, const LegGeometry &leg_geometry) {
return sum + leg_geometry.locations.size();
}) -
leg_geometries.size() + 1;
auto overview_size = std::accumulate(leg_geometries.begin(),
leg_geometries.end(),
0,
[](const std::size_t sum, const LegGeometry &leg_geometry)
{ return sum + leg_geometry.locations.size(); }) -
leg_geometries.size() + 1;
std::vector<util::Coordinate> overview_geometry;
overview_geometry.reserve(overview_size);
using GeometryIter = decltype(overview_geometry)::const_iterator;
auto leg_reverse_index = leg_geometries.size();
const auto insert_without_overlap = [&leg_reverse_index, &overview_geometry](GeometryIter begin,
GeometryIter end) {
const auto insert_without_overlap =
[&leg_reverse_index, &overview_geometry](GeometryIter begin, GeometryIter end)
{
// not the last leg
if (leg_reverse_index > 1)
{
+15 -12
View File
@@ -7,18 +7,21 @@ namespace osrm::engine::guidance
Route assembleRoute(const std::vector<RouteLeg> &route_legs)
{
auto distance = std::accumulate(
route_legs.begin(), route_legs.end(), 0., [](const double sum, const RouteLeg &leg) {
return sum + leg.distance;
});
auto duration = std::accumulate(
route_legs.begin(), route_legs.end(), 0., [](const double sum, const RouteLeg &leg) {
return sum + leg.duration;
});
auto weight = std::accumulate(
route_legs.begin(), route_legs.end(), 0., [](const double sum, const RouteLeg &leg) {
return sum + leg.weight;
});
auto distance =
std::accumulate(route_legs.begin(),
route_legs.end(),
0.,
[](const double sum, const RouteLeg &leg) { return sum + leg.distance; });
auto duration =
std::accumulate(route_legs.begin(),
route_legs.end(),
0.,
[](const double sum, const RouteLeg &leg) { return sum + leg.duration; });
auto weight =
std::accumulate(route_legs.begin(),
route_legs.end(),
0.,
[](const double sum, const RouteLeg &leg) { return sum + leg.weight; });
return Route{distance, duration, weight};
}
@@ -102,7 +102,8 @@ bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection,
// 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 angle = [](const RouteStep &step)
{
const auto &intersection = step.intersections.front();
const auto entry_bearing = util::bearing::reverse(intersection.bearings[intersection.in]);
const auto exit_bearing = intersection.bearings[intersection.out];
+12 -6
View File
@@ -59,7 +59,8 @@ double findTotalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_ste
// c
// |
// d
const auto use_total_angle = [&]() {
const auto use_total_angle = [&]()
{
// only consider actual turns in combination:
if (angularDeviation(total_angle, 180) < 0.5 * NARROW_TURN_ANGLE)
return false;
@@ -99,7 +100,8 @@ inline void handleSliproad(RouteStepIterator sliproad_step)
{
// find the next step after the sliproad step itself (this is not necessarily the next step,
// since we might have to skip over traffic lights/node penalties)
auto next_step = [&sliproad_step]() {
auto next_step = [&sliproad_step]()
{
auto next_step = findNextTurn(sliproad_step);
while (isTrafficLightStep(*next_step))
{
@@ -196,7 +198,8 @@ void AdjustToCombinedTurnStrategy::operator()(RouteStep &step_at_turn_location,
: getTurnDirection(angle);
// a turn that is a new name or straight (turn/continue)
const auto is_non_turn = [](const RouteStep &step) {
const auto is_non_turn = [](const RouteStep &step)
{
return hasTurnType(step, TurnType::NewName) ||
(hasTurnType(step, TurnType::Turn) &&
hasModifier(step, DirectionModifier::Straight)) ||
@@ -307,7 +310,8 @@ void SegregatedTurnStrategy::operator()(RouteStep &step_at_turn_location,
// Used to control updating of the modifier based on turn direction
bool update_modifier_for_turn_direction = true;
const auto calculate_turn_angle = [](const RouteStep &entry_step, const RouteStep &exit_step) {
const auto calculate_turn_angle = [](const RouteStep &entry_step, const RouteStep &exit_step)
{
return util::bearing::angleBetween(entry_step.maneuver.bearing_before,
exit_step.maneuver.bearing_after);
};
@@ -316,7 +320,8 @@ void SegregatedTurnStrategy::operator()(RouteStep &step_at_turn_location,
const auto turn_angle = calculate_turn_angle(step_at_turn_location, transfer_from_step);
const auto turn_direction = getTurnDirection(turn_angle);
const auto is_straight_step = [](const RouteStep &step) {
const auto is_straight_step = [](const RouteStep &step)
{
return ((hasTurnType(step, TurnType::NewName) || hasTurnType(step, TurnType::Continue) ||
hasTurnType(step, TurnType::Suppressed) || hasTurnType(step, TurnType::Turn)) &&
(hasModifier(step, DirectionModifier::Straight) ||
@@ -324,7 +329,8 @@ void SegregatedTurnStrategy::operator()(RouteStep &step_at_turn_location,
hasModifier(step, DirectionModifier::SlightRight)));
};
const auto is_turn_step = [](const RouteStep &step) {
const auto is_turn_step = [](const RouteStep &step)
{
return (hasTurnType(step, TurnType::Turn) || hasTurnType(step, TurnType::Continue) ||
hasTurnType(step, TurnType::NewName) || hasTurnType(step, TurnType::Suppressed));
};
+123 -112
View File
@@ -17,7 +17,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
const double min_distance_needed_for_lane_change)
{
// Lane anticipation works on contiguous ranges of short steps that have lane information
const auto is_short_has_lanes = [&](const RouteStep &step) {
const auto is_short_has_lanes = [&](const RouteStep &step)
{
const auto has_lanes = step.intersections.front().lanes.lanes_in_turn > 0;
if (!has_lanes)
@@ -45,7 +46,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
std::vector<StepIterRange> quick_lanes_ranges;
const auto range_back_inserter = [&](StepIterRange range) {
const auto range_back_inserter = [&](StepIterRange range)
{
if (std::distance(range.first, range.second) > 1)
quick_lanes_ranges.push_back(std::move(range));
};
@@ -58,7 +60,8 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
// Walk backwards over all turns, constraining possible turn lanes.
// Later turn lanes constrain earlier ones: we have to anticipate lane changes.
const auto constrain_lanes = [&](const StepIterRange &turns) {
const auto constrain_lanes = [&](const StepIterRange &turns)
{
const std::reverse_iterator<StepIter> rev_first{turns.second};
const std::reverse_iterator<StepIter> rev_last{turns.first};
@@ -74,127 +77,135 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
// segment for a lane switch, but the total distance shouldn't be unlimited.
double distance_to_constrained = 0.0;
util::for_each_pair(rev_first, rev_last, [&](RouteStep &current, RouteStep &previous) {
const auto current_inst = current.maneuver.instruction;
const auto current_lanes = current.intersections.front().lanes;
// Constrain the previous turn's lanes
auto &previous_lanes = previous.intersections.front().lanes;
const auto previous_inst = previous.maneuver.instruction;
// Lane mapping (N:M) from previous lanes (N) to current lanes (M), with:
// N > M, N > 1 fan-in situation, constrain N lanes to min(N,M) shared lanes
// otherwise nothing to constrain
const bool lanes_to_constrain = previous_lanes.lanes_in_turn > 1;
const bool lanes_fan_in = previous_lanes.lanes_in_turn > current_lanes.lanes_in_turn;
// only prevent use lanes due to making all turns. don't make turns during curvy
// segments
if (previous_inst.type == TurnType::Suppressed)
distance_to_constrained += previous.distance;
else
distance_to_constrained = 0.;
const auto lane_delta = previous_lanes.lanes_in_turn - current_lanes.lanes_in_turn;
const auto can_make_all_turns =
distance_to_constrained > lane_delta * min_distance_needed_for_lane_change;
if (!lanes_to_constrain || !lanes_fan_in || can_make_all_turns)
return;
// We do not have a mapping from lanes to lanes. All we have is the lanes in the turn
// and all the lanes at that situation. To perfectly handle lane anticipation in cases
// where lanes in the turn fan in but for example the overall lanes at that location
// fan out, we would have to know the asymmetric mapping of lanes. This is currently
// not possible at the moment. In the following we implement a heuristic instead.
const LaneID current_num_lanes_right_of_turn = current.NumLanesToTheRight();
const LaneID current_num_lanes_left_of_turn = current.NumLanesToTheLeft();
// 0/ Tag keep straight with the next turn's direction if available
const auto previous_is_straight =
!isLeftTurn(previous_inst) && !isRightTurn(previous_inst);
if (previous_is_straight)
util::for_each_pair(
rev_first,
rev_last,
[&](RouteStep &current, RouteStep &previous)
{
if (isLeftTurn(current_inst) || is_straight_left.count(&current) > 0)
is_straight_left.insert(&previous);
else if (isRightTurn(current_inst) || is_straight_right.count(&current) > 0)
is_straight_right.insert(&previous);
}
const auto current_inst = current.maneuver.instruction;
const auto current_lanes = current.intersections.front().lanes;
// 1/ How to anticipate left, right:
const auto anticipate_for_left_turn = [&] {
// Current turn is left turn, already keep left during previous turn.
// This implies constraining the rightmost lanes in previous step.
LaneID new_first_lane_from_the_right =
previous_lanes.first_lane_from_the_right // start from rightmost lane
+ previous_lanes.lanes_in_turn // one past leftmost lane
- current_lanes.lanes_in_turn; // back number of new lanes
// Constrain the previous turn's lanes
auto &previous_lanes = previous.intersections.front().lanes;
const auto previous_inst = previous.maneuver.instruction;
// The leftmost target lanes might not be involved in the turn. Figure out
// how many lanes are to the left and not in the turn.
new_first_lane_from_the_right -=
std::min(current_num_lanes_left_of_turn, current_lanes.lanes_in_turn);
// Lane mapping (N:M) from previous lanes (N) to current lanes (M), with:
// N > M, N > 1 fan-in situation, constrain N lanes to min(N,M) shared lanes
// otherwise nothing to constrain
const bool lanes_to_constrain = previous_lanes.lanes_in_turn > 1;
const bool lanes_fan_in =
previous_lanes.lanes_in_turn > current_lanes.lanes_in_turn;
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
};
// only prevent use lanes due to making all turns. don't make turns during curvy
// segments
if (previous_inst.type == TurnType::Suppressed)
distance_to_constrained += previous.distance;
else
distance_to_constrained = 0.;
const auto anticipate_for_right_turn = [&] {
// Current turn is right turn, already keep right during the previous turn.
// This implies constraining the leftmost lanes in the previous turn step.
LaneID new_first_lane_from_the_right = previous_lanes.first_lane_from_the_right;
const auto lane_delta = previous_lanes.lanes_in_turn - current_lanes.lanes_in_turn;
const auto can_make_all_turns =
distance_to_constrained > lane_delta * min_distance_needed_for_lane_change;
// The rightmost target lanes might not be involved in the turn. Figure out
// how many lanes are to the right and not in the turn.
new_first_lane_from_the_right +=
std::min(current_num_lanes_right_of_turn, current_lanes.lanes_in_turn);
if (!lanes_to_constrain || !lanes_fan_in || can_make_all_turns)
return;
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
};
// We do not have a mapping from lanes to lanes. All we have is the lanes in the
// turn and all the lanes at that situation. To perfectly handle lane anticipation
// in cases where lanes in the turn fan in but for example the overall lanes at that
// location fan out, we would have to know the asymmetric mapping of lanes. This is
// currently not possible at the moment. In the following we implement a heuristic
// instead.
const LaneID current_num_lanes_right_of_turn = current.NumLanesToTheRight();
const LaneID current_num_lanes_left_of_turn = current.NumLanesToTheLeft();
// 2/ When to anticipate a left, right turn
if (isLeftTurn(current_inst))
anticipate_for_left_turn();
else if (isRightTurn(current_inst))
anticipate_for_right_turn();
else // keepStraight
{
// Heuristic: we do not have a from-lanes -> to-lanes mapping. What we use
// here instead in addition is the number of all lanes (not only the lanes
// in a turn):
//
// -v-v v-v- straight follows
// | | | |
// <- v v -> keep straight here
// | |
// <-| |->
//
// A route from the top left to the bottom right here goes over a keep
// straight. If we handle all keep straights as right turns (in right-sided
// driving), we wrongly guide the user to the rightmost lanes in the first turn.
// Not only is this wrong but the opposite of what we expect.
//
// The following implements a heuristic to determine a keep straight's
// direction in relation to the next step. In the above example we would get:
//
// coming from right, going to left (in direction of way) -> handle as left turn
// 0/ Tag keep straight with the next turn's direction if available
const auto previous_is_straight =
!isLeftTurn(previous_inst) && !isRightTurn(previous_inst);
if (is_straight_left.count(&current) > 0)
if (previous_is_straight)
{
if (isLeftTurn(current_inst) || is_straight_left.count(&current) > 0)
is_straight_left.insert(&previous);
else if (isRightTurn(current_inst) || is_straight_right.count(&current) > 0)
is_straight_right.insert(&previous);
}
// 1/ How to anticipate left, right:
const auto anticipate_for_left_turn = [&]
{
// Current turn is left turn, already keep left during previous turn.
// This implies constraining the rightmost lanes in previous step.
LaneID new_first_lane_from_the_right =
previous_lanes.first_lane_from_the_right // start from rightmost lane
+ previous_lanes.lanes_in_turn // one past leftmost lane
- current_lanes.lanes_in_turn; // back number of new lanes
// The leftmost target lanes might not be involved in the turn. Figure out
// how many lanes are to the left and not in the turn.
new_first_lane_from_the_right -=
std::min(current_num_lanes_left_of_turn, current_lanes.lanes_in_turn);
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
};
const auto anticipate_for_right_turn = [&]
{
// Current turn is right turn, already keep right during the previous turn.
// This implies constraining the leftmost lanes in the previous turn step.
LaneID new_first_lane_from_the_right = previous_lanes.first_lane_from_the_right;
// The rightmost target lanes might not be involved in the turn. Figure out
// how many lanes are to the right and not in the turn.
new_first_lane_from_the_right +=
std::min(current_num_lanes_right_of_turn, current_lanes.lanes_in_turn);
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
};
// 2/ When to anticipate a left, right turn
if (isLeftTurn(current_inst))
anticipate_for_left_turn();
else if (is_straight_right.count(&current) > 0)
else if (isRightTurn(current_inst))
anticipate_for_right_turn();
else // FIXME: right-sided driving
anticipate_for_right_turn();
}
else // keepStraight
{
// Heuristic: we do not have a from-lanes -> to-lanes mapping. What we use
// here instead in addition is the number of all lanes (not only the lanes
// in a turn):
//
// -v-v v-v- straight follows
// | | | |
// <- v v -> keep straight here
// | |
// <-| |->
//
// A route from the top left to the bottom right here goes over a keep
// straight. If we handle all keep straights as right turns (in right-sided
// driving), we wrongly guide the user to the rightmost lanes in the first turn.
// Not only is this wrong but the opposite of what we expect.
//
// The following implements a heuristic to determine a keep straight's
// direction in relation to the next step. In the above example we would get:
//
// coming from right, going to left (in direction of way) -> handle as left turn
if (previous_inst.type == TurnType::Suppressed &&
current_inst.type == TurnType::Suppressed && previous.mode == current.mode &&
previous_lanes == current_lanes)
{
previous.ElongateBy(current);
current.Invalidate();
}
});
if (is_straight_left.count(&current) > 0)
anticipate_for_left_turn();
else if (is_straight_right.count(&current) > 0)
anticipate_for_right_turn();
else // FIXME: right-sided driving
anticipate_for_right_turn();
}
if (previous_inst.type == TurnType::Suppressed &&
current_inst.type == TurnType::Suppressed && previous.mode == current.mode &&
previous_lanes == current_lanes)
{
previous.ElongateBy(current);
current.Invalidate();
}
});
};
std::for_each(begin(quick_lanes_ranges), end(quick_lanes_ranges), constrain_lanes);
+21 -16
View File
@@ -77,7 +77,8 @@ void processRoundaboutExits(const RouteStepIterator begin, const RouteStepIterat
return;
}
const auto passes_exit_or_leaves_roundabout = [](auto const &step) {
const auto passes_exit_or_leaves_roundabout = [](auto const &step)
{
return staysOnRoundabout(step.maneuver.instruction) ||
leavesRoundabout(step.maneuver.instruction);
};
@@ -142,9 +143,8 @@ void processRoundaboutExits(const RouteStepIterator begin, const RouteStepIterat
// instructions in between
void processRoundaboutGroups(const std::pair<RouteStepIterator, RouteStepIterator> &range)
{
const auto leaves_roundabout = [](auto const &step) {
return leavesRoundabout(step.maneuver.instruction);
};
const auto leaves_roundabout = [](auto const &step)
{ return leavesRoundabout(step.maneuver.instruction); };
auto itr = range.first;
while (itr != range.second)
@@ -174,9 +174,8 @@ void processRoundaboutGroups(const std::pair<RouteStepIterator, RouteStepIterato
std::vector<RouteStep> handleRoundabouts(std::vector<RouteStep> steps)
{
// check if a step has roundabout type
const auto has_roundabout_type = [](auto const &step) {
return hasRoundaboutType(step.maneuver.instruction);
};
const auto has_roundabout_type = [](auto const &step)
{ return hasRoundaboutType(step.maneuver.instruction); };
const auto first_roundabout_type =
std::find_if(steps.begin(), steps.end(), has_roundabout_type);
@@ -193,7 +192,8 @@ std::vector<RouteStep> handleRoundabouts(std::vector<RouteStep> steps)
// this group by paradigm does might contain intermediate roundabout instructions, when they are
// directly connected. Otherwise it will be a sequence containing everything from enter to exit.
// If we already start on the roundabout, the first valid place will be steps.begin().
const auto is_on_roundabout = [&currently_on_roundabout](const auto &step) {
const auto is_on_roundabout = [&currently_on_roundabout](const auto &step)
{
if (currently_on_roundabout)
{
if (leavesRoundabout(step.maneuver.instruction))
@@ -327,10 +327,13 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
}
// and update the leg geometry indices for the removed entry
std::for_each(steps.begin(), steps.end(), [offset](RouteStep &step) {
step.geometry_begin -= offset;
step.geometry_end -= offset;
});
std::for_each(steps.begin(),
steps.end(),
[offset](RouteStep &step)
{
step.geometry_begin -= offset;
step.geometry_end -= offset;
});
auto &first_step = steps.front();
auto bearing = first_bearing;
@@ -645,16 +648,18 @@ void applyOverrides(const datafacade::BaseDataFacade &facade,
auto step_to_update = std::find_if(
current_step_it,
route_iter,
[&leg_geometry, &via_node_coords](const auto &step) {
[&leg_geometry, &via_node_coords](const auto &step)
{
util::Log(logDEBUG) << "Leg geom from " << step.geometry_begin << " to "
<< step.geometry_end << std::endl;
// iterators over geometry of current step
auto begin = leg_geometry.locations.begin() + step.geometry_begin;
auto end = leg_geometry.locations.begin() + step.geometry_end;
auto via_match = std::find_if(begin, end, [&](const auto &location) {
return location == via_node_coords;
});
auto via_match = std::find_if(begin,
end,
[&](const auto &location)
{ return location == via_node_coords; });
if (via_match != end)
{
util::Log(logDEBUG)
+27 -25
View File
@@ -15,19 +15,20 @@ std::vector<RouteStep> suppressShortNameSegments(std::vector<RouteStep> steps)
return steps;
// we remove only name changes that don't offer additional information
const auto name_change_without_lanes = [](const RouteStep &step) {
return hasTurnType(step, TurnType::NewName) && !hasLanes(step);
};
const auto name_change_without_lanes = [](const RouteStep &step)
{ return hasTurnType(step, TurnType::NewName) && !hasLanes(step); };
// check if the next step is not important enough to announce
const auto can_be_extended_to = [](const RouteStep &step) {
const auto can_be_extended_to = [](const RouteStep &step)
{
const auto is_not_arrive = !hasWaypointType(step);
const auto is_silent = !hasTurnType(step) || hasTurnType(step, TurnType::Suppressed);
return is_not_arrive && is_silent;
};
const auto suppress = [](RouteStep &from_step, RouteStep &onto_step) {
const auto suppress = [](RouteStep &from_step, RouteStep &onto_step)
{
from_step.ElongateBy(onto_step);
onto_step.Invalidate();
};
@@ -36,28 +37,29 @@ std::vector<RouteStep> suppressShortNameSegments(std::vector<RouteStep> steps)
// only available for a very short time
const auto reduce_verbosity_if_possible =
[suppress, can_be_extended_to](RouteStepIterator &current_turn_itr,
RouteStepIterator &previous_turn_itr) {
if (haveSameName(*previous_turn_itr, *current_turn_itr))
RouteStepIterator &previous_turn_itr)
{
if (haveSameName(*previous_turn_itr, *current_turn_itr))
suppress(*previous_turn_itr, *current_turn_itr);
else
{
// remember the location of the name change so we can advance the previous turn
const auto location_of_name_change = current_turn_itr;
auto distance = current_turn_itr->distance;
// sum up all distances that can be relevant to the name change
while (can_be_extended_to(*(current_turn_itr + 1)) &&
distance < NAME_SEGMENT_CUTOFF_LENGTH)
{
++current_turn_itr;
distance += current_turn_itr->distance;
}
if (distance < NAME_SEGMENT_CUTOFF_LENGTH)
suppress(*previous_turn_itr, *current_turn_itr);
else
{
// remember the location of the name change so we can advance the previous turn
const auto location_of_name_change = current_turn_itr;
auto distance = current_turn_itr->distance;
// sum up all distances that can be relevant to the name change
while (can_be_extended_to(*(current_turn_itr + 1)) &&
distance < NAME_SEGMENT_CUTOFF_LENGTH)
{
++current_turn_itr;
distance += current_turn_itr->distance;
}
if (distance < NAME_SEGMENT_CUTOFF_LENGTH)
suppress(*previous_turn_itr, *current_turn_itr);
else
previous_turn_itr = location_of_name_change;
}
};
previous_turn_itr = location_of_name_change;
}
};
BOOST_ASSERT(!hasTurnType(steps.back()) && hasWaypointType(steps.back()));
for (auto previous_turn_itr = steps.begin(), current_turn_itr = std::next(previous_turn_itr);