Skip to content

Commit

Permalink
new names at normal intersections, adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Kobitzsch committed Jan 2, 2017
1 parent f39f3b2 commit 3d0524b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 25 deletions.
18 changes: 9 additions & 9 deletions features/guidance/turn.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ Feature: Simple Turns
| a,c | in,through,through | depart,turn left,arrive |

# http://www.openstreetmap.org/#map=19/52.51556/13.41832
Scenario: No Slight Right over Jannowitzbruecke
Scenario: No Slight Right at Stralauer Strasse
Given the node map
"""
l m
Expand Down Expand Up @@ -1318,17 +1318,17 @@ Feature: Simple Turns
| waypoints | turns | route |
| a,e | depart,new name straight,arrive | Stralauer Str,Holzmarktstr,Holzmarktstr |

Scenario: No Slight Right over Jannowitzbruecke -- less extreme
Scenario: No Slight Right at Stralauer Strasse -- less extreme
Given the node map
"""
l m
| |
f_ | |
' 'g h_
' 'g---h_
| | '\_
| | i
a_ | |
'_ b c_
'_ b___c_
| | \_
| | e
j k
Expand All @@ -1347,17 +1347,17 @@ Feature: Simple Turns
| waypoints | turns | route |
| a,e | depart,new name straight,arrive | Stralauer Str,Holzmarktstr,Holzmarktstr |

