Skip to content

Commit

Permalink
fix(avoidance): fix invalid optional access (autowarefoundation#5804)
Browse files Browse the repository at this point in the history
Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
  • Loading branch information
satoshi-ota authored and karishma1911 committed May 28, 2024
1 parent 29458b3 commit c227db0
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ AvoidLineArray ShiftLineGenerator::addReturnShiftLine(
AvoidLineArray ret = shift_lines;

constexpr double ep = 1.0e-3;
constexpr double RETURN_SHIFT_THRESHOLD = 0.1;
const bool has_candidate_point = !ret.empty();
const bool has_registered_point = last_.has_value();

Expand All @@ -977,14 +978,15 @@ AvoidLineArray ShiftLineGenerator::addReturnShiftLine(
return ret;
}

// If the return-to-center shift points are already registered, do nothing.
if (!has_registered_point && std::fabs(base_offset_) < ep) {
return ret;
}

constexpr double RETURN_SHIFT_THRESHOLD = 0.1;
if (std::abs(last_.value().end_shift_length) < RETURN_SHIFT_THRESHOLD) {
return ret;
if (last_.has_value()) {
if (std::abs(last_.value().end_shift_length) < RETURN_SHIFT_THRESHOLD) {
return ret;
}
} else {
// If the return-to-center shift points are already registered, do nothing.
if (std::abs(base_offset_) < ep) {
return ret;
}
}

// From here, the return-to-center is not registered. But perhaps the candidate is
Expand Down

0 comments on commit c227db0

Please sign in to comment.