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/guided_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/guided_fill.py')
| -rw-r--r-- | lib/stitches/guided_fill.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/stitches/guided_fill.py b/lib/stitches/guided_fill.py index bc7a3ab2..1b564bcb 100644 --- a/lib/stitches/guided_fill.py +++ b/lib/stitches/guided_fill.py @@ -8,12 +8,15 @@ from shapely import geometry as shgeo from shapely.affinity import translate from shapely.ops import linemerge, nearest_points, unary_union +from lib.utils import prng + from ..debug import debug from ..stitch_plan import Stitch from ..utils.geometry import Point as InkstitchPoint from ..utils.geometry import (ensure_geometry_collection, ensure_multi_line_string, reverse_line_string) from ..utils.threading import check_stop_flag +from .running_stitch import random_running_stitch from .auto_fill import (auto_fill, build_fill_stitch_graph, build_travel_graph, collapse_sequential_outline_edges, find_stitch_path, graph_make_valid, travel) @@ -31,9 +34,13 @@ def guided_fill(shape, starting_point, ending_point, underpath, - strategy + strategy, + enable_random, + random_sigma, + random_seed, ): - segments = intersect_region_with_grating_guideline(shape, guideline, row_spacing, num_staggers, max_stitch_length, strategy) + segments = intersect_region_with_grating_guideline(shape, guideline, row_spacing, num_staggers, max_stitch_length, strategy, + enable_random, running_stitch_tolerance, random_sigma, random_seed,) if not segments: return fallback(shape, guideline, row_spacing, max_stitch_length, running_stitch_length, running_stitch_tolerance, num_staggers, skip_last, starting_point, ending_point, underpath) @@ -231,7 +238,8 @@ def _get_start_row(line, shape, row_spacing, line_direction): return copysign(row, shape_direction * line_direction) -def intersect_region_with_grating_guideline(shape, line, row_spacing, num_staggers, max_stitch_length, strategy): +def intersect_region_with_grating_guideline(shape, line, row_spacing, num_staggers, max_stitch_length, strategy, + enable_random, tolerance, random_sigma, random_seed): line = prepare_guide_line(line, shape) debug.log_line_string(shape.exterior, "guided fill shape") @@ -261,13 +269,14 @@ def intersect_region_with_grating_guideline(shape, line, row_spacing, num_stagge offset_line = clean_offset_line(offset_line) - if strategy == 1 and direction == -1: - # negative parallel offsets are reversed, so we need to compensate - offset_line = reverse_line_string(offset_line) - debug.log_line_string(offset_line, f"offset {row}") - stitched_line = apply_stitches(offset_line, max_stitch_length, num_staggers, row_spacing, row) + if enable_random: + points = [InkstitchPoint(*x) for x in offset_line.coords] + stitched_line = shgeo.LineString(random_running_stitch( + points, max_stitch_length, tolerance, random_sigma, prng.join_args(random_seed, row))) + else: + stitched_line = apply_stitches(offset_line, max_stitch_length, num_staggers, row_spacing, row) intersection = shape.intersection(stitched_line) if not intersection.is_empty and shape_envelope.intersects(stitched_line): |
