From 359b76b9af2a441a11c4f153509a671940898480 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Sep 2024 11:31:25 +0200 Subject: [PATCH] add a note about float imprecisions --- crates/parry2d/examples/bounding_sphere2d.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/parry2d/examples/bounding_sphere2d.rs b/crates/parry2d/examples/bounding_sphere2d.rs index 66bd4de6..81c05eab 100644 --- a/crates/parry2d/examples/bounding_sphere2d.rs +++ b/crates/parry2d/examples/bounding_sphere2d.rs @@ -48,8 +48,15 @@ async fn main() { GREEN }; - //assert!(bounding_bounding_sphere.contains(&bounding_sphere_cube1)); - //assert!(bounding_bounding_sphere.contains(&bounding_sphere_cube2)); + // Due to float imprecisions, it's dangerous to assume that both shapes will be + // contained in the merged. + // You can leverage `BoundingVolume::loosened` with an epsilon for expected results. + // + // These might fail: + // assert!(bounding_bounding_sphere.contains(&bounding_sphere_cube1)); + // assert!(bounding_bounding_sphere.contains(&bounding_sphere_cube2)); + + assert!(loose_bounding_sphere_cube2.contains(&bounding_sphere_cube1)); assert!(loose_bounding_sphere_cube2.contains(&bounding_sphere_cube2)); let cube1_translation =