Skip to content

Commit

Permalink
refactor(static_drivable_area_expansion): use lambda
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 committed Jan 24, 2024
1 parent b89a94d commit feacf2c
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ std::vector<geometry_msgs::msg::Point> calcBound(
const bool enable_expanding_hatched_road_markings, const bool enable_expanding_intersection_areas,
const bool enable_expanding_freespace_areas, const bool is_left, const bool is_driving_forward)
{
using motion_utils::removeOverlapPoints;

const auto & route_handler = planner_data->route_handler;

// a function to convert drivable lanes to points without duplicated points
Expand Down Expand Up @@ -1583,14 +1585,17 @@ std::vector<geometry_msgs::msg::Point> calcBound(
planner_data, is_left);
}();

// Step2. if there is no drivable area defined by polygon, return original drivable bound.
if (!enable_expanding_hatched_road_markings && !enable_expanding_intersection_areas) {
const auto bound = motion_utils::removeOverlapPoints(to_ros_point(bound_points));
return skip_post_process
const auto post_process = [&](const auto & bound, const auto skip) {
return skip
? bound
: postProcess(
bound, path, planner_data, drivable_lanes, enable_expanding_hatched_road_markings,
enable_expanding_intersection_areas, is_left, is_driving_forward);
};

// Step2. if there is no drivable area defined by polygon, return original drivable bound.
if (!enable_expanding_hatched_road_markings && !enable_expanding_intersection_areas) {
return post_process(removeOverlapPoints(to_ros_point(bound_points)), skip_post_process);
}

// Step3.if there are hatched road markings, expand drivable bound with the polygon.
Expand All @@ -1599,12 +1604,7 @@ std::vector<geometry_msgs::msg::Point> calcBound(
}

if (!enable_expanding_intersection_areas) {
const auto bound = motion_utils::removeOverlapPoints(to_ros_point(bound_points));
return skip_post_process
? bound
: postProcess(
bound, path, planner_data, drivable_lanes, enable_expanding_hatched_road_markings,
enable_expanding_intersection_areas, is_left, is_driving_forward);
return post_process(removeOverlapPoints(to_ros_point(bound_points)), skip_post_process);
}

// Step4. if there are intersection areas, expand drivable bound with the polygon.
Expand All @@ -1613,12 +1613,7 @@ std::vector<geometry_msgs::msg::Point> calcBound(
getBoundWithIntersectionAreas(bound_points, route_handler, drivable_lanes, is_left);
}

const auto bound = motion_utils::removeOverlapPoints(to_ros_point(bound_points));
return skip_post_process
? bound
: postProcess(
bound, path, planner_data, drivable_lanes, enable_expanding_hatched_road_markings,
enable_expanding_intersection_areas, is_left, is_driving_forward);
return post_process(removeOverlapPoints(to_ros_point(bound_points)), skip_post_process);

Check warning on line 1616 in planning/behavior_path_planner_common/src/utils/drivable_area_expansion/static_drivable_area.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

calcBound increases in cyclomatic complexity from 10 to 12, 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.

Check notice on line 1616 in planning/behavior_path_planner_common/src/utils/drivable_area_expansion/static_drivable_area.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Excess Number of Function Arguments

calcBound increases from 5 to 8 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
}

std::vector<geometry_msgs::msg::Point> makeBoundLongitudinallyMonotonic(
Expand Down

0 comments on commit feacf2c

Please sign in to comment.