generalize Element.shape and implement in all element types

pull/224/head
Lex Neva 2018-07-04 21:17:20 -04:00
rodzic d090fa0038
commit 62ef2850a2
4 zmienionych plików z 29 dodań i 0 usunięć

Wyświetl plik

@ -205,6 +205,10 @@ class EmbroideryElement(object):
def parse_path(self):
return apply_transforms(self.path, self.node)
@property
def shape(self):
raise NotImplementedError("INTERNAL ERROR: %s must implement shape()", self.__class__)
@property
@cache
def commands(self):

Wyświetl plik

@ -1,3 +1,5 @@
from shapely import geometry as shgeo
from .element import param, EmbroideryElement, Patch
from ..i18n import _
from ..utils.geometry import Point
@ -27,6 +29,11 @@ class Polyline(EmbroideryElement):
return points
@property
@cache
def shape(self):
return shgeo.LineString(self.points)
@property
def path(self):
# A polyline is a series of connected line segments described by their

Wyświetl plik

@ -87,6 +87,17 @@ class SatinColumn(EmbroideryElement):
# the edges of the satin column.
return self.get_float_param("zigzag_underlay_inset_mm") or self.contour_underlay_inset / 2.0
@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.
flattened = self.flatten(self.parse_path())
line_strings = [shgeo.LineString(path) for path in flattened]
return shgeo.MultiLineString(line_strings)
@property
@cache
def csp(self):

Wyświetl plik

@ -1,4 +1,5 @@
import sys
import shapely.geometry
from .element import param, EmbroideryElement, Patch
from ..i18n import _
@ -50,6 +51,12 @@ class Stroke(EmbroideryElement):
else:
return self.flatten(path)
@property
@cache
def shape(self):
line_strings = [shapely.geometry.LineString(path) for path in self.paths]
return shapely.geometry.MultiLineString(line_strings)
@property
@param('manual_stitch', _('Manual stitch placement'), tooltip=_("Stitch every node in the path. Stitch length and zig-zag spacing are ignored."), type='boolean', default=False)
def manual_stitch_mode(self):