summaryrefslogtreecommitdiff
path: root/lib/stitches
diff options
context:
space:
mode:
authorGeorge Steel <george.steel@gmail.com>2022-10-23 00:54:35 -0400
committerGeorge Steel <george.steel@gmail.com>2022-10-23 00:54:35 -0400
commit1cc0eab91189227371c5bb78d9e1f1f06deaeaf5 (patch)
tree3ad5b2159192f6cc9d3fe9fb1ea31858e9543703 /lib/stitches
parent11cde9062ee13b64f665b0ef9313c286da05fdfe (diff)
Add support for fractional-length stagger cycles in fills.
Diffstat (limited to 'lib/stitches')
-rw-r--r--lib/stitches/fill.py6
-rw-r--r--lib/stitches/guided_fill.py4
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/stitches/fill.py b/lib/stitches/fill.py
index 7c07b5c2..ed4ff655 100644
--- a/lib/stitches/fill.py
+++ b/lib/stitches/fill.py
@@ -37,9 +37,11 @@ def row_num(point, angle, row_spacing):
def adjust_stagger(stitch, angle, row_spacing, max_stitch_length, staggers):
+ if staggers == 0:
+ staggers = 1 # sanity check to avoid division by zero.
this_row_num = row_num(stitch, angle, row_spacing)
- row_stagger = this_row_num % staggers
- stagger_offset = (float(row_stagger) / staggers) * max_stitch_length
+ stagger_phase = (this_row_num / staggers) % 1
+ stagger_offset = stagger_phase * max_stitch_length
offset = ((stitch * east(angle)) - stagger_offset) % max_stitch_length
return stitch - offset * east(angle)
diff --git a/lib/stitches/guided_fill.py b/lib/stitches/guided_fill.py
index 05de14cd..6a92f8e8 100644
--- a/lib/stitches/guided_fill.py
+++ b/lib/stitches/guided_fill.py
@@ -148,7 +148,9 @@ def take_only_line_strings(thing):
def apply_stitches(line, max_stitch_length, num_staggers, row_spacing, row_num):
- start = (float(row_num % num_staggers) / num_staggers) * max_stitch_length
+ if num_staggers == 0:
+ num_staggers = 1 # sanity check to avoid division by zero.
+ start = ((row_num / num_staggers) % 1) * max_stitch_length
projections = np.arange(start, line.length, max_stitch_length)
points = np.array([line.interpolate(projection).coords[0] for projection in projections])
stitched_line = shgeo.LineString(points)