Skip to content

Commit b712753

Browse files
committed
Use algorithm functions instead of for loop code
1 parent 4db120b commit b712753

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

external/concealer/src/field_operator_application.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,10 @@ auto FieldOperatorApplication::plan(
359359
assert(not route.empty());
360360

361361
std::vector<geometry_msgs::msg::Pose> waypoints;
362-
for (size_t i = 0; i < route.size() - 1; ++i) {
363-
waypoints.push_back(route[i].pose);
362+
if (route.size() > 1) {
363+
std::transform(
364+
route.begin(), route.end() - 1, std::back_inserter(waypoints),
365+
[](const auto & stamped_pose) { return stamped_pose.pose; });
364366
}
365367

366368
RouteOption route_option;
@@ -386,13 +388,9 @@ static auto make(
386388
request->goal = goal;
387389

388390
if constexpr (std::is_same_v<Request, autoware_adapi_v1_msgs::srv::SetRoutePoints::Request>) {
389-
for (const auto & waypoint : waypoints) {
390-
request->waypoints.push_back(waypoint);
391-
}
391+
request->waypoints.assign(waypoints.begin(), waypoints.end());
392392
} else if constexpr (std::is_same_v<Request, autoware_adapi_v1_msgs::srv::SetRoute::Request>) {
393-
for (const auto & waypoint : waypoints) {
394-
request->segments.push_back(waypoint);
395-
}
393+
request->segments.assign(waypoints.begin(), waypoints.end());
396394
}
397395

398396
/*

simulation/traffic_simulator/src/entity/ego_entity.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ void EgoEntity::requestAssignRoute(
270270
"Failed to get current lanelet of ego entity. (", __FILE__, ":", __LINE__, ")");
271271
}
272272

273-
for (size_t i = 0; i < route.size(); ++i) {
273+
for (const auto & route_point : route) {
274274
// NOTE: Interpolating between lanelets because set route API requires continuous lanelet ids on lanelet graph
275275
auto segment_route = hdmap_utils_ptr_->getRoute(
276-
route_segments.back().preferred.id, route[i].getLaneletId(), routing_configuration);
277-
for (auto lanelet_id : segment_route) {
278-
route_segments.push_back(make_segment(lanelet_id));
279-
}
276+
route_segments.back().preferred.id, route_point.getLaneletId(), routing_configuration);
277+
std::transform(
278+
segment_route.begin(), segment_route.end(), std::back_inserter(route_segments),
279+
[make_segment](const int64_t & lanelet_id) { return make_segment(lanelet_id); });
280280
}
281281

282282
// NOTE: Make the lanelet IDs unique, because set route API recognizes duplicate IDs as loops and does not accept.
@@ -329,8 +329,8 @@ void EgoEntity::requestAssignRoute(
329329

330330
auto goal = route.back();
331331
std::vector<geometry_msgs::msg::Pose> waypoints;
332-
for (size_t i = 0; i < route.size() - 1; ++i) {
333-
waypoints.push_back(route[i]);
332+
if (route.size() > 1) {
333+
waypoints.assign(route.begin(), route.end() - 1);
334334
}
335335

336336
if (not initialized) {
@@ -402,12 +402,13 @@ auto EgoEntity::requestReplanRoute(
402402
concealer::FieldOperatorApplication::RouteOption route_option;
403403
route_option.allow_goal_modification = allow_goal_modification;
404404
assert(not route.empty());
405-
auto goal = route.back().pose;
406405
std::vector<geometry_msgs::msg::Pose> waypoints;
407-
for (size_t i = 0; i < route.size() - 1; ++i) {
408-
waypoints.push_back(route[i].pose);
406+
if (route.size() > 1) {
407+
std::transform(
408+
route.begin(), route.end() - 1, waypoints.begin(),
409+
[](const geometry_msgs::msg::PoseStamped & pose) { return pose.pose; });
409410
}
410-
plan(goal, waypoints, route_option);
411+
plan(route.back().pose, waypoints, route_option);
411412
}
412413
enableAutowareControl();
413414
FieldOperatorApplication::engage();

0 commit comments

Comments
 (0)