From e884fb78db288c91e8183ef8e242840ba5d68db2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Jun 2022 09:26:37 -0400 Subject: add running stitch tolerance param (#1701) --- lib/stitches/running_stitch.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/stitches/running_stitch.py') 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 -- cgit v1.2.3