summaryrefslogtreecommitdiff
path: root/lib/elements/element.py
diff options
context:
space:
mode:
authorGeorge Steel <george.steel@gmail.com>2022-11-24 21:14:26 -0500
committerGitHub <noreply@github.com>2022-11-24 21:14:26 -0500
commitac655910eb4d283e3c00b27260fd1d2dbecd903e (patch)
tree87134bfa73b0a5461b88584145f80d7e9c150d15 /lib/elements/element.py
parentdf4c5cd59b0e391048c8fd2271893dbd49ec7cd3 (diff)
parent81168fd299c27b1f6a7c5ed62a3a5ca3ff95acbb (diff)
Merge pull request #1897 from inkstitch/george-steel/pull-comp-percent
Add proportional and asymmetric pull compensation and underlay inset options to satin columns, plus a param to swap the 2 rails.
Diffstat (limited to 'lib/elements/element.py')
-rw-r--r--lib/elements/element.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 75d22580..96949ca3 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -5,6 +5,7 @@
import sys
from copy import deepcopy
+import numpy as np
import inkex
from inkex import bezier
@@ -135,6 +136,32 @@ class EmbroideryElement(object):
return value
+ # returns 2 float values as a numpy array
+ # if a single number is given in the param, it will apply to both returned values.
+ # Not cached the cache will crash if the default is a numpy array.
+ # The ppoperty calling this will need to cache itself and can safely do so since it has no parameters
+ def get_split_float_param(self, param, default=(0, 0)):
+ default = np.array(default) # type coersion in case the default is a tuple
+
+ raw = self.get_param(param, "")
+ parts = raw.split()
+ try:
+ if len(parts) == 0:
+ return default
+ elif len(parts) == 1:
+ a = float(parts[0])
+ return np.array([a, a])
+ else:
+ a = float(parts[0])
+ b = float(parts[1])
+ return np.array([a, b])
+ except (TypeError, ValueError):
+ return default
+
+ # not cached
+ def get_split_mm_param_as_px(self, param, default):
+ return self.get_split_float_param(param, default) * PIXELS_PER_MM
+
def set_param(self, name, value):
param = INKSTITCH_ATTRIBS[name]
self.node.set(param, str(value))