From 4efc780fc4cabc9853e77e5b0266beedc262a566 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sat, 4 Sep 2021 14:45:29 +0200 Subject: [PATCH] fix(core): Handle path.offset() for very short curves This path.offset method used to travel 2mm along the path to find out the direction at the start/end of paths. That caused errors when the curve being offsetted was less then 2mm. So now, it checks and if it's shorter will use 10% of the path length instead. This closes #1257 --- packages/core/src/path.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/src/path.js b/packages/core/src/path.js index 02e237c32da..f799ea51422 100644 --- a/packages/core/src/path.js +++ b/packages/core/src/path.js @@ -348,14 +348,20 @@ function pathOffset(path, distance, raise) { .withRaise(path.raise) .move(current) .curve(op.cp1, op.cp2, op.to) - .shiftAlong(2) + cp1 = cp1.shiftAlong(cp1.length() > 2 + ? 2 + : cp1.length()/10 + ) } else cp1 = op.cp1 if (op.cp2.sitsRoughlyOn(op.to)) { cp2 = new Path(path.debug) .withRaise(path.raise) .move(op.to) .curve(op.cp2, op.cp1, current) - .shiftAlong(2) + cp2 = cp2.shiftAlong(cp2.length() > 2 + ? 2 + : cp2.length()/10 + ) } else cp2 = op.cp2 let b = new Bezier( { x: current.x, y: current.y },