Description
Describe the bug
The CatmullRomSpline
member function getPolygon
when called with num_points = 0
raises an error with a description failed to calculate curve index
.
This description does not say where the real error is in this case. It is thrown deep from the call stack by member function getCurveIndexAndS
in the call order presented below:
getPolygon -> getLeftBounds -> getNormalVector -> getCurveIndexAndS
This happens because the num_points
(= 0) is used in getLeftBounds
to calculate step_size
(which is then equal to infinity).
This leads to a NaN
s
value which then is not matched to any component curve and a mentioned exception is being thrown by getCurveIndexAndS
.In my opinion there are three ways to improve the behavior in this situation:
- To catch the exception in the
getPolygon
function and thrown another exception with more informative description - To just throw an exception in
getPolygon
whennum_points == 0
- To add an early return in
getPolygon
to return an empty vector whennum_points == 0
Context:
I am adding unit tests for the geometry package and wanted to add tests for the getPolygon
function.
To Reproduce
Steps to reproduce the behavior:
- Edit any existing source code file or create a new one
- Create any
CatmullRomSpline
- Call the
getPolygon
member function withnum_points
argument set to 0 - Compile and execute
- See the error
Expected behavior
Either an exception with an appropriate description or the return of an empty vector.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]: Ubuntu
- Browser [e.g. chrome, safari]: Firefox
- Version [e.g. 22]: 22
- ROS 2 version: Humble
- DDS: CycloneDDS