summaryrefslogtreecommitdiff
path: root/lib/elements/satin_column.py
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2023-04-27 13:53:34 -0400
committerGitHub <noreply@github.com>2023-04-27 19:53:34 +0200
commit675898a602e60d69bf3e161d16450338ba0780bf (patch)
treec03f4f13d2201f2e01f5fac0a5f96fd5de3cc213 /lib/elements/satin_column.py
parent97bbe6f174245251d16b4c41537cab41b03b795b (diff)
(auto) reverse rung (#2223)
Diffstat (limited to 'lib/elements/satin_column.py')
-rw-r--r--lib/elements/satin_column.py66
1 files changed, 57 insertions, 9 deletions
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index 4f083b21..dafc9c6b 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -229,16 +229,61 @@ class SatinColumn(EmbroideryElement):
# wider than we desire the column to end up.
return self.get_split_mm_param_as_px("pull_compensation_mm", (0, 0))
+ _reverse_rails_options = [ParamOption('automatic', _('Automatic')),
+ ParamOption('none', _("Don't reverse")),
+ ParamOption('first', _('Reverse first rail')),
+ ParamOption('second', _('Reverse second rail')),
+ ParamOption('both', _('Reverse both rails'))
+ ]
+
@property
@param(
- 'reverse_one_rail',
- _('Reverse one rail'),
- tooltip=_('Enabling this may help if your satin renders very strangely.'),
- type='boolean',
- default='false',
+ 'reverse_rails',
+ _('Reverse rails'),
+ tooltip=_('This may help if your satin renders very strangely. ' +
+ 'Default: automatically detect and fix a reversed rail.'),
+ type='combo',
+ options=_reverse_rails_options,
+ default='automatic',
sort_index=10)
- def reverse_one_rail(self):
- return self.get_boolean_param('reverse_one_rail', False)
+ def reverse_rails(self):
+ return self.get_param('reverse_rails', 'automatic')
+
+ def _get_rails_to_reverse(self, rails):
+ choice = self.reverse_rails
+
+ if choice == 'first':
+ return True, False
+ elif choice == 'second':
+ return False, True
+ elif choice == 'both':
+ return True, True
+ elif choice == 'automatic':
+ if len(rails) == 2:
+ # Sample ten points along the rails. Compare the distance
+ # between corresponding points on both rails with and without
+ # one rail reversed. If the average distance between points
+ # with one rail reversed is less than without one reversed, then
+ # the user has probably accidentally reversed a rail.
+ lengths = []
+ lengths_reverse = []
+
+ for i in range(10):
+ distance = i / 10
+ point0 = rails[0].interpolate(distance, normalized=True)
+ point1 = rails[1].interpolate(distance, normalized=True)
+ point1_reverse = rails[1].interpolate(1 - distance, normalized=True)
+
+ lengths.append(point0.distance(point1))
+ lengths_reverse.append(point0.distance(point1_reverse))
+
+ debug.log(f"lengths: {lengths}")
+ debug.log(f"lengths_reverse: {lengths_reverse}")
+ if sum(lengths) > sum(lengths_reverse):
+ # reverse the second rail
+ return False, True
+
+ return None
@property
@param(
@@ -416,8 +461,11 @@ class SatinColumn(EmbroideryElement):
"""The rails, as LineStrings."""
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])
+ rails_to_reverse = self._get_rails_to_reverse(paths)
+ if paths and rails_to_reverse is not None:
+ for i, reverse in enumerate(rails_to_reverse):
+ if reverse:
+ paths[i] = shgeo.LineString(paths[i].coords[::-1])
return tuple(paths)