From 37774a331a7b4a7f839b06ed4d281eb192bf90cf Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Fri, 13 Oct 2017 17:06:22 +0200 Subject: [PATCH] fix collapsing into uturns, that aren't u-turns --- features/guidance/collapse-detail.feature | 4 ++-- .../engine/guidance/collapsing_utility.hpp | 22 +++++++++++++++++++ .../guidance/collapse_scenario_detection.cpp | 7 +++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/features/guidance/collapse-detail.feature b/features/guidance/collapse-detail.feature index 60ecbba38..bd20da416 100644 --- a/features/guidance/collapse-detail.feature +++ b/features/guidance/collapse-detail.feature @@ -174,5 +174,5 @@ Feature: Collapse | fe | service | | When I route I should get - | waypoints | route | turns | - | c,e | road,, | depart,turn uturn,arrive | + | waypoints | route | turns | + | c,e | road,,, | depart,turn right,turn right,arrive | diff --git a/include/engine/guidance/collapsing_utility.hpp b/include/engine/guidance/collapsing_utility.hpp index e84b77ac2..6cd5af6da 100644 --- a/include/engine/guidance/collapsing_utility.hpp +++ b/include/engine/guidance/collapsing_utility.hpp @@ -4,6 +4,7 @@ #include "extractor/guidance/turn_instruction.hpp" #include "engine/guidance/route_step.hpp" #include "util/attributes.hpp" +#include "util/bearing.hpp" #include "util/guidance/name_announcements.hpp" #include @@ -189,6 +190,27 @@ inline std::vector removeNoTurnInstructions(std::vector st return steps; } +inline double totalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_step) +{ + if (entry_step.geometry_begin > exit_step.geometry_begin) + return totalTurnAngle(exit_step, entry_step); + + const auto exit_intersection = exit_step.intersections.front(); + const auto entry_intersection = entry_step.intersections.front(); + if ((exit_intersection.out >= exit_intersection.bearings.size()) || + (entry_intersection.in >= entry_intersection.bearings.size())) + return entry_intersection.bearings[entry_intersection.out]; + + const auto exit_step_exit_bearing = exit_intersection.bearings[exit_intersection.out]; + const auto entry_step_entry_bearing = + util::bearing::reverse(entry_intersection.bearings[entry_intersection.in]); + + const double total_angle = + util::bearing::angleBetween(entry_step_entry_bearing, exit_step_exit_bearing); + + return total_angle; +} + } /* namespace guidance */ } /* namespace engine */ } /* namespace osrm */ diff --git a/src/engine/guidance/collapse_scenario_detection.cpp b/src/engine/guidance/collapse_scenario_detection.cpp index ddcb51fb5..d8ab058dc 100644 --- a/src/engine/guidance/collapse_scenario_detection.cpp +++ b/src/engine/guidance/collapse_scenario_detection.cpp @@ -306,7 +306,12 @@ bool suppressedStraightBetweenTurns(const RouteStepIterator step_entering_inters hasTurnType(*step_leaving_intersection, TurnType::Continue) || hasTurnType(*step_leaving_intersection, TurnType::OnRamp)); - return both_short_enough && similar_length && correct_types; + const auto total_angle = + totalTurnAngle(*step_entering_intersection, *step_leaving_intersection); + const auto total_angle_is_not_uturn = + (total_angle > NARROW_TURN_ANGLE) && (total_angle < 360 - NARROW_TURN_ANGLE); + + return both_short_enough && similar_length && correct_types && total_angle_is_not_uturn; } bool maneuverSucceededByNameChange(const RouteStepIterator step_entering_intersection,