From 000aad0a3c36083128765c534e30fd3a35736dce Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Sun, 22 Nov 2020 16:35:59 +0100 Subject: Fix NaNs in unused WAABB lanes during the creation of the WAABBTree. --- src/geometry/waabb.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/geometry/waabb.rs b/src/geometry/waabb.rs index 645ac04..1ebf528 100644 --- a/src/geometry/waabb.rs +++ b/src/geometry/waabb.rs @@ -105,7 +105,16 @@ impl WAABB { } pub fn dilate_by_factor(&mut self, factor: SimdFloat) { - let dilation = (self.maxs - self.mins) * factor; + // If some of the AABBs on this WAABB are invalid, + // don't, dilate them. + let is_valid = self.mins.x.simd_le(self.maxs.x); + let factor = factor.select(is_valid, SimdFloat::zero()); + + // NOTE: we multiply each by factor instead of doing + // (maxs - mins) * factor. That's to avoid overflows (and + // therefore NaNs if this WAABB contains some invalid + // AABBs initialised with f32::MAX + let dilation = self.maxs * factor - self.mins * factor; self.mins -= dilation; self.maxs += dilation; } -- cgit