From 0aa39277fab0a9a83e8b1283b910c65f3b98c2eb Mon Sep 17 00:00:00 2001 From: Kosuke Takeuchi Date: Sun, 14 Jan 2024 23:37:39 +0900 Subject: [PATCH] fix(motion_utils): add guard to calcCurvature (#6070) * fix(motion_utils): add guard to calcCurvature Signed-off-by: kosuke55 * style(pre-commit): autofix --------- Signed-off-by: kosuke55 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../include/motion_utils/trajectory/trajectory.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/motion_utils/include/motion_utils/trajectory/trajectory.hpp b/common/motion_utils/include/motion_utils/trajectory/trajectory.hpp index d81f75815ecc6..b9136bc4002e3 100644 --- a/common/motion_utils/include/motion_utils/trajectory/trajectory.hpp +++ b/common/motion_utils/include/motion_utils/trajectory/trajectory.hpp @@ -952,7 +952,10 @@ calcArcLength>( template std::vector calcCurvature(const T & points) { - std::vector curvature_vec(points.size()); + std::vector curvature_vec(points.size(), 0.0); + if (points.size() < 3) { + return curvature_vec; + } for (size_t i = 1; i < points.size() - 1; ++i) { const auto p1 = tier4_autoware_utils::getPoint(points.at(i - 1));