Shapes return an empty array
colludium opened this issue · 1 comments
colludium commented
I am finding that some hull shapes will return an empty array (for both polygonDecomp(a) and polygonQuickDecomp(a) ). Here's an example - when plotted in Excel these points make a simple hull shape:
[[1100,300],[300,1100],[300,3100],[1300,3700],[3100,3800],[3700,3200],[3700,2300],[1800,300],[1200,300]]
schteppe commented
I believe you forgot to make the polygon counter-clockwise. The following works for me:
var path=[[1100,300],[300,1100],[300,3100],[1300,3700],[3100,3800],[3700,3200],[3700,2300],[1800,300],[1200,300]];
decomp.makeCCW(path);
var polys = decomp.quickDecomp(path);
You can test this yourself in the online demo, just paste the following in the console:
path=[[1100,300],[300,1100],[300,3100],[1300,3700],[3100,3800],[3700,3200],[3700,2300],[1800,300],[1200,300]].map((point)=>[0.1*point[0]+100,0.1*point[1]+200]); decomp.makeCCW(path); polys=decomp.quickDecomp(path); mousedown=true; render();
If you remove the makeCCW() part, the algorithm will not work and you will get an empty result.