|
1 |
| -#include "engine/guidance/post_processing.hpp" |
2 | 1 | #include "extractor/guidance/constants.hpp"
|
3 | 2 | #include "extractor/guidance/turn_instruction.hpp"
|
| 3 | +#include "engine/guidance/post_processing.hpp" |
4 | 4 | #include "engine/guidance/toolkit.hpp"
|
5 | 5 |
|
6 | 6 | #include "engine/guidance/assemble_steps.hpp"
|
@@ -528,8 +528,7 @@ void collapseTurnAt(std::vector<RouteStep> &steps,
|
528 | 528 |
|
529 | 529 | // check if the actual turn we wan't to announce is delayed. This situation describes a turn
|
530 | 530 | // 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) { |
533 | 532 | // only possible if both are compatible
|
534 | 533 | if (!compatible(opening_turn, finishing_turn))
|
535 | 534 | return false;
|
@@ -816,13 +815,17 @@ void collapseTurnAt(std::vector<RouteStep> &steps,
|
816 | 815 | // | or | becomes a -> b
|
817 | 816 | // a -> * * -> b
|
818 | 817 | //
|
819 |
| -bool isStaggeredIntersection(const RouteStep &previous, const RouteStep ¤t) |
| 818 | +bool isStaggeredIntersection(const std::vector<RouteStep> &steps, |
| 819 | + const std::size_t ¤t_index, |
| 820 | + const std::size_t &previous_index) |
820 | 821 | {
|
| 822 | + const RouteStep previous = steps[previous_index]; |
| 823 | + const RouteStep current = steps[current_index]; |
| 824 | + |
821 | 825 | // don't touch roundabouts
|
822 | 826 | if (entersRoundabout(previous.maneuver.instruction) ||
|
823 | 827 | entersRoundabout(current.maneuver.instruction))
|
824 | 828 | return false;
|
825 |
| - |
826 | 829 | // Base decision on distance since the zig-zag is a visual clue.
|
827 | 830 | // If adjusted, make sure to check validity of the is_right/is_left classification below
|
828 | 831 | 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 ¤t
|
853 | 856 | // We are only interested in the distance between the first and the second.
|
854 | 857 | const auto is_short = previous.distance < MAX_STAGGERED_DISTANCE;
|
855 | 858 |
|
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 | + } |
857 | 867 |
|
858 | 868 | // previous step maneuver intersections should be length 1 to indicate that
|
859 | 869 | // there are no intersections between the two potentially collapsible turns
|
860 | 870 | const auto no_intermediary_intersections = previous.intersections.size() == 1;
|
861 | 871 |
|
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; |
863 | 874 | }
|
864 | 875 |
|
865 | 876 | } // namespace
|
@@ -1174,7 +1185,7 @@ std::vector<RouteStep> collapseTurns(std::vector<RouteStep> steps)
|
1174 | 1185 | else if (one_back_index > 0 && compatible(current_step, one_back_step) &&
|
1175 | 1186 | ((isCollapsableInstruction(current_step.maneuver.instruction) &&
|
1176 | 1187 | isCollapsableInstruction(one_back_step.maneuver.instruction)) ||
|
1177 |
| - isStaggeredIntersection(one_back_step, current_step))) |
| 1188 | + isStaggeredIntersection(steps, step_index, one_back_index))) |
1178 | 1189 | {
|
1179 | 1190 | const auto two_back_index = getPreviousIndex(one_back_index, steps);
|
1180 | 1191 | BOOST_ASSERT(two_back_index < steps.size());
|
|
0 commit comments