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

Fix inconsistent Bodies.fromVertices behavior #1178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

controversial
Copy link

When calling Bodies.fromVertices with an array of vertexSets in which some vertexSets are convex and some are concave, the convex vertices end up in wildly different places from the concave vertices.

See the following example, where in vectorized text, the three convex parts (making up the “i” and the “o”) are out of place with the rest of the (concave) parts, even though they were correctly positioned in the input data:

Screenshot 2022-11-19 at 1 22 45 PM

This occurs because the Bodies.fromVertices implementation sets the x, y of convex parts to the input x, y (which is the same for every part) but it sets the x, y of concave parts to the center of mass of the part.

This pull request makes the behavior consistent by ensuring every part has its position set to its center of mass, so that multiple vertexSets passed to Matter.fromVertices have their relative positions preserved.

@dreerr
Copy link

dreerr commented Jun 12, 2024

Thanks a lot, this Pull request finally solved my problem I was having for over a week. I needed Polygons with holes and did not like the results of poly-decomp so I used another algorithm @mapbox/earcut, but the resulting vertices always were on top of each other. With this small change it works!

@dreerr dreerr mentioned this pull request Jun 12, 2024
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 this pull request may close these issues.

2 participants