From c030e3283530bc1d0f4bad219f4c61db22750506 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:51:43 +0200 Subject: Fix short relative lock stitches (#2998) --- lib/stitch_plan/lock_stitch.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'lib/stitch_plan') diff --git a/lib/stitch_plan/lock_stitch.py b/lib/stitch_plan/lock_stitch.py index e05764de..1a8923af 100644 --- a/lib/stitch_plan/lock_stitch.py +++ b/lib/stitch_plan/lock_stitch.py @@ -85,25 +85,20 @@ class RelativeLock(LockStitchDefinition): to_previous = stitches[1] - stitches[0] length = to_previous.length() - lock_stitches = [] - if length > 0.5 * PIXELS_PER_MM: + # travel at least 0.5 and at most 1.5 + length = max(length, 0.5 * PIXELS_PER_MM) + length = min(length, 1.5 * PIXELS_PER_MM) - # Travel back one stitch, stopping halfway there. - # Then go forward one stitch, stopping halfway between - # again. + direction = to_previous.unit() - # but travel at most 1.5 mm - length = min(length, 1.5 * PIXELS_PER_MM) + # Travel back one stitch, stopping halfway there. + # Then go forward one stitch, stopping halfway between + # again. - direction = to_previous.unit() + lock_stitches = [] + for delta in path: + lock_stitches.append(Stitch(stitches[0] + delta * length * direction, tags=('lock_stitch',))) - for delta in path: - lock_stitches.append(Stitch(stitches[0] + delta * length * direction, tags=('lock_stitch',))) - else: - # Too short to travel part of the way to the previous stitch; just go - # back and forth to it a couple times. - for i in (1, 0, 1, 0): - lock_stitches.append(stitches[i]) return lock_stitches -- cgit v1.2.3