Skip to content

Should convex decomposition return an option or a result? #264

Description

@hakolao

I ran into

A compound shape must contain at least one shape.

I'm generating lots of convex decomposition colliders like this:

        let contours = self.contours_with_holes_flat(bitmap_to_pixels, simplify_epsilon);
        if contours.len() < 4 {
            return vec![];
        }
        let indices = (0..contours.len() as u32 - 1)
            .map(|i| [i, i + 1])
            .collect::<Vec<[u32; 2]>>();
        let collider = ColliderBuilder::convex_decomposition_with_params(
            &contours,
            &indices,
            &VHACDParameters {
                resolution: 64,
                fill_mode,
                ..Default::default()
            },
        )
        .build();

The assertion in parry2d-0.17.0\src\shape\compound.rs:35:9 causes a panic, and can't do much about it. I don't really know when exactly the function fails to generate a shape, and my attempt to not let too small contours only helps for some other panics...

I would prefer no panics, and let the user handle the issues (Option or Result).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions