From d3eb573ae9412d3ce65b8259878f9b7abb9f08f2 Mon Sep 17 00:00:00 2001 From: thingsapart Date: Mon, 15 Jul 2024 17:34:12 -0700 Subject: [PATCH] Do not break down all long move segments, only those that would violate target Z --- src/geo/polygon.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 3c743529..4039ed6b 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -1162,7 +1162,17 @@ class Polygon { // When "in Ease-Down" (ie. while target Z not yet reached) - follow path while slowly decreasing Z. let deltaZ = fromZ - next.z; dist2next = last.distTo2D(next); - next = next.clone().setZ(fromZ - dist2next * slope); + let deltaZFullMove = dist2next * slope; + + if (deltaZFullMove > deltaZ) { + // Too long: easing along full path would overshoot depth, synth intermediate point at target Z. + // + // XXX: please check my super basic trig - this should follow from `last` to `next` up until the + // intersect at the target Z distance. + fn(last.followTo(next, dist2next * deltaZ / deltaZFullMove).setZ(next.z), offset++); + } else { + next = next.clone().setZ(fromZ - deltaZFullMove); + } fromZ = next.z; } else if (offset === 0 && next.z < fromZ) {