beautify small bit of code

This commit is contained in:
Stewart Allen 2022-10-15 20:18:24 -04:00
commit 357e851f95
2 changed files with 25 additions and 15 deletions

View file

@ -329,6 +329,7 @@ function pointsToPath(points, offset, open, miter = 1.5) {
normals.push(-rn.dx, -rn.dy, zn); normals.push(-rn.dx, -rn.dy, zn);
normals.push(ln.dx, ln.dy, zn); normals.push(ln.dx, ln.dy, zn);
} }
return { left, right, faces, normals, open }; return { left, right, faces, normals, open };
} }

View file

@ -198,11 +198,14 @@ function path(levels, update, opts = {}) {
} }
lastOut = out; lastOut = out;
}); });
lastEnd = lastOut;
// all moves with an emit at the very end (common in contouring) // all moves with an emit at the very end (common in contouring)
if (lastOut.emit && !emits) { if (lastOut.emit && !emits) {
pushPrint(lastOut.tool, current) pushPrint(lastOut.tool, current)
} }
lastEnd = lastOut;
if (changes.length) { if (changes.length) {
output output
.setLayer('tool', { line: 0x000055, face: 0x0000ff, opacity: 0.5 }, true) .setLayer('tool', { line: 0x000055, face: 0x0000ff, opacity: 0.5 }, true)
@ -210,6 +213,7 @@ function path(levels, update, opts = {}) {
return newPolygon().centerCircle(point, 0.2, 4).setZ(point.z + 0.03); return newPolygon().centerCircle(point, 0.2, 4).setZ(point.z + 0.03);
}), { outline: true }); }), { outline: true });
} }
if (retracts.length) { if (retracts.length) {
output output
.setLayer('retract', { line: 0x550000, face: 0xff0000, opacity: 0.5 }, true) .setLayer('retract', { line: 0x550000, face: 0xff0000, opacity: 0.5 }, true)
@ -217,6 +221,7 @@ function path(levels, update, opts = {}) {
return newPolygon().centerCircle(point, 0.2, 5).setZ(point.z + 0.01); return newPolygon().centerCircle(point, 0.2, 5).setZ(point.z + 0.01);
}), { outline: true }); }), { outline: true });
} }
if (engages.length) { if (engages.length) {
output output
.setLayer('engage', { line: 0x005500, face: 0x00ff00, opacity: 0.5 }, true) .setLayer('engage', { line: 0x005500, face: 0x00ff00, opacity: 0.5 }, true)
@ -224,6 +229,7 @@ function path(levels, update, opts = {}) {
return newPolygon().centerCircle(point, 0.2, 7).setZ(point.z + 0.02); return newPolygon().centerCircle(point, 0.2, 7).setZ(point.z + 0.02);
}), { outline: true }); }), { outline: true });
} }
if (thin && heads.length) { if (thin && heads.length) {
let line = dark ? 0xffffff : 0x112233; let line = dark ? 0xffffff : 0x112233;
output output
@ -238,30 +244,33 @@ function path(levels, update, opts = {}) {
return newPolygon().addPoints([p2,p3,p4]).setZ(p2.z + 0.01); return newPolygon().addPoints([p2,p3,p4]).setZ(p2.z + 0.01);
}), { thin: true, outline: true }); }), { thin: true, outline: true });
} }
// always add moves
output output
.setLayer(opts.other || 'move', moveOpt, opts.moves !== true) .setLayer(opts.other || 'move', moveOpt, opts.moves !== true)
.addPolys(moves, { thin: true, z: opts.z }); .addPolys(moves, { thin: true, z: opts.z });
// force level when present // force level when present
let pz = level.z ? level.z - height : opts.z; let pz = level.z ? level.z - height : opts.z;
Object.values(prints).forEach(array => { for (let array of Object.values(prints)) {
array.forEach(poly => { for (let poly of array) {
if (flat && poly.appearsClosed()) { if (flat && poly.appearsClosed()) {
poly.setClosed(); poly.setClosed();
poly.points.pop(); poly.points.pop();
} }
output output
.setLayer(opts.action || 'print', printOpt) .setLayer(opts.action || 'print', printOpt)
.addPolys([ poly ], .addPolys([ poly ],
thin ? { thin, z: opts.z, color: poly.color } : thin ? { thin, z: opts.z, color: poly.color } :
flat ? { flat ? {
flat, z: pz, color: poly.color, flat, z: pz, color: poly.color,
outline: true, offset: array.width, open: poly.open } : outline: true, offset: array.width, open: poly.open } :
{ {
offset: array.width, height, z: pz, offset: array.width, height, z: pz,
color: { face: poly.color, line: poly.color } color: { face: poly.color, line: poly.color }
}) })
}); }
}); }
update(index / levels.length, output); update(index / levels.length, output);
}); });