From d5490290f13f371aa73e1d8a1df343c395d6ed7a Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Mon, 2 Nov 2020 16:36:48 -0500 Subject: [PATCH] checkpoint depth-mark based pooling strategy --- src/geo/polygons.js | 10 +++++++--- src/kiri/print.js | 3 ++- src/mode/cam/driver.js | 13 ++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/geo/polygons.js b/src/geo/polygons.js index ff83aded..b4530927 100644 --- a/src/geo/polygons.js +++ b/src/geo/polygons.js @@ -148,7 +148,9 @@ * @returns {Polygon[]} top level parent polygons */ function nest(polygons, deep, opentop) { - if (!polygons) return polygons; + if (!polygons) { + return polygons; + } // sort groups by size polygons.sort(function (a, b) { return a.area() - b.area(); @@ -167,7 +169,9 @@ for (let j = i + 1; j < polygons.length; j++) { let parent = polygons[j]; // prevent open polys from having inners - if (opentop && parent.isOpen()) continue; + if (opentop && parent.isOpen()) { + continue; + } if (poly.isNested(parent)) { parent.addInner(poly); break; @@ -545,7 +549,7 @@ opt.outs.append(polys, opt.flat); // callback for expand() compatibility if (opt.call) { - opt.call(polys, count); + opt.call(polys, count, depth); } // check for more offsets if (count > 1) { diff --git a/src/kiri/print.js b/src/kiri/print.js index 50c84ce4..5688c2b3 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -1057,7 +1057,8 @@ // - it has more than one sibling // - it has no parent (top/outer most) // - it is offset from its parent by more than diameter - if (poly.isOpen() || !poly.parent || poly.parent.innerCount() > 1 || !polygonWithinOffset(poly, poly.parent, offset)) { + // if (poly.isOpen() || !poly.parent || poly.parent.innerCount() > 1 || !polygonWithinOffset(poly, poly.parent, offset)) { + if (poly.depth === 0) { pools.push(poly); poly.pool = []; poly.poolsDown = []; diff --git a/src/mode/cam/driver.js b/src/mode/cam/driver.js index b8fe841e..4a91ea57 100644 --- a/src/mode/cam/driver.js +++ b/src/mode/cam/driver.js @@ -686,8 +686,8 @@ outer = [], offset = []; - // when holes present, use them as fake top offsets - // to prevent clearing out the entire thru pocket + // when thru holes present, treat them as top offsets + // to prevent roughing out the entire hole if (holes) { tops.appendAll(holes); } @@ -711,7 +711,13 @@ z: slice.z, count: 999, flat: true, - outs: outer + outs: outer, + call: (polys, count, depth) => { + polys.forEach(p => { + p.depth = depth; + if (p.inner) p.inner.forEach(p => p.depth = depth); + }); + } }); if (!pocket) { @@ -721,6 +727,7 @@ shell.clone(true).forEach(function(poly) { poly.setZ(slice.z).flattenTo(offset); poly.setClosed(); + poly.depth = 0; }); // re-nest offset polys // outer = POLY.nest(offset);