Skip to content

Commit 37824e2

Browse files
committed
don't staggered intersections on intermediary mode changes
1 parent ce5bcc7 commit 37824e2

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Diff for: src/engine/guidance/post_processing.cpp

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "engine/guidance/post_processing.hpp"
21
#include "extractor/guidance/constants.hpp"
32
#include "extractor/guidance/turn_instruction.hpp"
3+
#include "engine/guidance/post_processing.hpp"
44
#include "engine/guidance/toolkit.hpp"
55

66
#include "engine/guidance/assemble_steps.hpp"
@@ -528,8 +528,7 @@ void collapseTurnAt(std::vector<RouteStep> &steps,
528528

529529
// check if the actual turn we wan't to announce is delayed. This situation describes a turn
530530
// that is expressed by two turns,
531-
const auto isDelayedTurn = [](const RouteStep &opening_turn,
532-
const RouteStep &finishing_turn) {
531+
const auto isDelayedTurn = [](const RouteStep &opening_turn, const RouteStep &finishing_turn) {
533532
// only possible if both are compatible
534533
if (!compatible(opening_turn, finishing_turn))
535534
return false;
@@ -816,13 +815,17 @@ void collapseTurnAt(std::vector<RouteStep> &steps,
816815
// | or | becomes a -> b
817816
// a -> * * -> b
818817
//
819-
bool isStaggeredIntersection(const RouteStep &previous, const RouteStep &current)
818+
bool isStaggeredIntersection(const std::vector<RouteStep> &steps,
819+
const std::size_t &current_index,
820+
const std::size_t &previous_index)
820821
{
822+
const RouteStep previous = steps[previous_index];
823+
const RouteStep current = steps[current_index];
824+
821825
// don't touch roundabouts
822826
if (entersRoundabout(previous.maneuver.instruction) ||
823827
entersRoundabout(current.maneuver.instruction))
824828
return false;
825-
826829
// Base decision on distance since the zig-zag is a visual clue.
827830
// If adjusted, make sure to check validity of the is_right/is_left classification below
828831
const constexpr auto MAX_STAGGERED_DISTANCE = 3; // debatable, but keep short to be on safe side
@@ -853,13 +856,21 @@ bool isStaggeredIntersection(const RouteStep &previous, const RouteStep &current
853856
// We are only interested in the distance between the first and the second.
854857
const auto is_short = previous.distance < MAX_STAGGERED_DISTANCE;
855858

856-
const auto no_mode_change = previous.mode == current.mode;
859+
auto intermediary_mode_change = false;
860+
if (current_index > 1)
861+
{
862+
const auto &two_back_index = getPreviousIndex(previous_index, steps);
863+
const auto two_back_step = steps[two_back_index];
864+
intermediary_mode_change =
865+
two_back_step.mode == current.mode && previous.mode != current.mode;
866+
}
857867

858868
// previous step maneuver intersections should be length 1 to indicate that
859869
// there are no intersections between the two potentially collapsible turns
860870
const auto no_intermediary_intersections = previous.intersections.size() == 1;
861871

862-
return is_short && (left_right || right_left) && no_mode_change && no_intermediary_intersections;
872+
return is_short && (left_right || right_left) && !intermediary_mode_change &&
873+
no_intermediary_intersections;
863874
}
864875

865876
} // namespace
@@ -1174,7 +1185,7 @@ std::vector<RouteStep> collapseTurns(std::vector<RouteStep> steps)
11741185
else if (one_back_index > 0 && compatible(current_step, one_back_step) &&
11751186
((isCollapsableInstruction(current_step.maneuver.instruction) &&
11761187
isCollapsableInstruction(one_back_step.maneuver.instruction)) ||
1177-
isStaggeredIntersection(one_back_step, current_step)))
1188+
isStaggeredIntersection(steps, step_index, one_back_index)))
11781189
{
11791190
const auto two_back_index = getPreviousIndex(one_back_index, steps);
11801191
BOOST_ASSERT(two_back_index < steps.size());

0 commit comments

Comments
 (0)