more efficient shortest-distance pocket routing
This commit is contained in:
parent
ad53e78e7e
commit
f08319efe7
3 changed files with 40 additions and 9 deletions
|
|
@ -1800,7 +1800,7 @@ class Polygon {
|
||||||
* print paths.
|
* print paths.
|
||||||
*
|
*
|
||||||
* @param {Point} target
|
* @param {Point} target
|
||||||
* @return {Object} {point:point, distance:distance}
|
* @return {Object} {distance, point, index: point_index}
|
||||||
*/
|
*/
|
||||||
findClosestPointTo(target) {
|
findClosestPointTo(target) {
|
||||||
let dist,
|
let dist,
|
||||||
|
|
|
||||||
|
|
@ -1383,7 +1383,7 @@ class OpPocket extends CamOp {
|
||||||
|
|
||||||
prepare(ops, progress) {
|
prepare(ops, progress) {
|
||||||
let { op, state, pockets } = this;
|
let { op, state, pockets } = this;
|
||||||
let { setTool, setSpindle, setTolerance, sliceOutput } = ops;
|
let { setTool, setSpindle, setTolerance, sliceOutput, getPrintPoint } = ops;
|
||||||
let { process } = state.settings;
|
let { process } = state.settings;
|
||||||
|
|
||||||
setTool(op.tool, op.rate);
|
setTool(op.tool, op.rate);
|
||||||
|
|
@ -1393,13 +1393,37 @@ class OpPocket extends CamOp {
|
||||||
setTolerance(this.topo.tolerance);
|
setTolerance(this.topo.tolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let sliceOut of pockets) {
|
// eliminate empty pockets
|
||||||
sliceOutput(sliceOut, {
|
pockets = pockets.filter(p => p.length);
|
||||||
cutdir: process.camConventional,
|
|
||||||
depthFirst: process.camDepthFirst && !state.isIndexed,
|
// pockets is an [ array of an [ array of slices ] ]
|
||||||
easeDown: op.down && process.easeDown ? op.down : 0,
|
// each top level array is a pocket containing a [ z layer array of slices ]
|
||||||
progress: (n,m) => progress(n/m, "pocket")
|
// follow each pocket to the next closest one from previous exit
|
||||||
});
|
for (;;) {
|
||||||
|
let printPoint = getPrintPoint();
|
||||||
|
let min = {
|
||||||
|
dist: Infinity,
|
||||||
|
pocket: undefined
|
||||||
|
};
|
||||||
|
for (let pocket of pockets.filter(p => !p.used)) {
|
||||||
|
let poly = pocket[0].camLines.slice().sort((a,b) => b.area() - a.area())[0];
|
||||||
|
let find = poly.findClosestPointTo(printPoint);
|
||||||
|
if (find.distance < min.dist) {
|
||||||
|
min.pocket = pocket;
|
||||||
|
min.dist = find.distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (min.pocket) {
|
||||||
|
min.pocket.used = true;
|
||||||
|
sliceOutput(min.pocket, {
|
||||||
|
cutdir: process.camConventional,
|
||||||
|
depthFirst: process.camDepthFirst && !state.isIndexed,
|
||||||
|
easeDown: op.down && process.easeDown ? op.down : 0,
|
||||||
|
progress: (n,m) => progress(n/m, "pocket")
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -437,6 +437,12 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* output an array of slices that form a pocket
|
||||||
|
*
|
||||||
|
* @param {Slice[]} top-down Z stack of slices
|
||||||
|
* @param {*} opts
|
||||||
|
*/
|
||||||
function sliceOutput(sliceOut, opts = {}) {
|
function sliceOutput(sliceOut, opts = {}) {
|
||||||
const { cutdir, depthFirst, easeDown, progress } = opts;
|
const { cutdir, depthFirst, easeDown, progress } = opts;
|
||||||
|
|
||||||
|
|
@ -518,6 +524,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
setTolerance,
|
setTolerance,
|
||||||
setPrintPoint,
|
setPrintPoint,
|
||||||
setLasering,
|
setLasering,
|
||||||
|
getPrintPoint() { return printPoint },
|
||||||
printPoint,
|
printPoint,
|
||||||
newLayer,
|
newLayer,
|
||||||
addGCode,
|
addGCode,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue