Open lostPixels opened 2 years ago
I discovered that when usingsubtract() in the context of a P5JS generative app that the resulting polygons vertices were not in the correct order.
subtract()
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);
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) `
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.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) `