use alt strategy for depth first with outline

This commit is contained in:
Stewart Allen 2026-01-13 20:36:38 -05:00
commit 10c7bec3c8
2 changed files with 21 additions and 9 deletions

View file

@ -136,7 +136,6 @@ class OpArea extends CamOp {
// filter out invalid polys // filter out invalid polys
polys = polys.filter(p => p && p.length > 2); polys = polys.filter(p => p && p.length > 2);
console.log({ polys });
// process each area separately // process each area separately
let proc = 0; let proc = 0;
@ -489,8 +488,9 @@ class OpArea extends CamOp {
min.area.used = true; min.area.used = true;
pocket({ pocket({
cutdir: op.ov_conv, cutdir: op.ov_conv,
depthFirst: process.camDepthFirst && !op.drape, depthFirst: process.camDepthFirst,
easeDown: op.down && process.easeDown ? op.down : 0, easeDown: op.down && process.easeDown ? op.down : 0,
outline: op.drape || op.mode === 'trace',
progress: (n,m) => progress(n/m, "area"), progress: (n,m) => progress(n/m, "area"),
slices: min.area.filter(slice => slice.camLines) slices: min.area.filter(slice => slice.camLines)
}); });

View file

@ -667,16 +667,21 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
* @param {boolean} cutdir true=CW false=CCW * @param {boolean} cutdir true=CW false=CCW
* @param {boolean} depthFirst prioritize cut depth in pockets by nesting * @param {boolean} depthFirst prioritize cut depth in pockets by nesting
*/ */
function pocket({ slices, cutdir, depthFirst, progress }) { function pocket({ slices, cutdir, depthFirst, outline, progress }) {
let total = 0; let total = 0;
let depthData = []; let depthData = [];
for (let slice of slices) { for (let slice of slices) {
let polys = [], t = [], c = []; let polys = [], t = [], c = [];
// use shadow + tool radius offset when available (roughing)
// collect polys in to tops (parents) and children
// so we can have the windings be opposite
POLY.flatten(slice.camLines).forEach((poly) => { POLY.flatten(slice.camLines).forEach((poly) => {
// poly is child if has parent
let child = poly.parent; let child = poly.parent;
// for depth, collapse parent to 1 or 0 (has, missing)
if (depthFirst) { poly = poly.clone(); poly.parent = child ? 1 : 0 } if (depthFirst) { poly = poly.clone(); poly.parent = child ? 1 : 0 }
// place poly into top or child bucket
if (child) c.push(poly); else t.push(poly); if (child) c.push(poly); else t.push(poly);
polys.push(poly); polys.push(poly);
}); });
@ -687,6 +692,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
POLY.setWinding(c, !cutdir); POLY.setWinding(c, !cutdir);
if (depthFirst) { if (depthFirst) {
// re-nest layer polys and add to depth stack
polys = POLY.nest(polys,true,true); polys = POLY.nest(polys,true,true);
polys.tool_shadow = POLY.flatten(slice.tool_shadow.clone(true)); polys.tool_shadow = POLY.flatten(slice.tool_shadow.clone(true));
depthData.push(polys); depthData.push(polys);
@ -706,18 +712,18 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
if (depthFirst) { if (depthFirst) {
for (let i=0; i<depthData.length; i++) { for (let i=0; i<depthData.length; i++) {
descend(depthData.slice(i)); descend(depthData.slice(i), undefined, outline);
} }
} }
} }
function descend(stack, inside) { function descend(stack, inside, outline) {
if (stack.length === 0) return; if (stack.length === 0) return;
let tops = stack[0]; let tops = stack[0];
let flat = tops.filter(poly => !poly.marked); let flat = POLY.flatten(tops).filter(poly => !poly.marked);
if (flat.length === 0) return; if (flat.length === 0) return;
if (inside) { if (inside) {
flat = flat.filter(p => p.isNested(inside)); flat = flat.filter(p => p.isInside(inside));
} }
for (;;) { for (;;) {
@ -736,7 +742,13 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
polyEmit(poly, CLOSEST_TO_PP, engage); polyEmit(poly, CLOSEST_TO_PP, engage);
engage = false; engage = false;
} }
descend(stack.slice(1), poly); if (outline) {
output.forEach(poly => {
descend(stack.slice(1), poly);
});
} else {
descend(stack.slice(1), poly);
}
} else { } else {
return; return;
} }