Skip to content

Commit d153123

Browse files
committed
add flip direction option
1 parent c15bcb9 commit d153123

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lib/elements/fill_stitch.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,20 @@ def random_seed(self) -> str:
751751
def cross_coverage(self):
752752
return max(1, self.get_int_param("cross_coverage", 50))
753753

754+
@property
755+
@param(
756+
'flip_layers',
757+
_("Flip direction"),
758+
tooltip=_("Top stitches go from bottom left to top right by default. "
759+
"When enabled, top stitching goes from top left to bottom right."),
760+
type='boolean',
761+
default=False,
762+
select_items=[('fill_method', 'cross_stitch')],
763+
sort_index=63
764+
)
765+
def flip_layers(self):
766+
return self.get_boolean_param("flip_layers", False)
767+
754768
@property
755769
@cache
756770
def paths(self):

lib/stitches/cross_stitch.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,21 @@ def cross_stitch(fill, shape, starting_point, ending_point):
8989
# used for snapping
9090
center_points = MultiPoint(center_points)
9191

92+
travel_edges = list(ensure_multi_line_string(line_merge(MultiLineString(travel_edges))).geoms)
93+
9294
nodes = get_line_endpoints(rl)
9395
nodes.extend(get_line_endpoints(lr))
9496
nodes.extend(get_line_endpoints(v))
9597

9698
check_stop_flag()
9799

100+
if fill.flip_layers:
101+
rl, lr, crosses_rl, crosses_lr = lr, rl, crosses_lr, crosses_rl
102+
98103
starting_point, ending_point = get_start_and_end(
99104
fill.max_stitch_length, starting_point, ending_point, MultiLineString(crosses_lr), MultiLineString(crosses_rl)
100105
)
101106

102-
travel_edges = list(ensure_multi_line_string(line_merge(MultiLineString(travel_edges))).geoms)
103-
104107
stitches = _lines_to_stitches(
105108
lr, travel_edges, outline, stitch_length, fill.bean_stitch_repeats,
106109
starting_point, ending_point, nodes, center_points, clamp
@@ -277,10 +280,6 @@ def travel(shape, travel_graph, edge, center_points, stitch_length, clamp=True):
277280
pass
278281
else:
279282
line = LineString([last_point, point])
280-
if line.length < stitch_length / 2:
281-
stitches.append(Stitch(point, tags=["auto_fill_travel"]))
282-
last_point = point
283-
continue
284283
center = list(rotate(line, 90).coords)
285284
point1 = Point(center[0])
286285
if point1.within(shape):

lib/svg/tags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
'random_stitch_length_jitter_percent',
111111
'gap_fill_rows',
112112
'cross_coverage',
113+
'flip_layers',
113114
# stroke
114115
'stroke_method',
115116
'bean_stitch_repeats',

0 commit comments

Comments
 (0)