Skip to content

Commit e35acd5

Browse files
refactor(motion_velocity_planner_common): separation of cache and polygon functions (autowarefoundation#628)
refactor cache Signed-off-by: yuki-takagi-66 <yuki.takagi@tier4.jp>
1 parent d8ea965 commit e35acd5

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

planning/motion_velocity_planner/autoware_motion_velocity_planner_common/include/autoware/motion_velocity_planner_common/utils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ double get_dist_to_traj_poly(
172172
const geometry_msgs::msg::Point & point,
173173
const std::vector<autoware_utils::Polygon2d> & decimated_traj_polys);
174174

175+
/*
176+
* @brief return the distance from `predicted_object` to `decimated_traj_polys`
177+
*/
178+
double calc_dist_to_traj_poly(
179+
const autoware_perception_msgs::msg::PredictedObject & predicted_object,
180+
const std::vector<autoware_utils_geometry::Polygon2d> & decimated_traj_polys);
181+
175182
/**
176183
* @brief append the `input_points` up to `extend_length` every `step_length`, in the direction of
177184
* the last point of `input_points`, keeping its vel/acc

planning/motion_velocity_planner/autoware_motion_velocity_planner_common/src/planner_data.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,7 @@ double PlannerData::Object::get_dist_to_traj_poly(
267267
const std::vector<autoware_utils_geometry::Polygon2d> & decimated_traj_polys) const
268268
{
269269
if (!dist_to_traj_poly) {
270-
const auto & obj_pose = predicted_object.kinematics.initial_pose_with_covariance.pose;
271-
const auto obj_poly = autoware_utils_geometry::to_polygon2d(obj_pose, predicted_object.shape);
272-
dist_to_traj_poly = std::numeric_limits<double>::max();
273-
for (const auto & traj_poly : decimated_traj_polys) {
274-
const double current_dist_to_traj_poly = bg::distance(traj_poly, obj_poly);
275-
dist_to_traj_poly = std::min(*dist_to_traj_poly, current_dist_to_traj_poly);
276-
}
270+
dist_to_traj_poly = utils::calc_dist_to_traj_poly(predicted_object, decimated_traj_polys);
277271
}
278272
return *dist_to_traj_poly;
279273
}

planning/motion_velocity_planner/autoware_motion_velocity_planner_common/src/utils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,18 @@ double get_dist_to_traj_poly(
226226
return dist_to_traj_poly;
227227
}
228228

229+
double calc_dist_to_traj_poly(
230+
const autoware_perception_msgs::msg::PredictedObject & predicted_object,
231+
const std::vector<autoware_utils_geometry::Polygon2d> & decimated_traj_polys)
232+
{
233+
const auto obj_poly = autoware_utils_geometry::to_polygon2d(
234+
predicted_object.kinematics.initial_pose_with_covariance.pose, predicted_object.shape);
235+
double dist_to_traj_poly = std::numeric_limits<double>::max();
236+
for (const auto & traj_poly : decimated_traj_polys) {
237+
const double current_dist_to_traj_poly = boost::geometry::distance(traj_poly, obj_poly);
238+
dist_to_traj_poly = std::min(dist_to_traj_poly, current_dist_to_traj_poly);
239+
}
240+
return dist_to_traj_poly;
241+
}
242+
229243
} // namespace autoware::motion_velocity_planner::utils

0 commit comments

Comments
 (0)