Skip to content

Commit

Permalink
fix(utils): fix monotonic bound create logic
Browse files Browse the repository at this point in the history
Signed-off-by: satoshi-ota <[email protected]>
  • Loading branch information
satoshi-ota committed Nov 15, 2023
1 parent 2a1ad67 commit 253f84b
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions planning/behavior_path_planner/src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1933,22 +1933,33 @@ void makeBoundLongitudinallyMonotonic(
return ret;
};

const auto is_monotonic =
[&](const auto & p1, const auto & p2, const auto & p3, const auto is_points_left) {
const auto p1_to_p2 = calcAzimuthAngle(p1, p2);
const auto p2_to_p3 = calcAzimuthAngle(p2, p3);
const auto is_non_monotonic = [&](

Check warning on line 1936 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L1936

Added line #L1936 was not covered by tests
const auto & base_pose, const auto & point,
const auto is_points_left, const auto is_reverse) {
const auto p_transformed = tier4_autoware_utils::inverseTransformPoint(point, base_pose);

Check warning on line 1939 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L1939

Added line #L1939 was not covered by tests
if (p_transformed.x < 0.0 && p_transformed.y > 0.0) {
return is_points_left && !is_reverse;

Check warning on line 1941 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L1941

Added line #L1941 was not covered by tests
}

const auto theta = normalizeRadian(p1_to_p2 - p2_to_p3);
if (p_transformed.x < 0.0 && p_transformed.y < 0.0) {
return !is_points_left && !is_reverse;

Check warning on line 1945 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L1945

Added line #L1945 was not covered by tests
}

return (is_points_left && 0 < theta) || (!is_points_left && theta < 0);
};
if (p_transformed.x > 0.0 && p_transformed.y > 0.0) {
return is_points_left && is_reverse;

Check warning on line 1949 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L1949

Added line #L1949 was not covered by tests
}

if (p_transformed.x > 0.0 && p_transformed.y < 0.0) {
return !is_points_left && is_reverse;

Check warning on line 1953 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/utils.cpp#L1953

Added line #L1953 was not covered by tests
}

return false;
};

// define a function to remove non monotonic point on bound
const auto remove_non_monotonic_point = [&](const auto & bound_with_pose, const bool is_reverse) {
std::vector<Pose> monotonic_bound;

const bool is_points_left = is_reverse ? !is_bound_left : is_bound_left;

size_t bound_idx = 0;
while (true) {
monotonic_bound.push_back(bound_with_pose.at(bound_idx));
Expand All @@ -1961,21 +1972,20 @@ void makeBoundLongitudinallyMonotonic(
// opposite.
const double lat_offset = is_bound_left ? 100.0 : -100.0;

const auto p_bound_1 = getPoint(bound_with_pose.at(bound_idx));
const auto p_bound_2 = getPoint(bound_with_pose.at(bound_idx + 1));
const auto p_bound_1 = getPose(bound_with_pose.at(bound_idx));
const auto p_bound_2 = getPose(bound_with_pose.at(bound_idx + 1));

const auto p_bound_offset =
calcOffsetPose(getPose(bound_with_pose.at(bound_idx)), 0.0, lat_offset, 0.0);
const auto p_bound_offset = calcOffsetPose(p_bound_1, 0.0, lat_offset, 0.0);

if (!is_monotonic(p_bound_1, p_bound_2, p_bound_offset.position, is_points_left)) {
if (!is_non_monotonic(p_bound_1, p_bound_2.position, is_bound_left, is_reverse)) {
bound_idx++;
continue;
}

// skip non monotonic points
for (size_t i = bound_idx + 1; i < bound_with_pose.size() - 1; ++i) {
const auto intersect_point = intersect(
p_bound_1, p_bound_offset.position, bound_with_pose.at(i).position,
p_bound_1.position, p_bound_offset.position, bound_with_pose.at(i).position,

Check warning on line 1988 in planning/behavior_path_planner/src/utils/utils.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

makeBoundLongitudinallyMonotonic increases in cyclomatic complexity from 44 to 52, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
bound_with_pose.at(i + 1).position);

if (intersect_point) {
Expand Down

0 comments on commit 253f84b

Please sign in to comment.