Skip to content

Commit cf934a8

Browse files
enpemeta-codesync[bot]
authored andcommitted
Minor fix in test for Cylinder3
Summary: Follow-up for D87401326. The or a problem persisted: https://github.com/facebookresearch/ocean/actions/runs/19528205954/job/55905174755#step:7:784 Fixed a crash in CylinderT3::nearestIntersection() and TestCylinder3 when handling rays that are parallel or nearly parallel to the cylinder axis. The quadratic equation solver EquationT<T>::solveQuadratic() has an assertion that the quadratic coefficient 'a' must be non-zero. However, when computing ray-cylinder intersections, 'a' equals [d^T·d - (d^T·q)^2], which can be approximately zero when the ray direction d is parallel to the cylinder axis q. Added NumericT<T>::isNotEqualEps(a) checks before calling solveQuadratic() in: 1. Cylinder3.h: nearestIntersection() method 2. TestCylinder3.cpp: ground-truth calculation in test This matches the pattern already used in TestCone3.cpp and properly handles floating-point edge cases. Reviewed By: janherling Differential Revision: D87572921 fbshipit-source-id: 7289e7b0354d9627d87160c8f1ab10f77e652af0
1 parent 0225ced commit cf934a8

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

impl/ocean/math/Cylinder3.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ bool CylinderT3<T>::nearestIntersection(const LineT3<T>& ray, VectorT3<T>& inter
283283

284284
T minDistance = T(-1.), maxDistance = T(-1.);
285285

286-
if (EquationT<T>::solveQuadratic(a, b, c, minDistance, maxDistance))
286+
if (NumericT<T>::isNotEqualEps(a) && EquationT<T>::solveQuadratic(a, b, c, minDistance, maxDistance))
287287
{
288288
minDistance = min(minDistance, maxDistance);
289289
}
@@ -317,4 +317,3 @@ inline bool CylinderT3<T>::isValid() const
317317
} // namespace Ocean
318318

319319
#endif // META_OCEAN_MATH_CYLINDER_3_H
320-

impl/ocean/test/testmath/TestCylinder3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ bool TestCylinder3::testNearestIntersection(const double testDuration)
190190
const T a = projectedDirection.sqr();
191191
const T b = T(2.0) * (projectedDirection * projectedOrigin);
192192
const T c = projectedOrigin.sqr() - T(1.0);
193-
if (EquationT<T>::solveQuadratic(a, b, c, minDistance, maxDistance))
193+
if (NumericT<T>::isNotEqualEps(a) && EquationT<T>::solveQuadratic(a, b, c, minDistance, maxDistance))
194194
{
195195
if (minDistance < T(0.0))
196196
{

0 commit comments

Comments
 (0)