diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index c555fac2f..a6bed757c 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -145,6 +145,16 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa path_point.lane_data.second != INVALID_LANE_DESCRIPTIONID ? facade.GetTurnDescription(path_point.lane_data.second) : extractor::guidance::TurnLaneDescription(); + + // Lanes in turn are bound by total number of lanes at the location + BOOST_ASSERT(intersection.lanes.lanes_in_turn <= + intersection.lane_description.size()); + // No lanes at location and no turn lane or lanes at location and lanes in turn + BOOST_ASSERT((intersection.lane_description.empty() && + intersection.lanes.lanes_in_turn == 0) || + (!intersection.lane_description.empty() && + intersection.lanes.lanes_in_turn != 0)); + std::copy(bearing_data.begin(), bearing_data.end(), std::back_inserter(intersection.bearings)); diff --git a/include/engine/guidance/route_step.hpp b/include/engine/guidance/route_step.hpp index 29fb3a7b1..e7801f475 100644 --- a/include/engine/guidance/route_step.hpp +++ b/include/engine/guidance/route_step.hpp @@ -90,12 +90,19 @@ struct RouteStep // copy all strings from origin into the step, apart from rotary names RouteStep &AdaptStepSignage(const RouteStep &origin); - LaneID NumLanesToTheRight() const; + // Lane utilities for the step's turn. + // A step may have lanes left or right of the turn: think left turn with lanes going straight. + // Note: Lanes for intersections along the way are available via intersections[n].lanes. + bool HasLanesAtTurn() const; + + LaneID NumLanesInTurn() const; + LaneID NumLanesInTotal() const; + + LaneID NumLanesToTheRight() const; LaneID NumLanesToTheLeft() const; auto LanesToTheLeft() const; - auto LanesToTheRight() const; }; @@ -172,16 +179,32 @@ inline RouteStep &RouteStep::AdaptStepSignage(const RouteStep &origin) return *this; } +inline bool RouteStep::HasLanesAtTurn() const { return NumLanesInTotal() != 0; } + +inline LaneID RouteStep::NumLanesInTurn() const +{ + return intersections.front().lanes.lanes_in_turn; +} + +inline LaneID RouteStep::NumLanesInTotal() const +{ + return intersections.front().lane_description.size(); +} + inline LaneID RouteStep::NumLanesToTheRight() const { + if (!HasLanesAtTurn()) + return 0; + return intersections.front().lanes.first_lane_from_the_right; } inline LaneID RouteStep::NumLanesToTheLeft() const { - LaneID const total = intersections.front().lane_description.size(); - return total - (intersections.front().lanes.lanes_in_turn + - intersections.front().lanes.first_lane_from_the_right); + if (!HasLanesAtTurn()) + return 0; + + return NumLanesInTotal() - (NumLanesInTurn() + NumLanesToTheRight()); } inline auto RouteStep::LanesToTheLeft() const diff --git a/include/util/guidance/turn_lanes.hpp b/include/util/guidance/turn_lanes.hpp index 7dee62f51..e217f428e 100644 --- a/include/util/guidance/turn_lanes.hpp +++ b/include/util/guidance/turn_lanes.hpp @@ -69,7 +69,7 @@ class LaneTuple bool operator!=(const LaneTuple other) const; LaneID lanes_in_turn; - LaneID first_lane_from_the_right; + LaneID first_lane_from_the_right; // is INVALID_LANEID when no lanes present friend std::size_t hash_value(const LaneTuple &tup) {