From d660c1609c0903fb6576a89b197be715e5e73531 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Thu, 15 Jun 2017 11:28:04 +0200 Subject: [PATCH] don't collapse u-turns into combined turns --- CHANGELOG.md | 1 + features/guidance/collapse.feature | 4 +-- .../guidance/collapse_scenario_detection.cpp | 26 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b1239f04..8f3374424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Fixed a copy/paste issue assigning wrong directions in similar turns (left over right) - #4074: fixed a bug that would announce entering highway ramps as u-turns - #4122: osrm-routed/libosrm should throw exception when a dataset incompatible with the requested algorithm is loaded + - Avoid collapsing u-turns into combined turn instructions # 5.7.1 - Bugfixes diff --git a/features/guidance/collapse.feature b/features/guidance/collapse.feature index 63ed3a4ac..2f4416e06 100644 --- a/features/guidance/collapse.feature +++ b/features/guidance/collapse.feature @@ -1072,5 +1072,5 @@ Feature: Collapse | bd | service | When I route I should get - | waypoints | bearings | route | turns | locations | - | 1,2 | 90 270 | ab,bd,ab,ab | depart,turn right,end of road right,arrive | _,b,b,_ | + | waypoints | bearings | route | turns | locations | + | 1,2 | 90 270 | ab,bd,bd,ab,ab | depart,turn left,continue uturn,turn right,arrive | _,b,d,b,_ | diff --git a/src/engine/guidance/collapse_scenario_detection.cpp b/src/engine/guidance/collapse_scenario_detection.cpp index 530d353ff..fd6cef595 100644 --- a/src/engine/guidance/collapse_scenario_detection.cpp +++ b/src/engine/guidance/collapse_scenario_detection.cpp @@ -61,6 +61,22 @@ bool isShortAndUndisturbed(const RouteStep &step) return is_short && noIntermediaryIntersections(step); } +// On dual carriageways, we might want to use u-turns in combination with new-name instructions. +// Otherwise a u-turn should never be part of a collapsing instructions. +bool noBadUTurnCombination(const RouteStepIterator first, const RouteStepIterator second) +{ + auto has_uturn = hasModifier(*first, DirectionModifier::UTurn) || + hasModifier(*second, DirectionModifier::UTurn); + + auto const from_name_change_into_uturn = + hasTurnType(*first, TurnType::NewName) && hasModifier(*second, DirectionModifier::UTurn); + + auto const uturn_into_name_change = + hasTurnType(*second, TurnType::NewName) && hasModifier(*first, DirectionModifier::UTurn); + + return !has_uturn || from_name_change_into_uturn || uturn_into_name_change; +} + } // namespace bool basicCollapsePreconditions(const RouteStepIterator first, const RouteStepIterator second) @@ -70,7 +86,10 @@ bool basicCollapsePreconditions(const RouteStepIterator first, const RouteStepIt const auto waypoint_type = hasWaypointType(*first) || hasWaypointType(*second); - return !has_roundabout_type && !waypoint_type && haveSameMode(*first, *second); + const auto contains_bad_uturn = !noBadUTurnCombination(first, second); + + return !has_roundabout_type && !waypoint_type && haveSameMode(*first, *second) && + !contains_bad_uturn; } bool basicCollapsePreconditions(const RouteStepIterator first, @@ -81,8 +100,11 @@ bool basicCollapsePreconditions(const RouteStepIterator first, hasRoundaboutType(second->maneuver.instruction) || hasRoundaboutType(third->maneuver.instruction); + const auto contains_bad_uturn = + !noBadUTurnCombination(first, second) && !noBadUTurnCombination(second, third); + // require modes to match up - return !has_roundabout_type && haveSameMode(*first, *second, *third); + return !has_roundabout_type && haveSameMode(*first, *second, *third) && !contains_bad_uturn; } bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection,