Skip to content

Commit 3818f35

Browse files
authored
knockdown: add stitch length option (#4084)
1 parent 9626187 commit 3818f35

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/extensions/knockdown_fill.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Copyright (c) 2025 Authors
44
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
55

6+
from math import sqrt
7+
68
from inkex import Boolean, Path, PathElement
79
from shapely import minimum_bounding_circle, union_all
810
from shapely.geometry import LineString, Polygon
@@ -20,6 +22,7 @@ class KnockdownFill(InkstitchExtension):
2022
def __init__(self, *args, **kwargs):
2123
InkstitchExtension.__init__(self, *args, **kwargs)
2224
self.arg_parser.add_argument("--notebook")
25+
self.arg_parser.add_argument("-l", "--stitch-length", type=float, default=3, dest="stitch_length")
2326
self.arg_parser.add_argument("-k", "--keep-holes", type=Boolean, default=True, dest="keep_holes")
2427
self.arg_parser.add_argument("-o", "--offset", type=float, default=0, dest="offset")
2528
self.arg_parser.add_argument("-j", "--join-style", type=str, default="1", dest="join_style")
@@ -137,15 +140,19 @@ def _get_hole_paths(self, polygon):
137140
return d
138141

139142
def insert_path(self, d, transform, parent, index):
143+
stitch_length = self.options.stitch_length
144+
row_spacing = (sqrt(3) * stitch_length) / 2
145+
140146
path = PathElement()
141147
path.set('d', d)
142148
path.label = self.svg.get_unique_id('Knockdown ')
143149
path.set('transform', transform)
144150

145-
path.set('inkstitch:row_spacing_mm', '2.6')
151+
path.set('inkstitch:max_stitch_length_mm', stitch_length)
152+
path.set('inkstitch:row_spacing_mm', '{0:.4f}'.format(row_spacing))
146153
path.set('inkstitch:fill_underlay_angle', '60 -60')
147-
path.set('inkstitch:fill_underlay_max_stitch_length_mm', '3')
148-
path.set('inkstitch:fill_underlay_row_spacing_mm', '2.6')
154+
path.set('inkstitch:fill_underlay_max_stitch_length_mm', stitch_length)
155+
path.set('inkstitch:fill_underlay_row_spacing_mm', '{0:.4f}'.format(row_spacing))
149156
path.set('inkstitch:underlay_underpath', 'False')
150157
path.set('inkstitch:underpath', 'False')
151158
path.set('inkstitch:staggers', '2')

templates/knockdown_fill.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</effect>
1616
<param name="notebook" type="notebook">
1717
<page name="options" gui-text="Options">
18+
<param name="stitch-length" type="float" gui-text="Stitch length" min="0.1" max="50">3</param>
1819
<param name="keep-holes" type="bool" gui-text="Keep holes">true</param>
1920
<param name="offset" type="float" gui-text="Offset" min="-50" max="50">1</param>
2021
<param name="join-style" type="optiongroup" appearance="combo" gui-text="Join style">

0 commit comments

Comments
 (0)