Skip to content

fix: BvhNode::scale now handles negative scale components correctly#406

Open
robtfm wants to merge 1 commit intodimforge:masterfrom
robtfm:fix-bvh-negative-scale
Open

fix: BvhNode::scale now handles negative scale components correctly#406
robtfm wants to merge 1 commit intodimforge:masterfrom
robtfm:fix-bvh-negative-scale

Conversation

@robtfm
Copy link
Contributor

@robtfm robtfm commented Mar 6, 2026

check/update bvh for negative scales and remove arg condition. this condition was not mentioned in (at least) TriMesh::scaled_by, doesn't seem expensive to check correctly, and is on an infrequent codepath.

--

Previously, scaling an AABB by a negative factor would produce an inverted AABB (mins > maxs on the negated axis), breaking the BVH invariant and causing all intersection/shapecast queries to silently miss geometry.

Fix by taking component-wise min/max of the two scaled corners, so the AABB invariant is preserved regardless of sign. The parent-child containment property of the BVH is maintained since scale(merge(A,B)) == merge(scale(A),scale(B)) holds for any non-zero scale.

This unblocks use of TriMesh::scaled with negative scale (e.g. reflections).

Previously, scaling an AABB by a negative factor would produce an inverted
AABB (mins > maxs on the negated axis), breaking the BVH invariant and
causing all intersection/shapecast queries to silently miss geometry.

Fix by taking component-wise min/max of the two scaled corners, so the
AABB invariant is preserved regardless of sign. The parent-child containment
property of the BVH is maintained since scale(merge(A,B)) == merge(scale(A),scale(B))
holds for any non-zero scale.

This unblocks use of TriMesh::scaled with negative scale (e.g. reflections).
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.

1 participant