| 
									
										
										
										
											2021-03-12 04:17:19 +00:00
										 |  |  | # Authors: see git history | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Copyright (c) 2010 Authors | 
					
						
							|  |  |  | # Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details. | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  | import itertools | 
					
						
							| 
									
										
										
										
											2022-12-27 01:42:13 +00:00
										 |  |  | import typing | 
					
						
							| 
									
										
										
										
											2023-02-27 15:05:52 +00:00
										 |  |  | from copy import deepcopy | 
					
						
							|  |  |  | from itertools import chain | 
					
						
							| 
									
										
										
										
											2018-12-19 01:31:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  | import numpy as np | 
					
						
							| 
									
										
										
										
											2022-11-06 16:03:47 +00:00
										 |  |  | from inkex import paths | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  | from shapely import affinity as shaffinity | 
					
						
							|  |  |  | from shapely import geometry as shgeo | 
					
						
							| 
									
										
										
										
											2021-04-13 15:22:37 +00:00
										 |  |  | from shapely.ops import nearest_points | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-02 01:21:07 +00:00
										 |  |  | from ..i18n import _ | 
					
						
							| 
									
										
										
										
											2021-08-07 15:21:13 +00:00
										 |  |  | from ..stitch_plan import StitchGroup | 
					
						
							| 
									
										
										
										
											2023-02-27 15:05:52 +00:00
										 |  |  | from ..stitches import running_stitch | 
					
						
							| 
									
										
										
										
											2021-06-30 12:12:27 +00:00
										 |  |  | from ..svg import line_strings_to_csp, point_lists_to_csp | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  | from ..utils import Point, cache, cut, cut_multiple, prng | 
					
						
							| 
									
										
										
										
											2023-02-27 15:05:52 +00:00
										 |  |  | from .element import PIXELS_PER_MM, EmbroideryElement, param | 
					
						
							| 
									
										
										
										
											2022-04-24 06:27:42 +00:00
										 |  |  | from .validation import ValidationError, ValidationWarning | 
					
						
							| 
									
										
										
										
											2023-02-06 03:33:38 +00:00
										 |  |  | from ..utils.threading import check_stop_flag | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TooFewPathsError(ValidationError): | 
					
						
							|  |  |  |     name = _("Too few subpaths") | 
					
						
							|  |  |  |     description = _("Satin column: Object has too few subpaths.  A satin column should have at least two subpaths (the rails).") | 
					
						
							|  |  |  |     steps_to_solve = [ | 
					
						
							|  |  |  |         _("* Add another subpath (select two rails and do Path > Combine)"), | 
					
						
							|  |  |  |         _("* Convert to running stitch or simple satin (Params extension)") | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 06:27:42 +00:00
										 |  |  | class NotStitchableError(ValidationError): | 
					
						
							|  |  |  |     name = _("Not stitchable satin column") | 
					
						
							|  |  |  |     description = _("A satin column consists out of two rails and one or more rungs. This satin column may have a different setup.") | 
					
						
							|  |  |  |     steps_to_solve = [ | 
					
						
							|  |  |  |         _('Make sure your satin column is not a combination of multiple satin columns.'), | 
					
						
							|  |  |  |         _('Go to our website and read how a satin column should look like https://inkstitch.org/docs/stitches/satin-column/'), | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  | rung_message = _("Each rung should intersect both rails once.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 17:57:55 +00:00
										 |  |  | class TooManyIntersectionsError(ValidationError): | 
					
						
							|  |  |  |     name = _("Rungs intersects too many times") | 
					
						
							|  |  |  |     description = _("Satin column: A rung intersects a rail more than once.") + " " + rung_message | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-13 15:22:37 +00:00
										 |  |  | class DanglingRungWarning(ValidationWarning): | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |     name = _("Rung doesn't intersect rails") | 
					
						
							|  |  |  |     description = _("Satin column: A rung doesn't intersect both rails.") + " " + rung_message | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 17:57:55 +00:00
										 |  |  | class UnequalPointsWarning(ValidationError): | 
					
						
							|  |  |  |     name = _("Unequal number of points") | 
					
						
							|  |  |  |     description = _("Satin column: There are no rungs and rails have an an unequal number of points.") | 
					
						
							|  |  |  |     steps_to_solve = [ | 
					
						
							|  |  |  |         _('The easiest way to solve this issue is to add one or more rungs. '), | 
					
						
							|  |  |  |         _('Rungs control the stitch direction in satin columns.'), | 
					
						
							|  |  |  |         _('* With the selected object press "P" to activate the pencil tool.'), | 
					
						
							|  |  |  |         _('* Hold "Shift" while drawing the rung.') | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SatinColumn(EmbroideryElement): | 
					
						
							|  |  |  |     element_name = _("Satin Column") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, *args, **kwargs): | 
					
						
							|  |  |  |         super(SatinColumn, self).__init__(*args, **kwargs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('satin_column', _('Custom satin column'), type='toggle') | 
					
						
							|  |  |  |     def satin_column(self): | 
					
						
							|  |  |  |         return self.get_boolean_param("satin_column") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  |     # I18N: "E" stitch is so named because it looks like the letter E. | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('e_stitch', _('"E" stitch'), type='boolean', default='false') | 
					
						
							|  |  |  |     def e_stitch(self): | 
					
						
							|  |  |  |         return self.get_boolean_param("e_stitch") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 18:04:39 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('max_stitch_length_mm', | 
					
						
							|  |  |  |            _('Maximum stitch length'), | 
					
						
							|  |  |  |            tooltip=_('Maximum stitch length for split stitches.'), | 
					
						
							| 
									
										
										
										
											2021-06-29 18:42:16 +00:00
										 |  |  |            type='float', unit="mm") | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |     def max_stitch_length_px(self): | 
					
						
							| 
									
										
										
										
											2021-06-29 18:42:16 +00:00
										 |  |  |         return self.get_float_param("max_stitch_length_mm") or None | 
					
						
							| 
									
										
										
										
											2021-06-22 18:04:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-06 16:03:47 +00:00
										 |  |  |     @property | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  |     @param('random_width_decrease_percent', | 
					
						
							|  |  |  |            _('Random percentage of satin width decrease'), | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |            tooltip=_('shorten stitch across rails at most this percent. ' | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  |                      'Two values separated by a space may be used for an aysmmetric effect.'), | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |            default=0, type='float', unit="% (each side)", sort_index=91) | 
					
						
							|  |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |     def random_width_decrease(self): | 
					
						
							|  |  |  |         return self.get_split_float_param("random_width_decrease_percent", (0, 0)) / 100 | 
					
						
							| 
									
										
										
										
											2022-11-06 16:03:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  |     @param('random_width_increase_percent', | 
					
						
							|  |  |  |            _('Random percentage of satin width increase'), | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |            tooltip=_('lengthen stitch across rails at most this percent. ' | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  |                      'Two values separated by a space may be used for an aysmmetric effect.'), | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |            default=0, type='float', unit="% (each side)", sort_index=90) | 
					
						
							|  |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |     def random_width_increase(self): | 
					
						
							|  |  |  |         return self.get_split_float_param("random_width_increase_percent", (0, 0)) / 100 | 
					
						
							| 
									
										
										
										
											2022-11-06 16:03:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |     @property | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |     @param('random_zigzag_spacing_percent', | 
					
						
							| 
									
										
										
										
											2022-12-29 00:38:55 +00:00
										 |  |  |            _('Random zig-zag spacing percentage'), | 
					
						
							| 
									
										
										
										
											2023-01-08 00:32:29 +00:00
										 |  |  |            tooltip=_('Amount of random jitter added to stitch length.'), | 
					
						
							| 
									
										
										
										
											2022-12-29 00:38:55 +00:00
										 |  |  |            default=0, type='float', unit="± %", sort_index=92) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |     def random_zigzag_spacing(self): | 
					
						
							|  |  |  |         # peak-to-peak distance between zigzags | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |         return max(self.get_float_param("random_zigzag_spacing_percent", 0), 0) / 100 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('random_split_phase', | 
					
						
							|  |  |  |            _('Random phase for split stitches'), | 
					
						
							|  |  |  |            tooltip=_('Controls whether split stitches are centered or with a random phase (which may increase stitch count).'), | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |            default=False, type='boolean', sort_index=96) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |     def random_split_phase(self): | 
					
						
							|  |  |  |         return self.get_boolean_param('random_split_phase') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('min_random_split_length_mm', | 
					
						
							|  |  |  |            _('Minimum length for random-phase split.'), | 
					
						
							|  |  |  |            tooltip=_('Defaults to maximum stitch length. Smaller values allow for a transition between single-stitch and split-stitch.'), | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |            default='', type='float', unit='mm', sort_index=97) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |     def min_random_split_length_px(self): | 
					
						
							|  |  |  |         if self.max_stitch_length_px is None: | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  |         return min(self.max_stitch_length_px, self.get_float_param('min_random_split_length_mm', self.max_stitch_length_px)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |     @param('random_split_jitter_percent', | 
					
						
							|  |  |  |            _('Random jitter for split stitches'), | 
					
						
							|  |  |  |            tooltip=_('Randomizes split stitch length if random phase is enabled, stitch position if disabled.'), | 
					
						
							| 
									
										
										
										
											2022-12-29 00:38:55 +00:00
										 |  |  |            default=0, type='float', unit="± %", sort_index=95) | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |     def random_split_jitter(self): | 
					
						
							|  |  |  |         return min(max(self.get_float_param("random_split_jitter_percent", 0), 0), 100) / 100 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('short_stitch_inset', | 
					
						
							|  |  |  |            _('Short stitch inset'), | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |            tooltip=_('Stitches in areas with high density will be inset by this amount.'), | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  |            type='float', unit="%", | 
					
						
							|  |  |  |            default=15) | 
					
						
							|  |  |  |     def short_stitch_inset(self): | 
					
						
							|  |  |  |         return self.get_float_param("short_stitch_inset", 15) / 100 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('short_stitch_distance_mm', | 
					
						
							|  |  |  |            _('Short stitch distance'), | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |            tooltip=_('Inset stitches if the distance between stitches is smaller than this.'), | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  |            type='float', unit="mm", | 
					
						
							|  |  |  |            default=0.25) | 
					
						
							|  |  |  |     def short_stitch_distance(self): | 
					
						
							|  |  |  |         return self.get_float_param("short_stitch_distance_mm", 0.25) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     def color(self): | 
					
						
							|  |  |  |         return self.get_style("stroke") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							| 
									
										
										
										
											2018-08-09 18:32:41 +00:00
										 |  |  |     @param('zigzag_spacing_mm', | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |            _('Zig-zag spacing (peak-to-peak)'), | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |            tooltip=_('Peak-to-peak distance between zig-zags. This is double the mm/stitch measurement used by most mechanical machines.'), | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |            unit='mm/cycle', | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |            type='float', | 
					
						
							|  |  |  |            default=0.4) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     def zigzag_spacing(self): | 
					
						
							|  |  |  |         # peak-to-peak distance between zigzags | 
					
						
							|  |  |  |         return max(self.get_float_param("zigzag_spacing_mm", 0.4), 0.01) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-06 15:49:25 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param( | 
					
						
							|  |  |  |         'pull_compensation_percent', | 
					
						
							|  |  |  |         _('Pull compensation percentage'), | 
					
						
							| 
									
										
										
										
											2022-11-27 09:17:43 +00:00
										 |  |  |         tooltip=_('Additional pull compensation which varies as a percentage of stitch width. ' | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |                   'Two values separated by a space may be used for an aysmmetric effect.'), | 
					
						
							|  |  |  |         unit='% (each side)', | 
					
						
							| 
									
										
										
										
											2022-11-07 01:23:21 +00:00
										 |  |  |         type='float', | 
					
						
							| 
									
										
										
										
											2022-11-06 15:49:25 +00:00
										 |  |  |         default=0) | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-11-06 15:49:25 +00:00
										 |  |  |     def pull_compensation_percent(self): | 
					
						
							|  |  |  |         # pull compensation as a percentage of the width | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |         return self.get_split_float_param("pull_compensation_percent", (0, 0)) | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     @property | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |     @param( | 
					
						
							|  |  |  |         'pull_compensation_mm', | 
					
						
							|  |  |  |         _('Pull compensation'), | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         tooltip=_('Satin stitches pull the fabric together, resulting in a column narrower than you draw in Inkscape. ' | 
					
						
							|  |  |  |                   'This setting expands each pair of needle penetrations outward from the center of the satin column by a fixed length. ' | 
					
						
							|  |  |  |                   'Two values separated by a space may be used for an aysmmetric effect.'), | 
					
						
							|  |  |  |         unit='mm (each side)', | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |         type='float', | 
					
						
							|  |  |  |         default=0) | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |     def pull_compensation_px(self): | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # In satin stitch, the stitches have a tendency to pull together and | 
					
						
							|  |  |  |         # narrow the entire column.  We can compensate for this by stitching | 
					
						
							|  |  |  |         # wider than we desire the column to end up. | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |         return self.get_split_mm_param_as_px("pull_compensation_mm", (0, 0)) | 
					
						
							| 
									
										
										
										
											2022-11-06 15:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-11 03:15:40 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param( | 
					
						
							|  |  |  |         'reverse_one_rail', | 
					
						
							|  |  |  |         _('Reverse one rail'), | 
					
						
							|  |  |  |         tooltip=_('Enabling this may help if your satin renders very strangely.'), | 
					
						
							|  |  |  |         type='boolean', | 
					
						
							|  |  |  |         default='false', | 
					
						
							|  |  |  |         sort_index=10) | 
					
						
							|  |  |  |     def reverse_one_rail(self): | 
					
						
							|  |  |  |         return self.get_boolean_param('reverse_one_rail', False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param( | 
					
						
							|  |  |  |         'swap_satin_rails', | 
					
						
							|  |  |  |         _('Swap rails'), | 
					
						
							|  |  |  |         tooltip=_('Swaps the first and second rails of the satin column, ' | 
					
						
							| 
									
										
										
										
											2022-11-25 02:10:14 +00:00
										 |  |  |                   'affecting which side the thread finished on as well as any sided properties'), | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |         type='boolean', | 
					
						
							| 
									
										
										
										
											2023-03-11 03:15:40 +00:00
										 |  |  |         default='false', | 
					
						
							|  |  |  |         sort_index=11) | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     def swap_rails(self): | 
					
						
							|  |  |  |         return self.get_boolean_param('swap_satin_rails', False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay')) | 
					
						
							|  |  |  |     def contour_underlay(self): | 
					
						
							|  |  |  |         # "Contour underlay" is stitching just inside the rectangular shape | 
					
						
							|  |  |  |         # of the satin column; that is, up one side and down the other. | 
					
						
							|  |  |  |         return self.get_boolean_param("contour_underlay") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('contour_underlay_stitch_length_mm', _('Stitch length'), unit='mm', group=_('Contour Underlay'), type='float', default=1.5) | 
					
						
							|  |  |  |     def contour_underlay_stitch_length(self): | 
					
						
							|  |  |  |         return max(self.get_float_param("contour_underlay_stitch_length_mm", 1.5), 0.01) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							| 
									
										
										
										
											2018-08-09 18:32:41 +00:00
										 |  |  |     @param('contour_underlay_inset_mm', | 
					
						
							| 
									
										
										
										
											2022-11-09 03:53:55 +00:00
										 |  |  |            _('Inset distance (fixed)'), | 
					
						
							|  |  |  |            tooltip=_('Shrink the outline by a fixed length, to prevent the underlay from showing around the outside of the satin column.'), | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |            group=_('Contour Underlay'), | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |            unit='mm (each side)', type='float', default=0.4, | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |            sort_index=2) | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |     def contour_underlay_inset_px(self): | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # how far inside the edge of the column to stitch the underlay | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |         return self.get_split_mm_param_as_px("contour_underlay_inset_mm", (0.4, 0.4)) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('contour_underlay_inset_percent', | 
					
						
							| 
									
										
										
										
											2022-11-09 03:53:55 +00:00
										 |  |  |            _('Inset distance (proportional)'), | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |            tooltip=_('Shrink the outline by a proportion of the column width, ' | 
					
						
							|  |  |  |                      'to prevent the underlay from showing around the outside of the satin column.'), | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |            group=_('Contour Underlay'), | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |            unit='% (each side)', type='float', default=0, | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |            sort_index=3) | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |     def contour_underlay_inset_percent(self): | 
					
						
							|  |  |  |         # how far inside the edge of the column to stitch the underlay | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |         return self.get_split_float_param("contour_underlay_inset_percent", (0, 0)) | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('center_walk_underlay', _('Center-walk underlay'), type='toggle', group=_('Center-Walk Underlay')) | 
					
						
							|  |  |  |     def center_walk_underlay(self): | 
					
						
							|  |  |  |         # "Center walk underlay" is stitching down and back in the centerline | 
					
						
							|  |  |  |         # between the two sides of the satin column. | 
					
						
							|  |  |  |         return self.get_boolean_param("center_walk_underlay") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('center_walk_underlay_stitch_length_mm', _('Stitch length'), unit='mm', group=_('Center-Walk Underlay'), type='float', default=1.5) | 
					
						
							|  |  |  |     def center_walk_underlay_stitch_length(self): | 
					
						
							|  |  |  |         return max(self.get_float_param("center_walk_underlay_stitch_length_mm", 1.5), 0.01) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |     @property | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |     @param('center_walk_underlay_repeats', | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |            _('Repeats'), | 
					
						
							|  |  |  |            tooltip=_('For an odd number of repeats, this will reverse the direction the satin column is stitched, ' | 
					
						
							|  |  |  |                      'causing stitching to both begin and end at the start point.'), | 
					
						
							|  |  |  |            group=_('Center-Walk Underlay'), | 
					
						
							|  |  |  |            type='int', default=2, | 
					
						
							|  |  |  |            sort_index=2) | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |     def center_walk_underlay_repeats(self): | 
					
						
							|  |  |  |         return max(self.get_int_param("center_walk_underlay_repeats", 2), 1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |     @property | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |     @param('center_walk_underlay_position', | 
					
						
							|  |  |  |            _('Position'), | 
					
						
							|  |  |  |            tooltip=_('Position of underlay from between the rails. 0% is along the first rail, 50% is centered, 100% is along the second rail.'), | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |            group=_('Center-Walk Underlay'), | 
					
						
							|  |  |  |            type='float', unit='%', default=50, | 
					
						
							|  |  |  |            sort_index=3) | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |     def center_walk_underlay_position(self): | 
					
						
							|  |  |  |         return min(100, max(0, self.get_float_param("center_walk_underlay_position", 50))) | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('zigzag_underlay', _('Zig-zag underlay'), type='toggle', group=_('Zig-zag Underlay')) | 
					
						
							|  |  |  |     def zigzag_underlay(self): | 
					
						
							|  |  |  |         return self.get_boolean_param("zigzag_underlay") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							| 
									
										
										
										
											2018-08-09 18:32:41 +00:00
										 |  |  |     @param('zigzag_underlay_spacing_mm', | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |            _('Zig-Zag spacing (peak-to-peak)'), | 
					
						
							|  |  |  |            tooltip=_('Distance between peaks of the zig-zags.'), | 
					
						
							|  |  |  |            unit='mm', | 
					
						
							|  |  |  |            group=_('Zig-zag Underlay'), | 
					
						
							|  |  |  |            type='float', | 
					
						
							|  |  |  |            default=3) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     def zigzag_underlay_spacing(self): | 
					
						
							|  |  |  |         return max(self.get_float_param("zigzag_underlay_spacing_mm", 3), 0.01) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							| 
									
										
										
										
											2018-08-09 18:32:41 +00:00
										 |  |  |     @param('zigzag_underlay_inset_mm', | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |            _('Inset amount (fixed)'), | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |            tooltip=_('default: half of contour underlay inset'), | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |            unit='mm (each side)', | 
					
						
							| 
									
										
										
										
											2018-08-22 00:32:50 +00:00
										 |  |  |            group=_('Zig-zag Underlay'), | 
					
						
							|  |  |  |            type='float', | 
					
						
							|  |  |  |            default="") | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |     def zigzag_underlay_inset_px(self): | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # how far in from the edge of the satin the points in the zigzags | 
					
						
							|  |  |  |         # should be | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Default to half of the contour underlay inset.  That is, if we're | 
					
						
							|  |  |  |         # doing both contour underlay and zigzag underlay, make sure the | 
					
						
							|  |  |  |         # points of the zigzag fall outside the contour underlay but inside | 
					
						
							|  |  |  |         # the edges of the satin column. | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         default = self.contour_underlay_inset_px * 0.5 / PIXELS_PER_MM | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |         x = self.get_split_mm_param_as_px("zigzag_underlay_inset_mm", default) | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         return x | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @param('zigzag_underlay_inset_percent', | 
					
						
							|  |  |  |            _('Inset amount (proportional)'), | 
					
						
							|  |  |  |            tooltip=_('default: half of contour underlay inset'), | 
					
						
							|  |  |  |            unit='% (each side)', | 
					
						
							|  |  |  |            group=_('Zig-zag Underlay'), | 
					
						
							|  |  |  |            type='float', | 
					
						
							|  |  |  |            default="") | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |     def zigzag_underlay_inset_percent(self): | 
					
						
							|  |  |  |         default = self.contour_underlay_inset_percent * 0.5 | 
					
						
							| 
									
										
										
										
											2022-11-24 02:58:39 +00:00
										 |  |  |         return self.get_split_float_param("zigzag_underlay_inset_percent", default) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 11:33:43 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @param('zigzag_underlay_max_stitch_length_mm', | 
					
						
							|  |  |  |            _('Maximum stitch length'), | 
					
						
							|  |  |  |            tooltip=_('Split stitch if distance of maximum stitch length is exceeded'), | 
					
						
							|  |  |  |            unit='mm', | 
					
						
							|  |  |  |            group=_('Zig-zag Underlay'), | 
					
						
							|  |  |  |            type='float', | 
					
						
							|  |  |  |            default="") | 
					
						
							|  |  |  |     def zigzag_underlay_max_stitch_length(self): | 
					
						
							|  |  |  |         return self.get_float_param("zigzag_underlay_max_stitch_length_mm") or None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 01:17:20 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def shape(self): | 
					
						
							|  |  |  |         # This isn't used for satins at all, but other parts of the code | 
					
						
							|  |  |  |         # may need to know the general shape of a satin column. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-18 14:02:07 +00:00
										 |  |  |         return shgeo.MultiLineString(self.flattened_rails).convex_hull | 
					
						
							| 
									
										
										
										
											2018-07-05 01:17:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def csp(self): | 
					
						
							| 
									
										
										
										
											2023-01-28 21:33:58 +00:00
										 |  |  |         paths = self.parse_path() | 
					
						
							|  |  |  |         # exclude subpaths which are just a point | 
					
						
							|  |  |  |         paths = [path for path in paths if len(path) >= 2] | 
					
						
							|  |  |  |         return paths | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |     def rails(self): | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |         """The rails in order, as point lists""" | 
					
						
							| 
									
										
										
										
											2022-11-24 04:09:57 +00:00
										 |  |  |         rails = [subpath for i, subpath in enumerate(self.csp) if i in self.rail_indices] | 
					
						
							|  |  |  |         if len(rails) == 2 and self.swap_rails: | 
					
						
							|  |  |  |             return [rails[1], rails[0]] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             return rails | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def flattened_rails(self): | 
					
						
							|  |  |  |         """The rails, as LineStrings.""" | 
					
						
							| 
									
										
										
										
											2023-03-11 03:15:40 +00:00
										 |  |  |         paths = [shgeo.LineString(self.flatten_subpath(rail)) for rail in self.rails] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if paths and self.reverse_one_rail: | 
					
						
							|  |  |  |             paths[0] = shgeo.LineString(paths[0].coords[::-1]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return tuple(paths) | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def flattened_rungs(self): | 
					
						
							|  |  |  |         """The rungs, as LineStrings.""" | 
					
						
							|  |  |  |         return tuple(shgeo.LineString(self.flatten_subpath(rung)) for rung in self.rungs) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def rungs(self): | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |         """The rungs, as point lists.
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         If there are no rungs, then this is an old-style satin column.  The | 
					
						
							|  |  |  |         rails are expected to have the same number of path nodes.  The path | 
					
						
							|  |  |  |         nodes, taken in sequential pairs, act in the same way as rungs would. | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         if len(self.csp) == 2: | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |             # It's an old-style satin column.  To make things easier we'll | 
					
						
							|  |  |  |             # actually create the implied rungs. | 
					
						
							|  |  |  |             return self._synthesize_rungs() | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |             return [subpath for i, subpath in enumerate(self.csp) if i not in self.rail_indices] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _synthesize_rungs(self): | 
					
						
							|  |  |  |         rung_endpoints = [] | 
					
						
							| 
									
										
										
										
											2023-03-09 17:57:55 +00:00
										 |  |  |         # check for unequal length of rails | 
					
						
							|  |  |  |         equal_length = len(self.rails[0]) == len(self.rails[1]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         for rail in self.rails: | 
					
						
							|  |  |  |             points = self.strip_control_points(rail) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 17:57:55 +00:00
										 |  |  |             if len(points) > 2 or not equal_length: | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |                 # Don't bother putting rungs at the start and end. | 
					
						
							|  |  |  |                 points = points[1:-1] | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 # But do include one at the start if we wouldn't add one otherwise. | 
					
						
							|  |  |  |                 # This avoids confusing other parts of the code. | 
					
						
							|  |  |  |                 points = points[:-1] | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |             rung_endpoints.append(points) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         rungs = [] | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |         for start, end in zip(*rung_endpoints): | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |             rungs.append([[start, start, start], [end, end, end]]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return rungs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def rail_indices(self): | 
					
						
							|  |  |  |         paths = [self.flatten_subpath(subpath) for subpath in self.csp] | 
					
						
							|  |  |  |         paths = [shgeo.LineString(path) for path in paths] | 
					
						
							|  |  |  |         num_paths = len(paths) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Imagine a satin column as a curvy ladder. | 
					
						
							|  |  |  |         # The two long paths are the "rails" of the ladder.  The remainder are | 
					
						
							|  |  |  |         # the "rungs". | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         # | 
					
						
							|  |  |  |         # The subpaths in this SVG path may be in arbitrary order, so we need | 
					
						
							|  |  |  |         # to figure out which are the rails and which are the rungs. | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         # Rungs are the paths that intersect with exactly 2 other paths. | 
					
						
							|  |  |  |         # Rails are everything else. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if num_paths <= 2: | 
					
						
							|  |  |  |             # old-style satin column with no rungs | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |             return list(range(num_paths)) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # This takes advantage of the fact that sum() counts True as 1 | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |         intersection_counts = [sum(paths[i].intersects(paths[j]) for j in range(num_paths) if i != j) | 
					
						
							|  |  |  |                                for i in range(num_paths)] | 
					
						
							|  |  |  |         paths_not_intersecting_two = [i for i in range(num_paths) if intersection_counts[i] != 2] | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         num_not_intersecting_two = len(paths_not_intersecting_two) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if num_not_intersecting_two == 2: | 
					
						
							|  |  |  |             # Great, we have two unambiguous rails. | 
					
						
							|  |  |  |             return paths_not_intersecting_two | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             # This is one of two situations: | 
					
						
							|  |  |  |             # | 
					
						
							|  |  |  |             # 1. There are two rails and two rungs, and it looks like a | 
					
						
							|  |  |  |             # hash symbol (#).  Unfortunately for us, this is an ambiguous situation | 
					
						
							|  |  |  |             # and we'll have to take a guess as to which are the rails and | 
					
						
							|  |  |  |             # which are the rungs.  We'll guess that the rails are the longest | 
					
						
							|  |  |  |             # ones. | 
					
						
							|  |  |  |             # | 
					
						
							|  |  |  |             # or, | 
					
						
							|  |  |  |             # | 
					
						
							|  |  |  |             # 2. The paths don't look like a ladder at all, but some other | 
					
						
							|  |  |  |             # kind of weird thing.  Maybe one of the rungs crosses a rail more | 
					
						
							|  |  |  |             # than once.  Treat it like the previous case and we'll sort out | 
					
						
							|  |  |  |             # the intersection issues later. | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |             indices_by_length = sorted(list(range(num_paths)), key=lambda index: paths[index].length, reverse=True) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |             return indices_by_length[:2] | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def flattened_sections(self): | 
					
						
							|  |  |  |         """Flatten the rails, cut with the rungs, and return the sections in pairs.""" | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |         rails = list(self.flattened_rails) | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |         rungs = self.flattened_rungs | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |         for i, rail in enumerate(rails): | 
					
						
							|  |  |  |             cut_points = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for rung in rungs: | 
					
						
							|  |  |  |                 point_on_rung, point_on_rail = nearest_points(rung, rail) | 
					
						
							|  |  |  |                 cut_points.append(rail.project(point_on_rail)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             rails[i] = cut_multiple(rail, cut_points) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         for rail in rails: | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |             for i in range(len(rail)): | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |                 if rail[i] is not None: | 
					
						
							|  |  |  |                     rail[i] = [Point(*coord) for coord in rail[i].coords] | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         # Clean out empty segments.  Consider an old-style satin like this: | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         #  |   | | 
					
						
							|  |  |  |         #  *   *---* | 
					
						
							|  |  |  |         #  |       | | 
					
						
							|  |  |  |         #  |       | | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         # The stars indicate where the bezier endpoints lay.  On the left, there's a | 
					
						
							|  |  |  |         # zero-length bezier at the star.  The user's goal here is to ignore the | 
					
						
							|  |  |  |         # horizontal section of the right rail. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |         sections = list(zip(*rails)) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         sections = [s for s in sections if s[0] is not None and s[1] is not None] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return sections | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-13 15:22:37 +00:00
										 |  |  |     def validation_warnings(self): | 
					
						
							| 
									
										
										
										
											2023-03-09 17:57:55 +00:00
										 |  |  |         if len(self.csp) == 2 and len(self.rails[0]) != len(self.rails[1]): | 
					
						
							|  |  |  |             yield UnequalPointsWarning(self.flattened_rails[0].interpolate(0.5, normalized=True)) | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |         for rung in self.flattened_rungs: | 
					
						
							| 
									
										
										
										
											2021-04-13 15:22:37 +00:00
										 |  |  |             for rail in self.flattened_rails: | 
					
						
							|  |  |  |                 intersection = rung.intersection(rail) | 
					
						
							|  |  |  |                 if intersection.is_empty: | 
					
						
							|  |  |  |                     yield DanglingRungWarning(rung.interpolate(0.5, normalized=True)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |     def validation_errors(self): | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |         # The node should have exactly two paths with the same number of points - or it should | 
					
						
							|  |  |  |         # have two rails and at least one rung | 
					
						
							| 
									
										
										
										
											2023-01-28 21:33:58 +00:00
										 |  |  |         if len(self.csp) < 2: | 
					
						
							|  |  |  |             yield TooFewPathsError((0, 0)) | 
					
						
							|  |  |  |         elif len(self.rails) < 2: | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |             yield TooFewPathsError(self.shape.centroid) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |             for rung in self.flattened_rungs: | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |                 for rail in self.flattened_rails: | 
					
						
							|  |  |  |                     intersection = rung.intersection(rail) | 
					
						
							| 
									
										
										
										
											2021-04-13 15:22:37 +00:00
										 |  |  |                     if not intersection.is_empty and not isinstance(intersection, shgeo.Point): | 
					
						
							| 
									
										
										
										
											2019-08-06 02:42:48 +00:00
										 |  |  |                         yield TooManyIntersectionsError(rung.interpolate(0.5, normalized=True)) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 06:27:42 +00:00
										 |  |  |         if not self.to_stitch_groups(): | 
					
						
							|  |  |  |             yield NotStitchableError(self.shape.centroid) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |     def _center_walk_is_odd(self): | 
					
						
							|  |  |  |         return self.center_walk_underlay_repeats % 2 == 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |     def reverse(self): | 
					
						
							|  |  |  |         """Return a new SatinColumn like this one but in the opposite direction.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         The path will be flattened and the new satin will contain a new XML | 
					
						
							|  |  |  |         node that is not yet in the SVG. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         # flatten the path because you can't just reverse a CSP subpath's elements (I think) | 
					
						
							|  |  |  |         point_lists = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for rail in self.rails: | 
					
						
							|  |  |  |             point_lists.append(list(reversed(self.flatten_subpath(rail)))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # reverse the order of the rails because we're sewing in the opposite direction | 
					
						
							|  |  |  |         point_lists.reverse() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for rung in self.rungs: | 
					
						
							|  |  |  |             point_lists.append(self.flatten_subpath(rung)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-27 17:14:41 +00:00
										 |  |  |         # If originally there were only two subpaths (no rungs) with same number of rails, the rails may now | 
					
						
							| 
									
										
										
										
											2022-11-06 16:03:47 +00:00
										 |  |  |         # have two rails with different number of points, and still no rungs, let's add one. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if not self.rungs: | 
					
						
							|  |  |  |             rails = [shgeo.LineString(reversed(self.flatten_subpath(rail))) for rail in self.rails] | 
					
						
							|  |  |  |             rails.reverse() | 
					
						
							|  |  |  |             path_list = rails | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             rung_start = path_list[0].interpolate(0.1) | 
					
						
							|  |  |  |             rung_end = path_list[1].interpolate(0.1) | 
					
						
							|  |  |  |             rung = shgeo.LineString((rung_start, rung_end)) | 
					
						
							|  |  |  |             # make it a bit bigger so that it definitely intersects | 
					
						
							|  |  |  |             rung = shaffinity.scale(rung, 1.1, 1.1) | 
					
						
							|  |  |  |             path_list.append(rung) | 
					
						
							|  |  |  |             return (self._path_list_to_satins(path_list)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         return self._csp_to_satin(point_lists_to_csp(point_lists)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def apply_transform(self): | 
					
						
							|  |  |  |         """Return a new SatinColumn like this one but with transforms applied.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         This node's and all ancestor nodes' transforms will be applied.  The | 
					
						
							|  |  |  |         new SatinColumn's node will not be in the SVG document. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return self._csp_to_satin(self.csp) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |     def split(self, split_point): | 
					
						
							|  |  |  |         """Split a satin into two satins at the specified point
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         split_point is a point on or near one of the rails, not at one of the | 
					
						
							|  |  |  |         ends. Finds corresponding point on the other rail (taking into account | 
					
						
							|  |  |  |         the rungs) and breaks the rails at these points. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         split_point can also be a noramlized projection of a distance along the | 
					
						
							|  |  |  |         satin, in the range 0.0 to 1.0. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         Returns two new SatinColumn instances: the part before and the part | 
					
						
							|  |  |  |         after the split point.  All parameters are copied over to the new | 
					
						
							|  |  |  |         SatinColumn instances. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cut_points = self._find_cut_points(split_point) | 
					
						
							|  |  |  |         path_lists = self._cut_rails(cut_points) | 
					
						
							|  |  |  |         self._assign_rungs_to_split_rails(path_lists) | 
					
						
							|  |  |  |         self._add_rungs_if_necessary(path_lists) | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         return [self._path_list_to_satins(path_list) for path_list in path_lists] | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _find_cut_points(self, split_point): | 
					
						
							|  |  |  |         """Find the points on each satin corresponding to the split point.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         split_point is a point that is near but not necessarily touching one | 
					
						
							|  |  |  |         of the rails.  It is projected onto that rail to obtain the cut point | 
					
						
							|  |  |  |         for that rail.  A corresponding cut point will be chosen on the other | 
					
						
							|  |  |  |         rail, taking into account the satin's rungs to choose a matching point. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         split_point can instead be a number in [0.0, 1.0] indicating a | 
					
						
							|  |  |  |         a fractional distance down the satin to cut at. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         Returns: a list of two Point objects corresponding to the selected | 
					
						
							|  |  |  |           cut points. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         # like in do_satin() | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         points = list(chain.from_iterable(self.plot_points_on_rails(self.zigzag_spacing))) | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if isinstance(split_point, float): | 
					
						
							|  |  |  |             index_of_closest_stitch = int(round(len(points) * split_point)) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             split_point = Point(*split_point) | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |             index_of_closest_stitch = min(list(range(len(points))), key=lambda index: split_point.distance(points[index])) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if index_of_closest_stitch % 2 == 0: | 
					
						
							|  |  |  |             # split point is on the first rail | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |             return (points[index_of_closest_stitch], | 
					
						
							|  |  |  |                     points[index_of_closest_stitch + 1]) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         else: | 
					
						
							|  |  |  |             # split point is on the second rail | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |             return (points[index_of_closest_stitch - 1], | 
					
						
							|  |  |  |                     points[index_of_closest_stitch]) | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _cut_rails(self, cut_points): | 
					
						
							|  |  |  |         """Cut the rails of this satin at the specified points.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cut_points is a list of two elements, corresponding to the cut points | 
					
						
							|  |  |  |         for each rail in order. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Returns: A list of two elements, corresponding two the two new sets of | 
					
						
							|  |  |  |           rails.  Each element is a list of two rails of type LineString. | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         rails = [shgeo.LineString(self.flatten_subpath(rail)) for rail in self.rails] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         path_lists = [[], []] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for i, rail in enumerate(rails): | 
					
						
							|  |  |  |             before, after = cut(rail, rail.project(shgeo.Point(cut_points[i]))) | 
					
						
							|  |  |  |             path_lists[0].append(before) | 
					
						
							|  |  |  |             path_lists[1].append(after) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return path_lists | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _assign_rungs_to_split_rails(self, split_rails): | 
					
						
							|  |  |  |         """Add this satin's rungs to the new satins.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Each rung is appended to the correct one of the two new satin columns. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         rungs = [shgeo.LineString(self.flatten_subpath(rung)) for rung in self.rungs] | 
					
						
							|  |  |  |         for path_list in split_rails: | 
					
						
							|  |  |  |             path_list.extend(rung for rung in rungs if path_list[0].intersects(rung) and path_list[1].intersects(rung)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _add_rungs_if_necessary(self, path_lists): | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         """Add an additional rung to each new satin if needed.
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         Case #1: If the split point is between the end and the last rung, then | 
					
						
							|  |  |  |         one of the satins will have no rungs.  It will be treated as an old-style | 
					
						
							|  |  |  |         satin, but it may not have an equal number of points in each rail.  Adding | 
					
						
							|  |  |  |         a rung will make it stitch properly. | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         Case #2: If one of the satins ends up with exactly two rungs, it's | 
					
						
							|  |  |  |         ambiguous which of the subpaths are rails and which are rungs.  Adding | 
					
						
							|  |  |  |         another rung disambiguates this case.  See rail_indices() above for more | 
					
						
							|  |  |  |         information. | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for path_list in path_lists: | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |             if len(path_list) in (2, 4): | 
					
						
							| 
									
										
										
										
											2022-11-27 07:37:59 +00:00
										 |  |  |                 # Add the rung at the start of the satin. | 
					
						
							|  |  |  |                 rung_start = path_list[0].coords[0] | 
					
						
							|  |  |  |                 rung_end = path_list[1].coords[0] | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |                 rung = shgeo.LineString((rung_start, rung_end)) | 
					
						
							|  |  |  |                 path_list.append(rung) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |     def _path_list_to_satins(self, path_list): | 
					
						
							|  |  |  |         return self._csp_to_satin(line_strings_to_csp(path_list)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _csp_to_satin(self, csp): | 
					
						
							|  |  |  |         node = deepcopy(self.node) | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |         d = paths.CubicSuperPath(csp).to_path() | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         node.set("d", d) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # we've already applied the transform, so get rid of it | 
					
						
							|  |  |  |         if node.get("transform"): | 
					
						
							|  |  |  |             del node.attrib["transform"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return SatinColumn(node) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     @cache | 
					
						
							|  |  |  |     def center_line(self): | 
					
						
							|  |  |  |         # similar technique to do_center_walk() | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         center_walk = [p[0] for p in self.plot_points_on_rails(self.zigzag_spacing, (0, 0), (-0.5, -0.5))] | 
					
						
							| 
									
										
											  
											
												new extension: Auto-Route Satin Columns (#330)
**video demo:** https://www.youtube.com/watch?v=tbghtqziB1g
This branch adds a new extension, Auto-Route Satin Columns, implementing #214!  This is a huge new feature that opens the door wide for exciting stuff like lettering (#142).
To use it, select some satin columns and run the extension.  After a few seconds, it will replace your satins with a new set with a logical stitching order.  Under-pathing and jump-stitches will be added as necessary, and satins will be broken to facilitate jumps.  The resulting satins will retain all of the parameters you had set on the original satins, including underlay, zig-zag spacing, etc.
By default, it will choose the left-most extreme as the starting point and the right-most extreme as the ending point (even if these occur partway through a satin such as the left edge of a letter "o").  You can override this by attaching the new "Auto-route satin stitch starting/ending position" commands.
There's also an option to add trims instead of jump stitches.  Any jump stitch over 1mm is trimmed.  I might make this configurable in the future but in my tests it seems to do a good job.  Trim commands are added to the SVG, so it's easy enough to modify/delete as you see fit.
											
										 
											2018-10-30 23:43:21 +00:00
										 |  |  |         return shgeo.LineString(center_walk) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-25 02:10:14 +00:00
										 |  |  |     def offset_points(self, pos1, pos2, offset_px, offset_proportional): | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # Expand or contract two points about their midpoint.  This is | 
					
						
							|  |  |  |         # useful for pull compensation and insetting underlay. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         distance = (pos1 - pos2).length() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if distance < 0.0001: | 
					
						
							|  |  |  |             # if they're the same point, we don't know which direction | 
					
						
							|  |  |  |             # to offset in, so we have to just return the points | 
					
						
							|  |  |  |             return pos1, pos2 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 01:23:21 +00:00
										 |  |  |         # calculate the offset for each side | 
					
						
							| 
									
										
										
										
											2022-11-25 02:10:14 +00:00
										 |  |  |         offset_a = offset_px[0] + (distance * offset_proportional[0]) | 
					
						
							|  |  |  |         offset_b = offset_px[1] + (distance * offset_proportional[1]) | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         offset_total = offset_a + offset_b | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 01:23:21 +00:00
										 |  |  |         # don't contract beyond the midpoint, or we'll start expanding | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         if offset_total < -distance: | 
					
						
							| 
									
										
										
										
											2022-11-27 09:17:43 +00:00
										 |  |  |             scale = -distance / offset_total | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |             offset_a = offset_a * scale | 
					
						
							|  |  |  |             offset_b = offset_b * scale | 
					
						
							| 
									
										
										
										
											2022-11-06 15:49:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         out1 = pos1 + (pos1 - pos2).unit() * offset_a | 
					
						
							|  |  |  |         out2 = pos2 + (pos2 - pos1).unit() * offset_b | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-11 05:26:59 +00:00
										 |  |  |         return out1, out2 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def walk(self, path, start_pos, start_index, distance): | 
					
						
							|  |  |  |         # Move <distance> pixels along <path>, which is a sequence of line | 
					
						
							|  |  |  |         # segments defined by points. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # <start_index> is the index of the line segment in <path> that | 
					
						
							|  |  |  |         # we're currently on.  <start_pos> is where along that line | 
					
						
							|  |  |  |         # segment we are.  Return a new position and index. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # print >> dbg, "walk", start_pos, start_index, distance | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pos = start_pos | 
					
						
							|  |  |  |         index = start_index | 
					
						
							|  |  |  |         last_index = len(path) - 1 | 
					
						
							|  |  |  |         distance_remaining = distance | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         while True: | 
					
						
							|  |  |  |             if index >= last_index: | 
					
						
							|  |  |  |                 return pos, index | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             segment_end = path[index + 1] | 
					
						
							|  |  |  |             segment = segment_end - pos | 
					
						
							|  |  |  |             segment_length = segment.length() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if segment_length > distance_remaining: | 
					
						
							|  |  |  |                 # our walk ends partway along this segment | 
					
						
							|  |  |  |                 return pos + segment.unit() * distance_remaining, index | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 # our walk goes past the end of this segment, so advance | 
					
						
							|  |  |  |                 # one point | 
					
						
							|  |  |  |                 index += 1 | 
					
						
							|  |  |  |                 distance_remaining -= segment_length | 
					
						
							|  |  |  |                 pos = segment_end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |     def plot_points_on_rails(self, spacing, offset_px=(0, 0), offset_proportional=(0, 0), use_random=False | 
					
						
							|  |  |  |                              ) -> typing.List[typing.Tuple[Point, Point]]: | 
					
						
							| 
									
										
										
										
											2019-02-26 01:09:59 +00:00
										 |  |  |         # Take a section from each rail in turn, and plot out an equal number | 
					
						
							|  |  |  |         # of points on both rails.  Return the points plotted. The points will | 
					
						
							|  |  |  |         # be contracted or expanded by offset using self.offset_points(). | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         # pre-cache ramdomised parameters to avoid property calls in loop | 
					
						
							|  |  |  |         if use_random: | 
					
						
							| 
									
										
										
										
											2023-01-16 19:34:29 +00:00
										 |  |  |             seed = prng.join_args(self.random_seed, "satin-points") | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |             offset_proportional_min = np.array(offset_proportional) - self.random_width_decrease | 
					
						
							|  |  |  |             offset_range = (self.random_width_increase + self.random_width_decrease) | 
					
						
							| 
									
										
										
										
											2022-12-29 00:38:55 +00:00
										 |  |  |             spacing_sigma = spacing * self.random_zigzag_spacing | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         pairs = [] | 
					
						
							| 
									
										
										
										
											2019-02-26 01:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |         to_travel = 0 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         cycle = 0 | 
					
						
							| 
									
										
										
										
											2019-02-26 01:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |         for section0, section1 in self.flattened_sections: | 
					
						
							|  |  |  |             # Take one section at a time, delineated by the rungs.  For each | 
					
						
							|  |  |  |             # one, we want to try to travel proportionately on each rail as | 
					
						
							|  |  |  |             # we go between stitches.  For example, for the letter O, the | 
					
						
							|  |  |  |             # outside rail is longer than the inside rail.  We need to travel | 
					
						
							|  |  |  |             # further on the outside rail between each stitch than we do | 
					
						
							|  |  |  |             # on the inside rail. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             pos0 = section0[0] | 
					
						
							|  |  |  |             pos1 = section1[0] | 
					
						
							| 
									
										
										
										
											2019-02-26 01:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |             len0 = shgeo.LineString(section0).length | 
					
						
							|  |  |  |             len1 = shgeo.LineString(section1).length | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |             last_index0 = len(section0) - 1 | 
					
						
							|  |  |  |             last_index1 = len(section1) - 1 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 16:39:36 +00:00
										 |  |  |             if len0 == 0: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |             ratio = len1 / len0 | 
					
						
							| 
									
										
										
										
											2019-02-26 01:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |             index0 = 0 | 
					
						
							|  |  |  |             index1 = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             while index0 < last_index0 and index1 < last_index1: | 
					
						
							| 
									
										
										
										
											2023-02-06 03:33:38 +00:00
										 |  |  |                 check_stop_flag() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |                 # Each iteration of this outer loop is one stitch.  Keep going | 
					
						
							|  |  |  |                 # until we fall off the end of the section. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 03:33:38 +00:00
										 |  |  |                 old_center = shgeo.Point(x / 2 for x in (pos0 + pos1)) | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 while to_travel > 0 and index0 < last_index0 and index1 < last_index1: | 
					
						
							|  |  |  |                     # In this loop, we inch along each rail a tiny bit per | 
					
						
							|  |  |  |                     # iteration.  The goal is to travel the requested spacing | 
					
						
							|  |  |  |                     # amount along the _centerline_ between the two rails. | 
					
						
							|  |  |  |                     # | 
					
						
							|  |  |  |                     # Why not just travel the requested amount along the rails | 
					
						
							|  |  |  |                     # themselves?  Imagine a letter V.  The distance we travel | 
					
						
							|  |  |  |                     # along the rails themselves is much longer than the distance | 
					
						
							|  |  |  |                     # between the horizontal stitches themselves: | 
					
						
							| 
									
										
										
										
											2019-03-09 00:55:13 +00:00
										 |  |  |                     # | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |                     # \______/ | 
					
						
							|  |  |  |                     #  \____/ | 
					
						
							|  |  |  |                     #   \__/ | 
					
						
							|  |  |  |                     #    \/ | 
					
						
							| 
									
										
										
										
											2019-03-09 00:55:13 +00:00
										 |  |  |                     # | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |                     # For more complicated rail shapes, the distance between each | 
					
						
							|  |  |  |                     # stitch will vary as the angles of the rails vary.  The | 
					
						
							|  |  |  |                     # easiest way to compensate for this is to just go a tiny bit | 
					
						
							|  |  |  |                     # at a time and see how far we went. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     # Note that this is 0.05 pixels, which is around 0.01mm, way | 
					
						
							|  |  |  |                     # smaller than the resolution of an embroidery machine. | 
					
						
							|  |  |  |                     pos0, index0 = self.walk(section0, pos0, index0, 0.05) | 
					
						
							|  |  |  |                     pos1, index1 = self.walk(section1, pos1, index1, 0.05 * ratio) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 17:40:53 +00:00
										 |  |  |                     new_center = shgeo.Point(x/2 for x in (pos0 + pos1)) | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  |                     to_travel -= new_center.distance(old_center) | 
					
						
							|  |  |  |                     old_center = new_center | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if to_travel <= 0: | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                     if use_random: | 
					
						
							| 
									
										
										
										
											2023-01-16 19:34:29 +00:00
										 |  |  |                         roll = prng.uniform_floats(seed, cycle) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                         offset_prop = offset_proportional_min + roll[0:2] * offset_range | 
					
						
							| 
									
										
										
										
											2022-12-29 00:38:55 +00:00
										 |  |  |                         to_travel = spacing + ((roll[2] - 0.5) * 2 * spacing_sigma) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                     else: | 
					
						
							|  |  |  |                         offset_prop = offset_proportional | 
					
						
							|  |  |  |                         to_travel = spacing | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     a, b = self.offset_points(pos0, pos1, offset_px, offset_prop) | 
					
						
							|  |  |  |                     pairs.append((a, b)) | 
					
						
							|  |  |  |                     cycle += 1 | 
					
						
							| 
									
										
										
										
											2020-01-27 18:53:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if to_travel > 0: | 
					
						
							| 
									
										
										
										
											2023-01-13 04:07:48 +00:00
										 |  |  |             a, b = self.offset_points(pos0, pos1, offset_px, offset_prop) | 
					
						
							|  |  |  |             pairs.append((a, b)) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         return pairs | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def do_contour_underlay(self): | 
					
						
							|  |  |  |         # "contour walk" underlay: do stitches up one side and down the | 
					
						
							|  |  |  |         # other. | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         pairs = self.plot_points_on_rails( | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |             self.contour_underlay_stitch_length, | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |             -self.contour_underlay_inset_px, -self.contour_underlay_inset_percent/100) | 
					
						
							| 
									
										
										
										
											2023-01-22 19:50:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |         if self._center_walk_is_odd(): | 
					
						
							| 
									
										
										
										
											2023-01-22 19:50:26 +00:00
										 |  |  |             stitches = [p[0] for p in reversed(pairs)] + [p[1] for p in pairs] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             stitches = [p[1] for p in pairs] + [p[0] for p in reversed(pairs)] | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-16 14:30:22 +00:00
										 |  |  |         return StitchGroup( | 
					
						
							|  |  |  |             color=self.color, | 
					
						
							|  |  |  |             tags=("satin_column", "satin_column_underlay", "satin_contour_underlay"), | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |             stitches=stitches) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def do_center_walk(self): | 
					
						
							|  |  |  |         # Center walk underlay is just a running stitch down and back on the | 
					
						
							|  |  |  |         # center line between the bezier curves. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |         inset_prop = -np.array([self.center_walk_underlay_position, 100-self.center_walk_underlay_position]) / 100 | 
					
						
							| 
									
										
										
										
											2022-11-27 09:17:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # Do it like contour underlay, but inset all the way to the center. | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         pairs = self.plot_points_on_rails( | 
					
						
							| 
									
										
										
										
											2022-11-07 03:23:25 +00:00
										 |  |  |             self.center_walk_underlay_stitch_length, | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |             (0, 0), inset_prop) | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         stitches = [] | 
					
						
							|  |  |  |         for i in range(self.center_walk_underlay_repeats): | 
					
						
							|  |  |  |             if i % 2 == 0: | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                 stitches += [p[0] for p in pairs] | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                 stitches += [p[1] for p in reversed(pairs)] | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-16 14:30:22 +00:00
										 |  |  |         return StitchGroup( | 
					
						
							|  |  |  |             color=self.color, | 
					
						
							|  |  |  |             tags=("satin_column", "satin_column_underlay", "satin_center_walk"), | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |             stitches=stitches) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def do_zigzag_underlay(self): | 
					
						
							|  |  |  |         # zigzag underlay, usually done at a much lower density than the | 
					
						
							|  |  |  |         # satin itself.  It looks like this: | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         # \/\/\/\/\/\/\/\/\/\/| | 
					
						
							|  |  |  |         # /\/\/\/\/\/\/\/\/\/\| | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         # In combination with the "contour walk" underlay, this is the | 
					
						
							|  |  |  |         # "German underlay" described here: | 
					
						
							|  |  |  |         #   http://www.mrxstitch.com/underlay-what-lies-beneath-machine-embroidery/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 14:57:53 +00:00
										 |  |  |         patch = StitchGroup(color=self.color) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         pairs = self.plot_points_on_rails(self.zigzag_underlay_spacing / 2.0, | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |                                           -self.zigzag_underlay_inset_px, | 
					
						
							|  |  |  |                                           -self.zigzag_underlay_inset_percent/100) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |         if self._center_walk_is_odd(): | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |             pairs = list(reversed(pairs)) | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # This organizes the points in each side in the order that they'll be | 
					
						
							|  |  |  |         # visited. | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         # take a points, from each side in turn, then go backed over the other points | 
					
						
							|  |  |  |         points = [p[i % 2] for i, p in enumerate(pairs)] + list(reversed([p[i % 2] for i, p in enumerate(pairs, 1)])) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         max_len = self.zigzag_underlay_max_stitch_length | 
					
						
							| 
									
										
										
										
											2021-09-30 11:33:43 +00:00
										 |  |  |         last_point = None | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         for point in points: | 
					
						
							|  |  |  |             if last_point and max_len: | 
					
						
							|  |  |  |                 if last_point.distance(point) > max_len: | 
					
						
							|  |  |  |                     split_points = running_stitch.split_segment_even_dist(last_point, point, max_len) | 
					
						
							|  |  |  |                     for p in split_points: | 
					
						
							|  |  |  |                         patch.add_stitch(p) | 
					
						
							| 
									
										
										
										
											2021-09-30 11:33:43 +00:00
										 |  |  |             last_point = point | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |             patch.add_stitch(point) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-16 14:30:22 +00:00
										 |  |  |         patch.add_tags(("satin_column", "satin_column_underlay", "satin_zigzag_underlay")) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         return patch | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def do_satin(self): | 
					
						
							|  |  |  |         # satin: do a zigzag pattern, alternating between the paths.  The | 
					
						
							|  |  |  |         # zigzag looks like this to make the satin stitches look perpendicular | 
					
						
							|  |  |  |         # to the column: | 
					
						
							|  |  |  |         # | 
					
						
							| 
									
										
										
										
											2018-09-29 20:00:36 +00:00
										 |  |  |         # |/|/|/|/|/|/|/|/| | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # print >> dbg, "satin", self.zigzag_spacing, self.pull_compensation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 14:57:53 +00:00
										 |  |  |         patch = StitchGroup(color=self.color) | 
					
						
							| 
									
										
										
										
											2022-11-07 01:23:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # pull compensation is automatically converted from mm to pixels by get_float_param | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         pairs = self.plot_points_on_rails( | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |             self.zigzag_spacing, | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |             self.pull_compensation_px, | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |             self.pull_compensation_percent/100, | 
					
						
							|  |  |  |             True, | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         max_stitch_length = self.max_stitch_length_px | 
					
						
							| 
									
										
										
										
											2022-12-27 06:12:15 +00:00
										 |  |  |         length_sigma = self.random_split_jitter | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         random_phase = self.random_split_phase | 
					
						
							|  |  |  |         min_split_length = self.min_random_split_length_px | 
					
						
							|  |  |  |         seed = self.random_seed | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         short_pairs = self.inset_short_stitches_sawtooth(pairs) | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         last_point = None | 
					
						
							|  |  |  |         last_short_point = None | 
					
						
							|  |  |  |         last_count = None | 
					
						
							|  |  |  |         for i, (a, b), (a_short, b_short) in zip(itertools.count(0), pairs, short_pairs): | 
					
						
							|  |  |  |             if last_point is not None: | 
					
						
							|  |  |  |                 split_points, _ = self.get_split_points( | 
					
						
							|  |  |  |                     last_point, a, last_short_point, a_short, max_stitch_length, last_count, | 
					
						
							| 
									
										
										
										
											2023-01-16 19:34:29 +00:00
										 |  |  |                     length_sigma, random_phase, min_split_length, prng.join_args(seed, 'satin-split', 2 * i)) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                 patch.add_stitches(split_points, ("satin_column", "satin_split_stitch")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             patch.add_stitch(a_short) | 
					
						
							|  |  |  |             patch.stitches[-1].add_tags(("satin_column", "satin_column_edge")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             split_points, last_count = self.get_split_points( | 
					
						
							|  |  |  |                 a, b, a_short, b_short, max_stitch_length, None, | 
					
						
							| 
									
										
										
										
											2023-01-16 19:34:29 +00:00
										 |  |  |                 length_sigma, random_phase, min_split_length, prng.join_args(seed, 'satin-split', 2 * i + 1)) | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |             patch.add_stitches(split_points, ("satin_column", "satin_split_stitch")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             patch.add_stitch(b_short) | 
					
						
							|  |  |  |             patch.stitches[-1].add_tags(("satin_column", "satin_column_edge")) | 
					
						
							|  |  |  |             last_point = b | 
					
						
							|  |  |  |             last_short_point = b_short | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |         if self._center_walk_is_odd(): | 
					
						
							|  |  |  |             patch.stitches = list(reversed(patch.stitches)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         return patch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  |     def do_e_stitch(self): | 
					
						
							|  |  |  |         # e stitch: do a pattern that looks like the letter "E".  It looks like | 
					
						
							|  |  |  |         # this: | 
					
						
							|  |  |  |         # | 
					
						
							|  |  |  |         # _|_|_|_|_|_|_|_|_|_|_|_| | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # print >> dbg, "satin", self.zigzag_spacing, self.pull_compensation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 14:57:53 +00:00
										 |  |  |         patch = StitchGroup(color=self.color) | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         pairs = self.plot_points_on_rails( | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |             self.zigzag_spacing, | 
					
						
							| 
									
										
										
										
											2022-11-17 06:51:33 +00:00
										 |  |  |             self.pull_compensation_px, | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |             self.pull_compensation_percent/100, | 
					
						
							| 
									
										
										
										
											2023-01-28 13:51:12 +00:00
										 |  |  |             self.random_width_decrease.any() or self.random_width_increase.any() or self.random_zigzag_spacing, | 
					
						
							| 
									
										
										
										
											2022-11-11 05:20:59 +00:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # "left" and "right" here are kind of arbitrary designations meaning | 
					
						
							| 
									
										
										
										
											2021-07-29 18:52:44 +00:00
										 |  |  |         # a point from the first and second rail respectively | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |         for left, right in pairs: | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  |             patch.add_stitch(left) | 
					
						
							|  |  |  |             patch.add_stitch(right) | 
					
						
							|  |  |  |             patch.add_stitch(left) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-10 14:23:44 +00:00
										 |  |  |         if self._center_walk_is_odd(): | 
					
						
							|  |  |  |             patch.stitches = list(reversed(patch.stitches)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-16 14:30:22 +00:00
										 |  |  |         patch.add_tags(("satin_column", "e_stitch")) | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  |         return patch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |     def get_split_points(self, a, b, a_short, b_short, length, count=None, length_sigma=0.0, random_phase=False, min_split_length=None, seed=None): | 
					
						
							|  |  |  |         if not length: | 
					
						
							|  |  |  |             return ([], None) | 
					
						
							|  |  |  |         if min_split_length is None: | 
					
						
							|  |  |  |             min_split_length = length | 
					
						
							|  |  |  |         distance = a.distance(b) | 
					
						
							|  |  |  |         if distance <= min_split_length: | 
					
						
							|  |  |  |             return ([], 1) | 
					
						
							|  |  |  |         if random_phase: | 
					
						
							|  |  |  |             points = running_stitch.split_segment_random_phase(a_short, b_short, length, length_sigma, seed) | 
					
						
							|  |  |  |             return (points, None) | 
					
						
							|  |  |  |         elif count is not None: | 
					
						
							|  |  |  |             points = running_stitch.split_segment_even_n(a, b, count, length_sigma, seed) | 
					
						
							|  |  |  |             return (points, count) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             points = running_stitch.split_segment_even_dist(a, b, length, length_sigma, seed) | 
					
						
							|  |  |  |             return (points, len(points) + 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def inset_short_stitches_sawtooth(self, pairs): | 
					
						
							|  |  |  |         min_dist = self.short_stitch_distance | 
					
						
							|  |  |  |         inset = min(self.short_stitch_inset, 0.5) | 
					
						
							|  |  |  |         max_stitch_length = None if self.random_split_phase else self.max_stitch_length_px | 
					
						
							|  |  |  |         if not min_dist or not inset: | 
					
						
							|  |  |  |             return pairs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         shortened = [] | 
					
						
							|  |  |  |         for i, (a, b) in enumerate(pairs): | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  |             if i % 2 == 0: | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                 shortened.append((a, b)) | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |             dist = a.distance(b) | 
					
						
							|  |  |  |             inset_px = inset * dist | 
					
						
							|  |  |  |             if max_stitch_length and not self.random_split_phase: | 
					
						
							|  |  |  |                 # make sure inset is less than split etitch length | 
					
						
							|  |  |  |                 inset_px = min(inset_px, max_stitch_length / 3) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             offset_px = [0, 0] | 
					
						
							|  |  |  |             if a.distance(pairs[i-1][0]) < min_dist: | 
					
						
							|  |  |  |                 offset_px[0] = -inset_px | 
					
						
							| 
									
										
										
										
											2023-01-28 11:02:17 +00:00
										 |  |  |             if b.distance(pairs[i-1][1]) < min_dist: | 
					
						
							| 
									
										
										
										
											2022-12-27 01:13:48 +00:00
										 |  |  |                 offset_px[1] = -inset_px | 
					
						
							|  |  |  |             shortened.append(self.offset_points(a, b, offset_px, (0, 0))) | 
					
						
							|  |  |  |         return shortened | 
					
						
							| 
									
										
										
										
											2022-06-24 05:25:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _get_inset_point(self, point1, point2, distance_fraction): | 
					
						
							|  |  |  |         return point1 * (1 - distance_fraction) + point2 * distance_fraction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 06:27:42 +00:00
										 |  |  |     def to_stitch_groups(self, last_patch=None): | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  |         # Stitch a variable-width satin column, zig-zagging between two paths. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # The algorithm will draw zigzags between each consecutive pair of | 
					
						
							|  |  |  |         # beziers.  The boundary points between beziers serve as "checkpoints", | 
					
						
							|  |  |  |         # allowing the user to control how the zigzags flow around corners. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-27 15:05:52 +00:00
										 |  |  |         patch = StitchGroup(color=self.color, | 
					
						
							|  |  |  |                             force_lock_stitches=self.force_lock_stitches, | 
					
						
							|  |  |  |                             lock_stitches=self.lock_stitches) | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if self.center_walk_underlay: | 
					
						
							| 
									
										
										
										
											2019-01-18 00:55:51 +00:00
										 |  |  |             patch += self.do_center_walk() | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if self.contour_underlay: | 
					
						
							| 
									
										
										
										
											2019-01-18 00:55:51 +00:00
										 |  |  |             patch += self.do_contour_underlay() | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if self.zigzag_underlay: | 
					
						
							|  |  |  |             # zigzag underlay comes after contour walk underlay, so that the | 
					
						
							|  |  |  |             # zigzags sit on the contour walk underlay like rail ties on rails. | 
					
						
							| 
									
										
										
										
											2019-01-18 00:55:51 +00:00
										 |  |  |             patch += self.do_zigzag_underlay() | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  |         if self.e_stitch: | 
					
						
							| 
									
										
										
										
											2019-01-18 00:55:51 +00:00
										 |  |  |             patch += self.do_e_stitch() | 
					
						
							| 
									
										
										
										
											2018-07-28 01:10:02 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2019-01-18 00:55:51 +00:00
										 |  |  |             patch += self.do_satin() | 
					
						
							| 
									
										
										
										
											2018-03-31 00:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-24 06:27:42 +00:00
										 |  |  |         if not patch.stitches: | 
					
						
							|  |  |  |             return [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 00:55:51 +00:00
										 |  |  |         return [patch] |