summaryrefslogtreecommitdiff
path: root/lib/stitches/running_stitch.py
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2022-06-22 09:26:37 -0400
committerGitHub <noreply@github.com>2022-06-22 15:26:37 +0200
commite884fb78db288c91e8183ef8e242840ba5d68db2 (patch)
treedf835bd6fbd9070c390cd53c22578023d24b3321 /lib/stitches/running_stitch.py
parentb6bde000fe675ed725d7d5dbd7db3f44fb33af0e (diff)
add running stitch tolerance param (#1701)
Diffstat (limited to 'lib/stitches/running_stitch.py')
-rw-r--r--lib/stitches/running_stitch.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/stitches/running_stitch.py b/lib/stitches/running_stitch.py
index 98d080ba..8c86eb7c 100644
--- a/lib/stitches/running_stitch.py
+++ b/lib/stitches/running_stitch.py
@@ -3,16 +3,15 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-from ..debug import debug
import math
from copy import copy
+
from shapely.geometry import LineString
""" Utility functions to produce running stitches. """
-@debug.time
-def running_stitch(points, stitch_length):
+def running_stitch(points, stitch_length, tolerance):
"""Generate running stitch along a path.
Given a path and a stitch length, walk along the path in increments of the
@@ -28,9 +27,9 @@ def running_stitch(points, stitch_length):
return []
# simplify will remove as many points as possible while ensuring that the
- # resulting path stays within 0.75 pixels (0.2mm) of the original path.
+ # resulting path stays within the specified tolerance of the original path.
path = LineString(points)
- simplified = path.simplify(0.75, preserve_topology=False)
+ simplified = path.simplify(tolerance, preserve_topology=False)
# save the points that simplify picked and make sure we stitch them
important_points = set(simplified.coords)
@@ -50,7 +49,7 @@ def running_stitch(points, stitch_length):
section_length = section_ls.length
if section_length > stitch_length:
# a fractional stitch needs to be rounded up, which will make all
- # of the stitches shorter
+ # the stitches shorter
num_stitches = math.ceil(section_length / stitch_length)
actual_stitch_length = section_length / num_stitches