Repository navigation
Handle rounding in flat BoundingBox ray clipping - #3075
adrian-andrzjewski wants to merge 1 commit into
Conversation
|
@riccardobl @pspeed42 — could one of you review this fix for #2556 when you have a chance? It adds a narrow scale-relative tolerance for nearly coincident slab distances, with regressions for flat-box corner hits and out-of-plane misses. Thanks. |
| } | ||
| // the comparison. Algebra for the win. | ||
| float newT = numerator / denom; | ||
| if (newT < t[0] - clipTolerance(newT, t[0])) { |
There was a problem hiding this comment.
This also relaxes the ray-origin lower bound t[0] = 0, so a ray that starts just outside a slab and travels away from the box can be reported as a hit: its exit parameter is slightly negative, passes this tolerance check, and the collision code then returns a contact at the origin. The tolerance should only bridge rounding between slab clipping distances, not admit an interval entirely behind the ray. Could you keep the zero-time bound exact?
| if (newT < t[0] - clipTolerance(newT, t[0])) { | |
| if (newT < t[0] && (t[0] == 0.0f || newT < t[0] - clipTolerance(newT, t[0]))) { |
jaime-jmebot
left a comment
There was a problem hiding this comment.
Hi, thanks for tackling this corner case and adding focused regressions. The change is nicely scoped, and keeping the parallel-slab test exact is important for preserving misses on flat boxes. I reviewed both ray-collision paths, which share this clipping helper, and the added tests cover the reported rounding issue from both clipping directions.
I did find one edge case to address before merging: the tolerance in the negative-denominator branch also applies when t[0] is still the ray's initial lower bound of zero. That can accept a slightly negative exit distance for a ray that starts just outside a box and points away from it; the collision path then treats the changed clipping interval as a hit, even though the entire interval is behind the ray origin. The inline comment suggests keeping that zero-time bound exact while still allowing tolerance between actual slab entry and exit distances.
Once that is addressed, this looks close. Thanks again for the targeted regression coverage!
Summary
BoundingBoxinstances.Fixes #2556.
Validation
gradlew.bat :jme3-core:testpassed on Windows.