Skip to content

Commit

Permalink
perf(motion_utils): improve performance of findNearestIndex (autoware…
Browse files Browse the repository at this point in the history
…foundation#3082) (#344)

Signed-off-by: Taiga Takano <[email protected]>
Co-authored-by: Taiga TAKANO <[email protected]>
  • Loading branch information
tkimura4 and TakanoTaiga authored Apr 3, 2023
1 parent c4ceede commit b6ae4cf
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ boost::optional<size_t> findNearestIndex(

for (size_t i = 0; i < points.size(); ++i) {
const auto squared_dist = tier4_autoware_utils::calcSquaredDistance2d(points.at(i), pose);
if (squared_dist > max_squared_dist) {
if (squared_dist > max_squared_dist || squared_dist >= min_squared_dist) {
continue;
}

Expand All @@ -208,10 +208,6 @@ boost::optional<size_t> findNearestIndex(
continue;
}

if (squared_dist >= min_squared_dist) {
continue;
}

min_squared_dist = squared_dist;
min_idx = i;
is_nearest_found = true;
Expand Down

0 comments on commit b6ae4cf

Please sign in to comment.