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

Convex shape validator fails to validate bucket shape #224

Open
CreativeTechGuy opened this issue Nov 20, 2022 · 2 comments · May be fixed by #265
Open

Convex shape validator fails to validate bucket shape #224

CreativeTechGuy opened this issue Nov 20, 2022 · 2 comments · May be fixed by #265

Comments

@CreativeTechGuy
Copy link

CreativeTechGuy commented Nov 20, 2022

Example code:

const bucket = new planck.Polygon([
    { x: -30, y: -26 },
    { x: -26, y: -18 },
    { x: -20, y: 26 },
    { x: 22, y: 26 },
    { x: 28, y: -18 },
    { x: 32, y: -26 },
    { x: 32, y: 30 },
    { x: -30, y: 30 },
].map((v) => new planck.Vec2(v)));
console.log(bucket.validate()); // This shows true

Screenshot of the points on a coordinate plane:

image

This is not a convex shape, but for some reason the validator says it is. This might be related to #218 although I am not repeating my start/end points so there is probably a different issue.

@CreativeTechGuy
Copy link
Author

Okay I think I figured it out. When constructing a Polygon, it'll generate the convex hull and strip out the remaining points. So in my screenshot, just points 1, 6, 7, 8 will remain. This all happens before validate can be called. So by the time you try to validate it, the shape has already been changed to a convex hull and so it'll be true.

It seems like the validate method should be static on the Polygon class since it doesn't work after the polygon has already been constructed.

@shakiba
Copy link
Collaborator

shakiba commented Jul 7, 2023

I only find one testbed example where this is used, I guess this was made to test the conversion code (rather than validate user input). Anyway, if you would like please free to make a pull request and convert it to a static method.

@MichaelHinrichs MichaelHinrichs linked a pull request Sep 25, 2023 that will close this issue
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 a pull request may close this issue.

2 participants