handle merge on collapsed instructions

This commit is contained in:
Moritz Kobitzsch 2016-06-06 11:01:55 +02:00
parent 1dfdb38d4a
commit 312e86eb58
5 changed files with 57 additions and 16 deletions

View File

@ -485,3 +485,29 @@ Feature: Collapse
| waypoints | route | turns |
| a,d | road,road,road | depart,continue right,arrive |
Scenario: Segregated Intersection into Slight Turn
Given the node map
| h | | | | | | |
| a | | | | | | |
| | | | | | | |
| | | g | | | | |
| | | b | f | | | |
| | | | c | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | e |
| | | | | | | d |
| | | j | i | | | |
And the ways
| nodes | highway | name | oneway |
| abcd | primary | road | yes |
| efgh | primary | road | yes |
| icf | secondary | in | yes |
| gbj | secondary | out | yes |
When I route I should get
| waypoints | route | turns |
| i,h | in,road,road | depart,turn slight left,arrive |
| a,d | road,road | depart,arrive |
| a,j | road,out,out | depart,turn slight right,arrive |

View File

@ -805,4 +805,3 @@ Feature: Simple Turns
| a,d | abc,bd,bd | depart,turn sharp right,arrive |
| a,e | abc,be,be | depart,turn right,arrive |
| a,f | abc,bf,bf | depart,turn slight right,arrive |

View File

@ -280,20 +280,6 @@ inline double getTurnConfidence(const double angle, TurnInstruction instruction)
return 1.0 - (difference / max_deviation) * (difference / max_deviation);
}
// swaps left <-> right modifier types
inline DirectionModifier::Enum mirrorDirectionModifier(const DirectionModifier::Enum modifier)
{
const constexpr DirectionModifier::Enum results[] = {DirectionModifier::UTurn,
DirectionModifier::SharpLeft,
DirectionModifier::Left,
DirectionModifier::SlightLeft,
DirectionModifier::Straight,
DirectionModifier::SlightRight,
DirectionModifier::Right,
DirectionModifier::SharpRight};
return results[modifier];
}
inline bool canBeSuppressed(const TurnType::Enum type)
{
if (type == TurnType::Turn)

View File

@ -49,6 +49,22 @@ inline extractor::guidance::DirectionModifier::Enum getTurnDirection(const doubl
return extractor::guidance::DirectionModifier::UTurn;
}
// swaps left <-> right modifier types
inline extractor::guidance::DirectionModifier::Enum
mirrorDirectionModifier(const extractor::guidance::DirectionModifier::Enum modifier)
{
const constexpr extractor::guidance::DirectionModifier::Enum results[] = {
extractor::guidance::DirectionModifier::UTurn,
extractor::guidance::DirectionModifier::SharpLeft,
extractor::guidance::DirectionModifier::Left,
extractor::guidance::DirectionModifier::SlightLeft,
extractor::guidance::DirectionModifier::Straight,
extractor::guidance::DirectionModifier::SlightRight,
extractor::guidance::DirectionModifier::Right,
extractor::guidance::DirectionModifier::SharpRight};
return results[modifier];
}
} // namespace guidance
} // namespace util
} // namespace osrm

View File

@ -40,7 +40,8 @@ bool isCollapsableInstruction(const TurnInstruction instruction)
(instruction.type == TurnType::Suppressed &&
instruction.direction_modifier == DirectionModifier::Straight) ||
(instruction.type == TurnType::Turn &&
instruction.direction_modifier == DirectionModifier::Straight);
instruction.direction_modifier == DirectionModifier::Straight) ||
(instruction.type == TurnType::Merge);
}
// A check whether two instructions can be treated as one. This is only the case for very short
@ -395,6 +396,13 @@ void collapseTurnAt(std::vector<RouteStep> &steps,
if (TurnType::Continue == current_step.maneuver.instruction.type ||
TurnType::Suppressed == current_step.maneuver.instruction.type)
steps[step_index].maneuver.instruction.type = TurnType::Turn;
else if (TurnType::Merge == current_step.maneuver.instruction.type)
{
steps[step_index].maneuver.instruction.direction_modifier =
util::guidance::mirrorDirectionModifier(
steps[step_index].maneuver.instruction.direction_modifier);
steps[step_index].maneuver.instruction.type = TurnType::Turn;
}
else if (TurnType::NewName == current_step.maneuver.instruction.type &&
current_step.maneuver.instruction.direction_modifier !=
DirectionModifier::Straight &&
@ -425,6 +433,12 @@ void collapseTurnAt(std::vector<RouteStep> &steps,
{
steps[one_back_index].maneuver.instruction.type = TurnType::Continue;
}
else if (TurnType::Merge == one_back_step.maneuver.instruction.type)
{
steps[one_back_index].maneuver.instruction.direction_modifier =
util::guidance::mirrorDirectionModifier(
steps[one_back_index].maneuver.instruction.direction_modifier);
}
steps[one_back_index].name = current_step.name;
steps[one_back_index].name_id = current_step.name_id;
invalidateStep(steps[step_index]);