Skip to content

Commit

Permalink
fix(traffic_light_utils): prevent accessing nullopt (autowarefoundati…
Browse files Browse the repository at this point in the history
…on#9163) (#1621)

Signed-off-by: satoshi-ota <[email protected]>
Co-authored-by: Satoshi OTA <[email protected]>
  • Loading branch information
shmpwk and satoshi-ota authored Nov 5, 2024
1 parent 2cd8869 commit 35fd9a0
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ double getDistanceToNextTrafficLight(
lanelet::utils::to2D(lanelet_point).basicPoint());

for (const auto & element : current_lanelet.regulatoryElementsAs<lanelet::TrafficLight>()) {
lanelet::ConstLineString3d lanelet_stop_lines = element->stopLine().value();
const auto lanelet_stop_lines = element->stopLine();

if (!lanelet_stop_lines.has_value()) continue;

const auto to_stop_line = lanelet::geometry::toArcCoordinates(
lanelet::utils::to2D(current_lanelet.centerline()),
lanelet::utils::to2D(lanelet_stop_lines).front().basicPoint());
lanelet::utils::to2D(lanelet_stop_lines.value()).front().basicPoint());

const auto distance_object_to_stop_line = to_stop_line.length - to_object.length;

Expand All @@ -61,11 +63,13 @@ double getDistanceToNextTrafficLight(
}

for (const auto & element : llt.regulatoryElementsAs<lanelet::TrafficLight>()) {
lanelet::ConstLineString3d lanelet_stop_lines = element->stopLine().value();
const auto lanelet_stop_lines = element->stopLine();

if (!lanelet_stop_lines.has_value()) continue;

const auto to_stop_line = lanelet::geometry::toArcCoordinates(
lanelet::utils::to2D(llt.centerline()),
lanelet::utils::to2D(lanelet_stop_lines).front().basicPoint());
lanelet::utils::to2D(lanelet_stop_lines.value()).front().basicPoint());

return distance + to_stop_line.length - to_object.length;
}
Expand Down

0 comments on commit 35fd9a0

Please sign in to comment.