checkpoint depth-mark based pooling strategy

This commit is contained in:
Stewart Allen 2020-11-02 16:36:48 -05:00
commit d5490290f1
3 changed files with 19 additions and 7 deletions

View file

@ -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) {

View file

@ -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 = [];

View file

@ -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);