Skip to content

Commit

Permalink
Refactor to use common function
Browse files Browse the repository at this point in the history
Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed Aug 9, 2024
1 parent 72fae32 commit 6607895
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ bool is_before_terminal(
const PredictedObject & object);

double calc_angle_to_lanelet_segment(const lanelet::ConstLanelets & lanelets, const Pose & pose);

ExtendedPredictedObjects transform_to_extended_objects(
const CommonDataPtr & common_data_ptr, const std::vector<PredictedObject> & objects,
const bool check_prepare_phase);
} // namespace autoware::behavior_path_planner::utils::lane_change

namespace autoware::behavior_path_planner::utils::lane_change::debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ lane_change::TargetObjects NormalLaneChange::getTargetObjects(
FilteredByLanesExtendedObjects NormalLaneChange::filterObjects() const

Check warning on line 997 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp#L997

Added line #L997 was not covered by tests
{
const auto & route_handler = getRouteHandler();
const auto & common_parameters = planner_data_->parameters;
auto objects = *planner_data_->dynamic_object;
utils::path_safety_checker::filterObjectsByClass(
objects, lane_change_parameters_->object_types_to_check);
Expand Down Expand Up @@ -1054,46 +1053,21 @@ FilteredByLanesExtendedObjects NormalLaneChange::filterObjects() const
return is_within_vel_th(object) && ahead_of_ego;
});

ExtendedPredictedObjects extended_target_lane_leading_objects;
const auto is_check_prepare_phase = check_prepare_phase();
std::for_each(
filtered_by_lanes_objects.target_lane_leading.begin(),
filtered_by_lanes_objects.target_lane_leading.end(), [&](const auto & object) {
auto extended_predicted_object = utils::lane_change::transform(
object, common_parameters, *lane_change_parameters_, is_check_prepare_phase);
extended_target_lane_leading_objects.push_back(extended_predicted_object);
});

ExtendedPredictedObjects extended_target_lane_trailing_objects;
std::for_each(
filtered_by_lanes_objects.target_lane_trailing.begin(),
filtered_by_lanes_objects.target_lane_trailing.end(), [&](const auto & object) {
auto extended_predicted_object = utils::lane_change::transform(
object, common_parameters, *lane_change_parameters_, is_check_prepare_phase);
extended_target_lane_trailing_objects.push_back(extended_predicted_object);
});

ExtendedPredictedObjects extended_current_lane_objects;
std::for_each(
filtered_by_lanes_objects.current_lane.begin(), filtered_by_lanes_objects.current_lane.end(),
[&](const auto & object) {
auto extended_predicted_object = utils::lane_change::transform(
object, common_parameters, *lane_change_parameters_, is_check_prepare_phase);
extended_current_lane_objects.push_back(extended_predicted_object);
});

ExtendedPredictedObjects extended_other_lane_objects;
std::for_each(
filtered_by_lanes_objects.other_lane.begin(), filtered_by_lanes_objects.other_lane.end(),
[&](const auto & object) {
auto extended_predicted_object = utils::lane_change::transform(
object, common_parameters, *lane_change_parameters_, is_check_prepare_phase);
extended_other_lane_objects.push_back(extended_predicted_object);
});
const auto target_lane_leading_extended_objects =
utils::lane_change::transform_to_extended_objects(
common_data_ptr_, filtered_by_lanes_objects.target_lane_leading, is_check_prepare_phase);
const auto target_lane_trailing_extended_objects =
utils::lane_change::transform_to_extended_objects(
common_data_ptr_, filtered_by_lanes_objects.target_lane_trailing, is_check_prepare_phase);
const auto current_lane_extended_objects = utils::lane_change::transform_to_extended_objects(
common_data_ptr_, filtered_by_lanes_objects.current_lane, is_check_prepare_phase);
const auto other_lane_extended_objects = utils::lane_change::transform_to_extended_objects(
common_data_ptr_, filtered_by_lanes_objects.other_lane, is_check_prepare_phase);

FilteredByLanesExtendedObjects lane_change_target_objects(
extended_current_lane_objects, extended_target_lane_leading_objects,
extended_target_lane_trailing_objects, extended_other_lane_objects);
current_lane_extended_objects, target_lane_leading_extended_objects,
target_lane_trailing_extended_objects, other_lane_extended_objects);
lane_change_debug_.filtered_objects = lane_change_target_objects;

Check notice on line 1071 in planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Method

NormalLaneChange::filterObjects is no longer above the threshold for cyclomatic complexity. 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.
return lane_change_target_objects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,23 @@ double calc_angle_to_lanelet_segment(const lanelet::ConstLanelets & lanelets, co
const auto closest_pose = lanelet::utils::getClosestCenterPose(closest_lanelet, pose.position);
return std::abs(autoware::universe_utils::calcYawDeviation(closest_pose, pose));
}

ExtendedPredictedObjects transform_to_extended_objects(

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp#L1358

Added line #L1358 was not covered by tests
const CommonDataPtr & common_data_ptr, const std::vector<PredictedObject> & objects,
const bool check_prepare_phase)
{
ExtendedPredictedObjects extended_objects;
extended_objects.reserve(objects.size());

const auto & bpp_param = *common_data_ptr->bpp_param_ptr;
const auto & lc_param = *common_data_ptr->lc_param_ptr;
std::transform(
objects.begin(), objects.end(), std::back_inserter(extended_objects), [&](const auto & object) {
return utils::lane_change::transform(object, bpp_param, lc_param, check_prepare_phase);

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp#L1369

Added line #L1369 was not covered by tests
});

return extended_objects;

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

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/src/utils/utils.cpp#L1372

Added line #L1372 was not covered by tests
}
} // namespace autoware::behavior_path_planner::utils::lane_change

namespace autoware::behavior_path_planner::utils::lane_change::debug
Expand Down

0 comments on commit 6607895

Please sign in to comment.