Skip to content

Handle rounding in flat BoundingBox ray clipping - #3075

Open
adrian-andrzjewski wants to merge 1 commit into
jMonkeyEngine:masterfrom
adrian-andrzjewski:codex/issue-2556-boundingbox-clip-precision
Open

adrian-andrzjewski wants to merge 1 commit into
jMonkeyEngine:masterfrom
adrian-andrzjewski:codex/issue-2556-boundingbox-clip-precision

Conversation

@adrian-andrzjewski

Copy link
Copy Markdown

Summary

  • Allow scale-relative rounding tolerance when ray slab entry and exit distances nearly coincide, preventing false misses on zero-extent BoundingBox instances.
  • Keep parallel-slab checks exact so rays outside a flat box's plane remain misses.
  • Add regressions for both clipping directions, a nearby miss, and a parallel ray outside the plane.

Fixes #2556.

Validation

  • gradlew.bat :jme3-core:test passed on Windows.
  • The corner case failed against the original implementation (0 collisions) and passes with the fix (1 collision).
  • The issue's TeaVM-specific path was not built; the same miss reproduces in the JVM regression.

@adrian-andrzjewski

Copy link
Copy Markdown
Author

@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])) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Suggested change
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 jaime-jmebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible floating point precision issue in corner case using BoundingBox.clip()

2 participants