clamp single trace to z top/bottom

This commit is contained in:
Stewart Allen 2025-12-07 22:11:04 -05:00
commit 8bca0a949a
2 changed files with 16 additions and 2 deletions

View file

@ -207,7 +207,7 @@ class OpArea extends CamOp {
} else
if (mode === 'trace') {
let { tr_type } = op;
let zs = down ? base_util.lerp(zTop, bounds.min.z, down) : [ bounds.min.z ];
let zs = down ? base_util.lerp(zTop, zBottom, down) : [ bounds.min.z ];
let zroc = 0;
let zinc = 1 / zs.length;
for (let z of zs) {
@ -217,7 +217,7 @@ class OpArea extends CamOp {
if (tr_type === 'none') {
// todo: move this out of the zs loop and only setZ when needed
area = area.clone(true);
outs = [ zs.length > 1 ? area.setZ(z) : area ];
outs = [ zs.length > 1 ? area.setZ(z) : clampZ(area, zTop, zBottom) ];
} else {
// todo: move this out of the zs loop
POLY.offset([ area ], tr_type === 'inside' ? [ -toolDiam / 2 ] : [ toolDiam / 2 ], {
@ -396,6 +396,19 @@ class OpArea extends CamOp {
}
}
function clampZ(poly, min, max) {
for (let p of poly.points) {
if (p.z < min) p.z = min;
else if (p.z > max) p.z = max;
}
if (poly.inner) {
for (let poly of poly.inner) {
clampZ(poly, min, max);
}
}
return poly;
}
// box2: THREE.Box2
// angle: radians (direction of each scan ray)
// step: spacing between parallel rays (world units)

View file

@ -454,6 +454,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
if (isMove && deltaXY <= shortCut && deltaZ <= 0 && !lasering) {
// but only if the z plunge is not too far
if (absDeltaZ < 0.01 || (tolerance > 0 && absDeltaZ <= tolerance)) {
if (debug) console.log('shortcut', { deltaXY, deltaZ, shortCut });
emit = 1;
} else
// otherwise move over before descending