Skip to content

Commit 7941300

Browse files
authored
Return early from edge interpolation for zero-length edges (#5453)
* Return early from edge interpolation for zero-length edges Signed-off-by: Emerson Knapp <[email protected]> * Move the check and add a test Signed-off-by: Emerson Knapp <[email protected]> --------- Signed-off-by: Emerson Knapp <[email protected]>
1 parent 69a60df commit 7941300

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

nav2_route/src/path_converter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ void PathConverter::interpolateEdge(
141141
// Find number of points to populate by given density
142142
const float mag = hypotf(x1 - x0, y1 - y0);
143143
const unsigned int num_pts = ceil(mag / density_);
144+
// For zero-length edges, we can just push the start point and return
145+
if (num_pts < 1) {
146+
return;
147+
}
148+
144149
const float iterpolated_dist = mag / num_pts;
145150

146151
// Find unit vector direction

nav2_route/test/test_path_converter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,15 @@ TEST(PathConverterTest, test_path_converter_interpolation)
163163
poses[i].pose.position.y - poses[i + 1].pose.position.y), 0.05);
164164
}
165165
}
166+
167+
TEST(PathConverterTest, test_path_converter_zero_length_edge)
168+
{
169+
auto node = std::make_shared<nav2::LifecycleNode>("edge_scorer_test");
170+
PathConverter converter;
171+
converter.configure(node);
172+
173+
float x0 = 10.0, y0 = 10.0, x1 = 10.0, y1 = 10.0;
174+
std::vector<geometry_msgs::msg::PoseStamped> poses;
175+
converter.interpolateEdge(x0, y0, x1, y1, poses);
176+
ASSERT_TRUE(poses.empty());
177+
}

0 commit comments

Comments
 (0)