Skip to content

Commit 37774a3

Browse files
Moritz KobitzschPatrick Niklaus
authored andcommitted
fix collapsing into uturns, that aren't u-turns
1 parent 8719821 commit 37774a3

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

features/guidance/collapse-detail.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ Feature: Collapse
174174
| fe | service | |
175175

176176
When I route I should get
177-
| waypoints | route | turns |
178-
| c,e | road,, | depart,turn uturn,arrive |
177+
| waypoints | route | turns |
178+
| c,e | road,,, | depart,turn right,turn right,arrive |

include/engine/guidance/collapsing_utility.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "extractor/guidance/turn_instruction.hpp"
55
#include "engine/guidance/route_step.hpp"
66
#include "util/attributes.hpp"
7+
#include "util/bearing.hpp"
78
#include "util/guidance/name_announcements.hpp"
89

910
#include <boost/range/algorithm_ext/erase.hpp>
@@ -189,6 +190,27 @@ inline std::vector<RouteStep> removeNoTurnInstructions(std::vector<RouteStep> st
189190
return steps;
190191
}
191192

193+
inline double totalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_step)
194+
{
195+
if (entry_step.geometry_begin > exit_step.geometry_begin)
196+
return totalTurnAngle(exit_step, entry_step);
197+
198+
const auto exit_intersection = exit_step.intersections.front();
199+
const auto entry_intersection = entry_step.intersections.front();
200+
if ((exit_intersection.out >= exit_intersection.bearings.size()) ||
201+
(entry_intersection.in >= entry_intersection.bearings.size()))
202+
return entry_intersection.bearings[entry_intersection.out];
203+
204+
const auto exit_step_exit_bearing = exit_intersection.bearings[exit_intersection.out];
205+
const auto entry_step_entry_bearing =
206+
util::bearing::reverse(entry_intersection.bearings[entry_intersection.in]);
207+
208+
const double total_angle =
209+
util::bearing::angleBetween(entry_step_entry_bearing, exit_step_exit_bearing);
210+
211+
return total_angle;
212+
}
213+
192214
} /* namespace guidance */
193215
} /* namespace engine */
194216
} /* namespace osrm */

src/engine/guidance/collapse_scenario_detection.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,12 @@ bool suppressedStraightBetweenTurns(const RouteStepIterator step_entering_inters
306306
hasTurnType(*step_leaving_intersection, TurnType::Continue) ||
307307
hasTurnType(*step_leaving_intersection, TurnType::OnRamp));
308308

309-
return both_short_enough && similar_length && correct_types;
309+
const auto total_angle =
310+
totalTurnAngle(*step_entering_intersection, *step_leaving_intersection);
311+
const auto total_angle_is_not_uturn =
312+
(total_angle > NARROW_TURN_ANGLE) && (total_angle < 360 - NARROW_TURN_ANGLE);
313+
314+
return both_short_enough && similar_length && correct_types && total_angle_is_not_uturn;
310315
}
311316

312317
bool maneuverSucceededByNameChange(const RouteStepIterator step_entering_intersection,

0 commit comments

Comments
 (0)