Skip to content

Commit 9626187

Browse files
authored
Enable swap rail and reverse rail options for satin guide (#4083)
1 parent 4dc0be3 commit 9626187

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

lib/elements/stroke.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,19 @@ def reverse(self):
359359
def reverse_rails(self):
360360
return self.get_param('reverse_rails', 'automatic')
361361

362+
@property
363+
@param(
364+
'swap_satin_rails',
365+
_('Swap rails'),
366+
tooltip=_('Swaps the first and second rails of a satin ripple, '
367+
'affecting which side the thread finished on as well as any sided properties'),
368+
type='boolean',
369+
default='false',
370+
select_items=[('stroke_method', 'ripple_stitch')],
371+
sort_index=23)
372+
def swap_rails(self):
373+
return self.get_boolean_param('swap_satin_rails', False)
374+
362375
@property
363376
@param('grid_size_mm',
364377
_('Grid size'),
@@ -367,7 +380,7 @@ def reverse_rails(self):
367380
default=0,
368381
unit='mm',
369382
select_items=[('stroke_method', 'ripple_stitch')],
370-
sort_index=23)
383+
sort_index=24)
371384
@cache
372385
def grid_size(self):
373386
return abs(self.get_float_param("grid_size_mm", 0))
@@ -379,7 +392,7 @@ def grid_size(self):
379392
type='boolean',
380393
default=False,
381394
select_items=[('stroke_method', 'ripple_stitch')],
382-
sort_index=24)
395+
sort_index=25)
383396
@cache
384397
def grid_first(self):
385398
return self.get_boolean_param("grid_first", False)

lib/stitches/ripple_stitch.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ def _get_staggered_stitches(stroke, lines, skip_start):
252252
random_seed = stroke.random_seed
253253
last_point = None
254254
for i, line in enumerate(lines):
255+
if len(line) == 1:
256+
continue
255257
connector = []
256258
if i != 0 and stroke.join_style == 0:
257259
if i % 2 == 0 or not stroke.flip_copies:
@@ -270,21 +272,10 @@ def _get_staggered_stitches(stroke, lines, skip_start):
270272
line.reverse()
271273
stitched_line = running_stitch(line, stitch_length, tolerance, is_random, length_sigma, prng.join_args(random_seed, i))
272274
else:
273-
if len(stitch_length) > 1:
274-
points = list(
275-
apply_stagger(line, stitch_length, stroke.staggers, i, tolerance, is_random, length_sigma, prng.join_args(random_seed, i)).coords
276-
)
277-
else:
278-
# uses the guided fill alforithm to stagger rows of stitches
279-
points = list(apply_stitches(LineString(line), stitch_length, stroke.staggers, 0.5, i, tolerance).coords)
280-
281-
# simplifying the path in apply_stitches could have removed the start or end point
282-
# we can simply add it again, the minimum stitch length value will take care to remove possible duplicates
283-
points = [line[0]] + points + [line[-1]]
284-
285-
stitched_line = [InkstitchPoint(*point) for point in points]
286-
if should_reverse and stroke.flip_copies:
287-
stitched_line.reverse()
275+
stitched_line = _stagger_line(
276+
line, stitch_length, stroke.staggers, i, tolerance, is_random, length_sigma, prng.join_args(random_seed, i),
277+
should_reverse, stroke.flip_copies
278+
)
288279

289280
stitched_line = connector + stitched_line
290281

@@ -293,6 +284,25 @@ def _get_staggered_stitches(stroke, lines, skip_start):
293284
return stitches
294285

295286

287+
def _stagger_line(line, stitch_length, staggers, i, tolerance, is_random, length_sigma, random, should_reverse, flip_copies):
288+
if len(stitch_length) > 1:
289+
points = list(
290+
apply_stagger(line, stitch_length, staggers, i, tolerance, is_random, length_sigma, random).coords
291+
)
292+
else:
293+
# uses the guided fill alforithm to stagger rows of stitches
294+
points = list(apply_stitches(LineString(line), stitch_length, staggers, 0.5, i, tolerance).coords)
295+
296+
# simplifying the path in apply_stitches could have removed the start or end point
297+
# we can simply add it again, the minimum stitch length value will take care to remove possible duplicates
298+
points = [line[0]] + points + [line[-1]]
299+
300+
stitched_line = [InkstitchPoint(*point) for point in points]
301+
if should_reverse and flip_copies:
302+
stitched_line.reverse()
303+
return stitched_line
304+
305+
296306
def apply_stagger(line, stitch_length, num_staggers, row_num, tolerance, is_random, stitch_length_sigma, random_seed):
297307
if num_staggers == 0:
298308
num_staggers = 1 # sanity check to avoid division by zero.
@@ -591,6 +601,8 @@ def _get_start_rotation(line):
591601

592602
def generate_satin_guide_helper_lines(stroke, outline, guide_line):
593603
anchor_line = stroke.get_anchor_line()
604+
guide_line.node.set('inkstitch:reverse_rails', stroke.reverse_rails)
605+
guide_line.node.set('inkstitch:swap_satin_rails', stroke.swap_rails)
594606
if anchor_line:
595607
# position, rotation and scale defined by anchor line
596608
outline0 = InkstitchPoint(*anchor_line.coords[0])

0 commit comments

Comments
 (0)