diff options
| author | George Steel <george.steel@gmail.com> | 2024-05-05 13:55:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-05 13:55:33 -0400 |
| commit | d32a8fd4661331da0affb15623a2ec9a9eac5c44 (patch) | |
| tree | 6ac6a11c099a5b6b5463c9ff46bc7fb87d6ba888 /lib/stitches/circular_fill.py | |
| parent | edbe382914bc45a3f953c6e0258ff1feb05d8c95 (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/circular_fill.py')
| -rw-r--r-- | lib/stitches/circular_fill.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/lib/stitches/circular_fill.py b/lib/stitches/circular_fill.py index 28346dd9..11fd0432 100644 --- a/lib/stitches/circular_fill.py +++ b/lib/stitches/circular_fill.py @@ -2,13 +2,15 @@ from networkx import is_empty from shapely import geometry as shgeo from shapely.ops import substring +from lib.utils import prng + from ..stitch_plan import Stitch -from ..utils.geometry import reverse_line_string +from ..utils.geometry import Point, reverse_line_string from .auto_fill import (build_fill_stitch_graph, build_travel_graph, collapse_sequential_outline_edges, fallback, find_stitch_path, graph_make_valid, travel) from .contour_fill import _make_fermat_spiral -from .running_stitch import bean_stitch, running_stitch +from .running_stitch import bean_stitch, even_running_stitch, running_stitch def circular_fill(shape, @@ -24,7 +26,10 @@ def circular_fill(shape, starting_point, ending_point, underpath, - target + target, + use_random, + running_stitch_length_jitter, + random_seed, ): # get furthest distance of the target point to a shape border @@ -35,8 +40,8 @@ def circular_fill(shape, if radius > distance: # if the shape is smaller than row_spacing, return a simple circle in the size of row_spacing - stitches = running_stitch([Stitch(*point) for point in center.buffer(radius).exterior.coords], - running_stitch_length, running_stitch_tolerance) + stitches = even_running_stitch([Stitch(*point) for point in center.buffer(radius).exterior.coords], + running_stitch_length, running_stitch_tolerance) return _apply_bean_stitch_and_repeats(stitches, repeats, bean_stitch_repeats) circles = [] @@ -61,16 +66,24 @@ def circular_fill(shape, # if we get a single linestrig (original shape is a circle), apply start and end commands and return path path = list(intersection.coords) path = _apply_start_end_commands(shape, path, starting_point, ending_point) - stitches = running_stitch([Stitch(*point) for point in path], running_stitch_length, running_stitch_tolerance) + stitches = running_stitch([Stitch(*point) for point in path], + running_stitch_length, + running_stitch_tolerance, + use_random, + running_stitch_length_jitter, + random_seed) return _apply_bean_stitch_and_repeats(stitches, repeats, bean_stitch_repeats) segments = [] - for line in intersection.geoms: + for n, line in enumerate(intersection.geoms): if isinstance(line, shgeo.LineString): # use running stitch here to adjust the stitch length - coords = running_stitch([Stitch(point[0], point[1]) for point in line.coords], + coords = running_stitch([Point(*point) for point in line.coords], running_stitch_length, - running_stitch_tolerance) + running_stitch_tolerance, + use_random, + running_stitch_length_jitter, + prng.join_args(random_seed, n)) segments.append([(point.x, point.y) for point in coords]) fill_stitch_graph = build_fill_stitch_graph(shape, segments, starting_point, ending_point) |
