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

subtract() returns a polygon with vertices in incorrect order. #103

Open
lostPixels opened this issue Jan 8, 2022 · 0 comments
Open

subtract() returns a polygon with vertices in incorrect order. #103

lostPixels opened this issue Jan 8, 2022 · 0 comments

Comments

@lostPixels
Copy link

I discovered that when using subtract() in the context of a P5JS generative app that the resulting polygons vertices were not in the correct order.

const poly1 = new Polygon(polygon1.map(({ x, y }) => [x, y]));
const poly2 = new Polygon(polygon2.map(({ x, y }) => [x, y]));
const res1= subtract(poly1, poly2);

image

This is a basic visualization of the issue when taking two boxes and subtracting one from the other.

To draw this, I'm using the below test code (not super relevant but I figured it could be useful.

`const drawPoly = (poly, color, showIndexes = false) => {
poly.forEach(g => {
fill(color);
beginShape();
g.forEach(p => vertex(p.x, p.y));
endShape();
g.forEach((p, i) => {
circle(p.x, p.y, 10);
if (showIndexes) {
fill(0)
textSize(22)
text(i, p.x, p.y);
}
});

})

}

drawPoly([res.vertices], [100, 100, 100], true)
`

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

No branches or pull requests

1 participant