diff options
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/empty_d_object.py | 3 | ||||
| -rw-r--r-- | lib/elements/polyline.py | 21 | ||||
| -rw-r--r-- | lib/elements/satin_column.py | 5 | ||||
| -rw-r--r-- | lib/elements/stroke.py | 11 |
4 files changed, 17 insertions, 23 deletions
diff --git a/lib/elements/empty_d_object.py b/lib/elements/empty_d_object.py index 3c24f333..82583683 100644 --- a/lib/elements/empty_d_object.py +++ b/lib/elements/empty_d_object.py @@ -23,5 +23,8 @@ class EmptyDObject(EmbroideryElement): label = self.node.get(INKSCAPE_LABEL) or self.node.get("id") yield EmptyD((0, 0), label) + def shape(self): + return + def to_stitch_groups(self, last_patch): return [] diff --git a/lib/elements/polyline.py b/lib/elements/polyline.py index e923aac0..5086c705 100644 --- a/lib/elements/polyline.py +++ b/lib/elements/polyline.py @@ -47,19 +47,9 @@ class Polyline(EmbroideryElement): return self.get_boolean_param("polyline") @property - def points(self): - # example: "1,2 0,0 1.5,3 4,2" - - points = self.node.get('points').strip() - points = points.split(" ") - points = [[float(coord) for coord in point.split(",")] for point in points] - - return points - - @property @cache def shape(self): - return shgeo.LineString(self.points) + return shgeo.LineString(self.path) @property def path(self): @@ -68,9 +58,12 @@ class Polyline(EmbroideryElement): # svg transforms that is in our superclass, we'll convert the polyline # to a degenerate cubic superpath in which the bezier handles are on # the segment endpoints. - path = self.node.get_path() + if self.node.get('points', None): + path = self.node.get_path() + else: + # Set path to (0, 0) for empty polylines + path = 'M 0 0' path = Path(path).to_superpath() - return path @property @@ -99,7 +92,7 @@ class Polyline(EmbroideryElement): return stitches def validation_warnings(self): - yield PolylineWarning(self.points[0]) + yield PolylineWarning(self.path[0][0][0]) def to_stitch_groups(self, last_patch): patch = StitchGroup(color=self.color) diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index a30f16d4..83080003 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -216,10 +216,7 @@ class SatinColumn(EmbroideryElement): # 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. - flattened = self.flatten(self.parse_path()) - line_strings = [shgeo.LineString(path) for path in flattened] - - return shgeo.MultiLineString(line_strings) + return shgeo.MultiLineString(self.flattened_rails).convex_hull @property @cache diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py index c9c0f795..7113bf3f 100644 --- a/lib/elements/stroke.py +++ b/lib/elements/stroke.py @@ -87,7 +87,7 @@ class Stroke(EmbroideryElement): # manipulate invalid path if len(flattened[0]) == 1: - return [[[flattened[0][0][0], flattened[0][0][1]], [flattened[0][0][0]+1.0, flattened[0][0][1]]]] + return [[[flattened[0][0][0], flattened[0][0][1]], [flattened[0][0][0] + 1.0, flattened[0][0][1]]]] if self.manual_stitch_mode: return [self.strip_control_points(subpath) for subpath in path] @@ -97,12 +97,13 @@ class Stroke(EmbroideryElement): @property @cache def shape(self): + return self.as_multi_line_string().convex_hull + + @cache + def as_multi_line_string(self): line_strings = [shapely.geometry.LineString(path) for path in self.paths] - # Using convex_hull here is an important optimization. Otherwise - # complex paths cause operations on the shape to take a long time. - # This especially happens when importing machine embroidery files. - return shapely.geometry.MultiLineString(line_strings).convex_hull + return shapely.geometry.MultiLineString(line_strings) @property @param('manual_stitch', |
