Guards against no lanes for lanes left and right of turn, resolves #3518

This commit is contained in:
Daniel J. Hofmann 2017-01-04 17:09:44 +01:00 committed by Moritz Kobitzsch
parent f6fef5c166
commit 5100f2cc7b
3 changed files with 39 additions and 6 deletions

View File

@ -145,6 +145,16 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
path_point.lane_data.second != INVALID_LANE_DESCRIPTIONID path_point.lane_data.second != INVALID_LANE_DESCRIPTIONID
? facade.GetTurnDescription(path_point.lane_data.second) ? facade.GetTurnDescription(path_point.lane_data.second)
: extractor::guidance::TurnLaneDescription(); : 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(), std::copy(bearing_data.begin(),
bearing_data.end(), bearing_data.end(),
std::back_inserter(intersection.bearings)); std::back_inserter(intersection.bearings));

View File

@ -90,12 +90,19 @@ struct RouteStep
// copy all strings from origin into the step, apart from rotary names // copy all strings from origin into the step, apart from rotary names
RouteStep &AdaptStepSignage(const RouteStep &origin); 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; LaneID NumLanesToTheLeft() const;
auto LanesToTheLeft() const; auto LanesToTheLeft() const;
auto LanesToTheRight() const; auto LanesToTheRight() const;
}; };
@ -172,16 +179,32 @@ inline RouteStep &RouteStep::AdaptStepSignage(const RouteStep &origin)
return *this; 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 inline LaneID RouteStep::NumLanesToTheRight() const
{ {
if (!HasLanesAtTurn())
return 0;
return intersections.front().lanes.first_lane_from_the_right; return intersections.front().lanes.first_lane_from_the_right;
} }
inline LaneID RouteStep::NumLanesToTheLeft() const inline LaneID RouteStep::NumLanesToTheLeft() const
{ {
LaneID const total = intersections.front().lane_description.size(); if (!HasLanesAtTurn())
return total - (intersections.front().lanes.lanes_in_turn + return 0;
intersections.front().lanes.first_lane_from_the_right);
return NumLanesInTotal() - (NumLanesInTurn() + NumLanesToTheRight());
} }
inline auto RouteStep::LanesToTheLeft() const inline auto RouteStep::LanesToTheLeft() const

View File

@ -69,7 +69,7 @@ class LaneTuple
bool operator!=(const LaneTuple other) const; bool operator!=(const LaneTuple other) const;
LaneID lanes_in_turn; 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) friend std::size_t hash_value(const LaneTuple &tup)
{ {