summaryrefslogtreecommitdiff
path: root/lib/stitches/auto_fill.py
diff options
context:
space:
mode:
authorGeorge Steel <george.steel@gmail.com>2024-05-05 13:55:33 -0400
committerGitHub <noreply@github.com>2024-05-05 13:55:33 -0400
commitd32a8fd4661331da0affb15623a2ec9a9eac5c44 (patch)
tree6ac6a11c099a5b6b5463c9ff46bc7fb87d6ba888 /lib/stitches/auto_fill.py
parentedbe382914bc45a3f953c6e0258ff1feb05d8c95 (diff)
Add randomized running and fill stitches (#2830)
Add a mode to running stitch that uses randomized phase and stitch length instead of even spacing. This greatly reduces moire effects when stitching closely-spaced curves in running-stitch-based fills. Add option for randomized running stitch to: ripple stitch circular fill contour fill guided fill auto-fill When is randomization is not selected, ripple stitch will use even running stitch when staggers are set to 0 (default) and the stagger algorithm from guided fill (which does not look nice with a stagger period of 0) when staggers is nonzero. Also includes fix for satin contour underlays (missing tolerance default) mentioned in #2814. This sets the default tolerance to 0.2mm, which is the largest tolerance guaranteed to be backwards-compatible with existing designs using the default inset of 0.4mm. Original commits: * fix satin underlay tolerance default * Add randomized running stitch, make available in ripple stitch, circular, and contour * add randomized guided fill * make ripple stitch use even stitching when not staggering or randomizing. * add random auto-fill and switch jitter parameter to a percentage (matches satin) * fix comments
Diffstat (limited to 'lib/stitches/auto_fill.py')
-rw-r--r--lib/stitches/auto_fill.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py
index e90093ce..159a869b 100644
--- a/lib/stitches/auto_fill.py
+++ b/lib/stitches/auto_fill.py
@@ -15,6 +15,7 @@ from shapely import segmentize
from shapely.ops import snap
from shapely.strtree import STRtree
+
from ..debug import debug
from ..stitch_plan import Stitch
from ..svg import PIXELS_PER_MM
@@ -25,8 +26,9 @@ from ..utils.geometry import (ensure_multi_line_string,
line_string_to_point_list)
from ..utils.smoothing import smooth_path
from ..utils.threading import check_stop_flag
+from ..utils.prng import join_args
from .fill import intersect_region_with_grating, stitch_row
-from .running_stitch import running_stitch
+from .running_stitch import even_running_stitch
class NoGratingsError(Exception):
@@ -77,7 +79,10 @@ def auto_fill(shape,
skip_last,
starting_point,
ending_point=None,
- underpath=True):
+ underpath=True,
+ enable_random=False,
+ random_sigma=0.0,
+ random_seed=""):
rows = intersect_region_with_grating(shape, angle, row_spacing, end_row_spacing)
if not rows:
# Small shapes may not intersect with the grating at all.
@@ -102,7 +107,7 @@ def auto_fill(shape,
path = find_stitch_path(fill_stitch_graph, travel_graph, starting_point, ending_point)
result = path_to_stitches(shape, path, travel_graph, fill_stitch_graph, angle, row_spacing,
max_stitch_length, running_stitch_length, running_stitch_tolerance,
- staggers, skip_last, underpath)
+ staggers, skip_last, underpath, enable_random, random_sigma, random_seed)
return result
@@ -335,7 +340,7 @@ def fallback(shape, running_stitch_length, running_stitch_tolerance):
boundary = ensure_multi_line_string(shape.boundary)
outline = boundary.geoms[0]
- return running_stitch(line_string_to_point_list(outline), running_stitch_length, running_stitch_tolerance)
+ return even_running_stitch(line_string_to_point_list(outline), running_stitch_length, running_stitch_tolerance)
@debug.time
@@ -694,7 +699,7 @@ def travel(shape, travel_graph, edge, running_stitch_length, running_stitch_tole
if len(path) > 1:
path = clamp_path_to_polygon(path, shape)
- points = running_stitch(path, running_stitch_length, running_stitch_tolerance)
+ points = even_running_stitch(path, running_stitch_length, running_stitch_tolerance)
stitches = [Stitch(point) for point in points]
for stitch in stitches:
@@ -718,7 +723,7 @@ def travel(shape, travel_graph, edge, running_stitch_length, running_stitch_tole
@debug.time
def path_to_stitches(shape, path, travel_graph, fill_stitch_graph, angle, row_spacing, max_stitch_length, running_stitch_length,
- running_stitch_tolerance, staggers, skip_last, underpath):
+ running_stitch_tolerance, staggers, skip_last, underpath, enable_random, random_sigma, random_seed):
path = collapse_sequential_outline_edges(path, fill_stitch_graph)
stitches = []
@@ -727,9 +732,10 @@ def path_to_stitches(shape, path, travel_graph, fill_stitch_graph, angle, row_sp
if not path[0].is_segment():
stitches.append(Stitch(*path[0].nodes[0]))
- for edge in path:
+ for i, edge in enumerate(path):
if edge.is_segment():
- stitch_row(stitches, edge[0], edge[1], angle, row_spacing, max_stitch_length, staggers, skip_last)
+ stitch_row(stitches, edge[0], edge[1], angle, row_spacing, max_stitch_length, staggers, skip_last,
+ enable_random, random_sigma, join_args(random_seed, i))
travel_graph.remove_edges_from(fill_stitch_graph[edge[0]][edge[1]]['segment'].get('underpath_edges', []))
else:
stitches.extend(travel(shape, travel_graph, edge, running_stitch_length, running_stitch_tolerance, skip_last, underpath))