Skip to content

Commit

Permalink
introduce early break to reduce computation time
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
  • Loading branch information
danielsanchezaran committed Jun 18, 2024
1 parent 4b6a201 commit 723ad9b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions control/autoware_autonomous_emergency_braking/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ void AEB::createObjectDataUsingPredictedObjects(
if (collision_points_bg.empty()) continue;

// Create an object for each intersection point
bool collision_points_added{false};
for (const auto & collision_point : collision_points_bg) {
const auto obj_position =
tier4_autoware_utils::createPoint(collision_point.x(), collision_point.y(), 0.0);
Expand All @@ -685,7 +686,11 @@ void AEB::createObjectDataUsingPredictedObjects(
obj.velocity = (obj_tangent_velocity > 0.0) ? obj_tangent_velocity : 0.0;
obj.distance_to_object = std::abs(dist_ego_to_object);
object_data_vector.push_back(obj);
collision_points_added = true;
}
// The ego polygons are in order, so the first intersection points found are the closest
// points. It is not necessary to continue iterating the ego polys for the same object.
if (collision_points_added) break;
}
});
}

Check warning on line 696 in control/autoware_autonomous_emergency_braking/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

AEB::createObjectDataUsingPredictedObjects 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.

Check warning on line 696 in control/autoware_autonomous_emergency_braking/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

AEB::createObjectDataUsingPredictedObjects has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
Expand Down

0 comments on commit 723ad9b

Please sign in to comment.