Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounding sphere merge sometimes results in non including both shapes #260

Open
Vrixyz opened this issue Sep 4, 2024 · 0 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@Vrixyz
Copy link
Contributor

Vrixyz commented Sep 4, 2024

Due to float imprecisions, we can't be certain a call to bounding1.merged(bounding2) will results in a bounding containing both shapes (or contains might return false for 1 or both shapes).

Reproduction

        let cube1_pos = Vec2::new(3.75, 2.6516504);
        let cube1_pos = Isometry2::translation(cube1_pos.x, cube1_pos.y);
        let cube2_pos = Isometry2::identity();
        dbg!(cube1_pos.translation);
        dbg!(cube2_pos.translation);

        let bounding_sphere_cube1 = cube1.bounding_sphere(&cube1_pos);
        let bounding_sphere_cube2 = cube2.bounding_sphere(&cube2_pos);

        // Merge the two spheres.
        let bounding_bounding_sphere = dbg!(bounding_sphere_cube1.merged(&bounding_sphere_cube2));

        // This fails /!\
        assert!(bounding_bounding_sphere.contains(&bounding_sphere_cube2));
[crates/parry2d/examples/bounding_sphere2d.rs:31:9] cube1_pos.translation = [
    3.75,
    2.6516504,
]
[crates/parry2d/examples/bounding_sphere2d.rs:32:9] cube2_pos.translation = [
    0.0,
    0.0,
]
[crates/parry2d/examples/bounding_sphere2d.rs:38:40] bounding_sphere_cube1.merged(&bounding_sphere_cube2) = BoundingSphere {
    center: [
        1.7072396,
        1.2072008,
    ],
    radius: 3.208967,
}
thread 'main' panicked at crates/parry2d/examples/bounding_sphere2d.rs:39:9:
assertion failed: bounding_bounding_sphere.contains(&bounding_sphere_cube2)

That's why bounding.loosened() exists.

The examples shouldn't encourage this assumption:

assert!(bounding_bounding_sphere.contains(&bounding_sphere_cube1));

@Vrixyz Vrixyz added the documentation Improvements or additions to documentation label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant