Skip to content

Commit

Permalink
define vector concatenate function
Browse files Browse the repository at this point in the history
  • Loading branch information
mitukou1109 committed Jun 27, 2024
1 parent 5a44be7 commit 9b313dd
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions planning/autoware_obstacle_cruise_planner/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ bool isLowerConsideringHysteresis(
}
return false;
}

template <typename T>
void concatenate(std::vector<T> & first, const std::vector<T> & last)
{
first.insert(first.end(), last.begin(), last.end());
}
} // namespace

namespace autoware::motion_planning
Expand Down Expand Up @@ -588,13 +594,9 @@ void ObstacleCruisePlannerNode::onTrajectory(const Trajectory::ConstSharedPtr ms
determineEgoBehaviorAgainstPredictedObjectObstacles(
ego_odom, *objects_ptr, traj_points, target_obstacles);

stop_obstacles.insert(
stop_obstacles.end(), stop_object_obstacles.begin(), stop_object_obstacles.end());
cruise_obstacles.insert(
cruise_obstacles.end(), cruise_object_obstacles.begin(), cruise_object_obstacles.end());
slow_down_obstacles.insert(
slow_down_obstacles.end(), slow_down_object_obstacles.begin(),
slow_down_object_obstacles.end());
concatenate(stop_obstacles, stop_object_obstacles);
concatenate(cruise_obstacles, cruise_object_obstacles);
concatenate(slow_down_obstacles, slow_down_object_obstacles);
}
if (pointcloud_ptr && !pointcloud_ptr->data.empty()) {
const auto target_obstacles =
Expand All @@ -603,14 +605,9 @@ void ObstacleCruisePlannerNode::onTrajectory(const Trajectory::ConstSharedPtr ms
const auto & [stop_pointcloud_obstacles, cruise_pointcloud_obstacles, slow_down_pointcloud_obstacles] =
determineEgoBehaviorAgainstPointCloudObstacles(ego_odom, traj_points, target_obstacles);

stop_obstacles.insert(
stop_obstacles.end(), stop_pointcloud_obstacles.begin(), stop_pointcloud_obstacles.end());
cruise_obstacles.insert(
cruise_obstacles.end(), cruise_pointcloud_obstacles.begin(),
cruise_pointcloud_obstacles.end());
slow_down_obstacles.insert(
slow_down_obstacles.end(), slow_down_pointcloud_obstacles.begin(),
slow_down_pointcloud_obstacles.end());
concatenate(stop_obstacles, stop_pointcloud_obstacles);
concatenate(cruise_obstacles, cruise_pointcloud_obstacles);
concatenate(slow_down_obstacles, slow_down_pointcloud_obstacles);
}
return std::make_tuple(stop_obstacles, cruise_obstacles, slow_down_obstacles);
}();

Check warning on line 613 in planning/autoware_obstacle_cruise_planner/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

ObstacleCruisePlannerNode::onTrajectory has a cyclomatic complexity of 13, 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.
Expand Down

0 comments on commit 9b313dd

Please sign in to comment.