diff options
Diffstat (limited to 'lib/elements/element.py')
| -rw-r--r-- | lib/elements/element.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py index 75d22580..8ff821e2 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_lr_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_lr_mm_param_as_px(self, param, default): + return self.get_lr_float_param(param, default) * PIXELS_PER_MM + def set_param(self, name, value): param = INKSTITCH_ATTRIBS[name] self.node.set(param, str(value)) |
