new depth-first strategy for roughing

This commit is contained in:
Stewart Allen 2020-11-05 21:11:07 -05:00
commit c4a04629e2
2 changed files with 70 additions and 52 deletions

View file

@ -18,28 +18,28 @@
newPoint = BASE.newPoint; newPoint = BASE.newPoint;
BASE.polygons = { BASE.polygons = {
rayIntersect : rayIntersect, rayIntersect,
alignWindings : alignWindings, alignWindings,
setWinding : setWinding, setWinding,
fillArea : fillArea, fillArea,
subtract : subtract, subtract,
flatten : flatten, flatten,
offset : offset, offset,
trimTo : trimTo, trimTo,
expand : expand, expand,
expand_lines: expand_lines, expand_lines,
union : union, union,
nest : nest, nest,
diff : doDiff, diff,
setZ : setZ, setZ,
filter : filter, filter,
toClipper : toClipper, toClipper,
fromClipperNode : fromClipperNode, fromClipperNode,
fromClipperTree : fromClipperTree, fromClipperTree,
fromClipperTreeUnion: fromClipperTreeUnion, fromClipperTreeUnion,
cleanClipperTree : cleanClipperTree, cleanClipperTree,
fingerprintCompare: fingerprintCompare, fingerprintCompare,
fingerprint: fingerprint fingerprint
}; };
/** ****************************************************************** /** ******************************************************************
@ -376,7 +376,7 @@
* @param {Polygon} poly clipping mask * @param {Polygon} poly clipping mask
* @returns {?Polygon[]} * @returns {?Polygon[]}
*/ */
function doDiff(setA, setB, z) { function diff(setA, setB, z) {
let clib = self.ClipperLib, let clib = self.ClipperLib,
ctyp = clib.ClipType, ctyp = clib.ClipType,
ptyp = clib.PolyType, ptyp = clib.PolyType,

View file

@ -417,6 +417,49 @@
update(sliceIndex / slices.length); update(sliceIndex / slices.length);
}); });
function polyEmit(poly, index, count, fromPoint) {
let last = null;
if (easeDown && poly.isClosed()) {
last = poly.forEachPointEaseDown(function(point, offset) {
camOut(point.clone(), offset > 0);
}, fromPoint);
} else {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
}, poly.isClosed(), index);
}
newLayer();
return last;
}
function polyLevelEmitter(start, depth, levels, tops, emitter, fit) {
let level = levels[depth];
if (!level) {
return start;
}
let ltops = tops[depth];
let fitted = fit ? ltops.filter(poly => poly.isInside(fit)) : ltops;
fitted.forEach(top => {
let inside = level.filter(poly => poly.isInside(top));
start = poly2polyEmit(inside, start, emitter);
start = polyLevelEmitter(start, depth + 1, levels, tops, emitter, top);
});
return start;
}
function polyArrayEmitter(levels, printPoint, emitter, info, fit) {
let tops = levels.map(level => {
return POLY.nest(level.filter(poly => poly.depth === 0).clone());
});
// start with the smallest polygon on the top
// printPoint = levels[0]
// .filter(p => p.depth)
// .sort((a,b) => { return a.area() - b.area() })
// .shift()
// .average();
return polyLevelEmitter(printPoint, 0, levels, tops, emitter);
}
// act on accumulated layer data // act on accumulated layer data
if (depthFirst) { if (depthFirst) {
// roughing depth first // roughing depth first
@ -424,41 +467,16 @@
lastMode = PRO.ROUGH; lastMode = PRO.ROUGH;
setTool(process.camRoughTool, process.camRoughSpeed, process.camRoughPlunge); setTool(process.camRoughTool, process.camRoughSpeed, process.camRoughPlunge);
spindle = Math.min(spindleMax, process.camRoughSpindle); spindle = Math.min(spindleMax, process.camRoughSpindle);
printPoint = poly2polyDepthFirstEmit(depthData.rough, printPoint, function(poly, index, count, fromPoint) { printPoint = polyArrayEmitter(depthData.rough, printPoint, polyEmit);
let last = null;
if (easeDown && poly.isClosed()) {
last = poly.forEachPointEaseDown(function(point, offset) {
camOut(point.clone(), offset > 0);
}, fromPoint);
} else {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
}, poly.isClosed(), index);
}
newLayer();
return last;
}, depthData.roughDiam * process.camRoughOver * 1.01);
} }
// outline depth first // outline depth first
if (depthData.outline.length > 0) { if (depthData.outline.length > 0) {
lastMode = PRO.OUTLINE; lastMode = PRO.OUTLINE;
setTool(process.camOutlineTool, process.camOutlineSpeed, process.camOutlinePlunge); setTool(process.camOutlineTool, process.camOutlineSpeed, process.camOutlinePlunge);
spindle = Math.min(spindleMax, process.camOutlineSpindle); spindle = Math.min(spindleMax, process.camOutlineSpindle);
printPoint = poly2polyDepthFirstEmit(depthData.outline, printPoint, function(poly, index, count, fromPoint) { printPoint = poly2polyDepthFirstEmit(
let last = null; depthData.outline, printPoint, polyEmit,
if (easeDown && poly.isClosed()) { depthData.outlineDiam * 0.01);
last = poly.forEachPointEaseDown(function(point, offset) {
camOut(point.clone(), offset > 0);
}, fromPoint);
} else {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
last = point;
}, poly.isClosed(), index);
}
newLayer();
return last;
}, depthData.outlineDiam * 0.01);
} }
// two modes for deferred outlining: x then y or combined // two modes for deferred outlining: x then y or combined
if (process.camContourCurves) { if (process.camContourCurves) {