Skip to content

Commit

Permalink
Add guard against division by 0, and use interpolation::lerp
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
  • Loading branch information
maxime-clem committed Jun 30, 2023
1 parent e4aef59 commit 31d72bd
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "behavior_path_planner/utils/drivable_area_expansion/map_utils.hpp"
#include "behavior_path_planner/utils/drivable_area_expansion/parameters.hpp"
#include "behavior_path_planner/utils/drivable_area_expansion/types.hpp"
#include "interpolation/linear_interpolation.hpp"

#include <boost/geometry.hpp>

Expand Down Expand Up @@ -144,8 +145,12 @@ void copy_z_over_arc_length(
s_from_prev = s_from;
s_from += tier4_autoware_utils::calcDistance2d(from[i_from], from[i_from + 1]);
}
const auto ratio = (s_to - s_from_prev) / (s_from - s_from_prev);
to[i_to].z = from[i_from - 1].z + ratio * (from[i_from].z - from[i_from - 1].z);
if (s_from - s_from_prev != 0.0) {
const auto ratio = (s_to - s_from_prev) / (s_from - s_from_prev);
to[i_to].z = interpolation::lerp(from[i_from - 1].z, from[i_from].z, ratio);
} else {
to[i_to].z = to[i_to - 1].z;

Check warning on line 152 in planning/behavior_path_planner/src/utils/drivable_area_expansion/drivable_area_expansion.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/utils/drivable_area_expansion/drivable_area_expansion.cpp#L152

Added line #L152 was not covered by tests
}
}
}

Check warning on line 155 in planning/behavior_path_planner/src/utils/drivable_area_expansion/drivable_area_expansion.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

copy_z_over_arc_length has a cyclomatic complexity of 9, 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 31d72bd

Please sign in to comment.