heal polys before tracing

This commit is contained in:
Stewart Allen 2021-01-14 09:25:58 -05:00
commit 208a2f2b0c
3 changed files with 16 additions and 3 deletions

View file

@ -106,6 +106,7 @@
tabs,
cutTabs,
cutPolys,
healPolys,
slicer,
sliceAll,
updateToolDiams,
@ -273,8 +274,11 @@
function cutPolys(polys, offset, z, inter) {
let noff = [];
// tabs = tabs.filter(tab => z < tab.pos.z + tab.dim.z/2).map(tab => tab.off).flat();
offset.forEach(op => noff.appendAll( op.cut(POLY.union(polys, 0, true), inter) ));
return healPolys(noff);
}
function healPolys(noff) {
if (noff.length > 1) {
let heal = 0;
// heal/rejoin open segments that share endpoints
@ -317,6 +321,14 @@
// cull nulls
noff = noff.filter(o => o);
}
// close poly if head meets tail
for (let poly of noff) {
if (poly.open && poly.first().isMergable2D(poly.last())) {
poly.points.pop();
poly.length--;
poly.open = false;
}
}
}
return noff;
}