Scenario: No Slight Right over Jannowitzbruecke
Scenario: No Slight Right at Stralauer Strasse
Given the node map
"""
l m
| |
| |
_ _ g h_
_ _ g---h_
f' | | '_
| | i
| |
_ _b c__
_ _b---c__
a' | | 'd
| |
j k
Expand All @@ -1373,8 +1373,8 @@ Feature: Simple Turns
| kchm | Alexanderstr | primary | yes |

When I route I should get
| waypoints | turns | route |
| a,d | depart,arrive | Stralauer Str,Holzmarktstr |
| waypoints | turns | route |
| a,d | depart,new name straight,arrive | Stralauer Str,Holzmarktstr,Holzmarktstr |

#http://www.openstreetmap.org/#map=19/49.48761/8.47618
@todo @3365
Expand Down
17 changes: 14 additions & 3 deletions include/engine/guidance/collapse_scenario_detection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ namespace guidance

// 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 RouteStepIterator step_prior_to_intersection,
const RouteStepIterator step_entering_intersection,
const RouteStepIterator step_leaving_intersection);

// Two two turns following close after another, we can announce them as a U-Turn if both end up
// involving the same (segregated) road.
//
// 
// b < - y
// | will be represented by at x, turn around instead of turn left at x, turn left at y
// a - > x
Expand All @@ -38,6 +37,18 @@ bool isNameOszillation(const RouteStepIterator step_prior_to_intersection,
const RouteStepIterator step_entering_intersection,
const RouteStepIterator step_leaving_intersection);

// Sometimes, segments names don't match the perceived turns. We try to detect these additional name
// changes and issue a combined turn.
// 
// | e |
// a - b - c
// d
// 
// can have `a-b` as one name, `b-c-d` as a second. At `b` we would issue a new name, even though
// the road turns right after. The offset would only be there due to the broad road at `e`
bool maneuverPreceededByNameChange(const RouteStepIterator step_entering_intersection,
const RouteStepIterator step_leaving_intersection);

} /* namespace guidance */
} /* namespace engine */
} /* namespace osrm */
Expand Down
3 changes: 3 additions & 0 deletions include/engine/guidance/collapse_turns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void CombineRouteSteps(RouteStep &step_at_turn_location,
step_after_turn_location.Invalidate();
}

// alias for suppressing a step, using CombineRouteStep with NoModificationStrategy only
void SuppressStep(RouteStep &step_at_turn_location, RouteStep &step_after_turn_location);

} /* namespace guidance */
} /* namespace osrm */
} /* namespace osrm */
Expand Down
3 changes: 2 additions & 1 deletion include/engine/guidance/collapsing_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace guidance
using RouteSteps = std::vector<RouteStep>;
using RouteStepIterator = typename RouteSteps::iterator;
const constexpr std::size_t MIN_END_OF_ROAD_INTERSECTIONS = std::size_t{2};
const constexpr double MAX_COLLAPSE_DISTANCE = 30;
const constexpr double MAX_COLLAPSE_DISTANCE = 30.0;
const constexpr double NAME_SEGMENT_CUTOFF_LENGTH = 100.0;

// check if a step is completely without turn type
inline bool hasTurnType(const RouteStep &step)
Expand Down
14 changes: 13 additions & 1 deletion src/engine/guidance/collapse_scenario_detection.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "engine/guidance/collapse_scenario_detection.hpp"
#include "util/bearing.hpp"

#include <numeric>

#include <boost/assert.hpp>

namespace osrm
Expand Down Expand Up @@ -123,13 +125,23 @@ bool isNameOszillation(const RouteStepIterator step_prior_to_intersection,
{
const auto are_name_changes = hasTurnType(*step_entering_intersection, TurnType::NewName) &&
hasTurnType(*step_leaving_intersection, TurnType::NewName);
if( !are_name_changes )
if (!are_name_changes)
return false;

const auto names_match = haveSameName(*step_prior_to_intersection, *step_leaving_intersection);
return names_match;
}

bool maneuverPreceededByNameChange(const RouteStepIterator step_entering_intersection,
const RouteStepIterator step_leaving_intersection)
{
const auto is_short = step_entering_intersection->distance <= MAX_COLLAPSE_DISTANCE;
const auto is_name_change = hasTurnType(*step_entering_intersection, TurnType::NewName);

const auto leaving_is_only_turn = numberOfAllowedTurns(*step_leaving_intersection) == 1;
return is_short && is_name_change && leaving_is_only_turn;
}

} /* namespace guidance */
} /* namespace engine */
} /* namespace osrm */
32 changes: 21 additions & 11 deletions src/engine/guidance/collapse_turns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ double findTotalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_ste
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
Expand All @@ -74,9 +75,11 @@ double findTotalTurnAngle(const RouteStep &entry_step, const RouteStep &exit_ste
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
Expand Down Expand Up @@ -188,6 +191,15 @@ void TransferLanesStrategy::operator()(RouteStep &step_at_turn_location,
transfer_from_step.intersections.front().lane_description;
}

void SuppressStep(RouteStep &step_at_turn_location, RouteStep &step_after_turn_location)
{
return CombineRouteSteps(step_at_turn_location,
step_after_turn_location,
NoModificationStrategy(),
NoModificationStrategy(),
NoModificationStrategy());
}

// OTHER IMPLEMENTATIONS
OSRM_ATTR_WARN_UNUSED
RouteSteps CollapseTurnInstructions(RouteSteps steps)
Expand Down Expand Up @@ -265,17 +277,15 @@ RouteSteps CollapseTurnInstructions(RouteSteps steps)
else if (isNameOszillation(previous_step, current_step, next_step))
{
// first deactivate the second name switch
CombineRouteSteps(*current_step,
*next_step,
NoModificationStrategy(),
NoModificationStrategy(),
NoModificationStrategy());
SuppressStep(*current_step, *next_step);
// and then the first (to ensure both iterators to be valid)
CombineRouteSteps(*previous_step,
*current_step,
NoModificationStrategy(),
NoModificationStrategy(),
NoModificationStrategy());
SuppressStep(*previous_step, *current_step);
}
else if (maneuverPreceededByNameChange(previous_step, current_step))
{
AdjustToCombinedTurnAngleStrategy()(*current_step, *previous_step);
// suppress previous step
SuppressStep(*findPreviousTurn(previous_step), *previous_step);
}
}
return steps;
Expand Down

0 comments on commit 3d0524b

Please sign in to comment.