kopia lustrzana https://github.com/inkstitch/inkstitch
break into subpaths
rodzic
0efca6dd97
commit
270688a709
|
@ -3,7 +3,7 @@
|
||||||
# Copyright (c) 2010 Authors
|
# Copyright (c) 2010 Authors
|
||||||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||||
|
|
||||||
import inkex
|
from inkex import Path, errormsg
|
||||||
from shapely.geometry import LineString, MultiPolygon, Polygon
|
from shapely.geometry import LineString, MultiPolygon, Polygon
|
||||||
|
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
|
@ -22,7 +22,7 @@ class Outline(InkstitchExtension):
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
if not self.svg.selection:
|
if not self.svg.selection:
|
||||||
inkex.errormsg(_("Please select one or more shapes to convert to their outline."))
|
errormsg(_("Please select one or more shapes to convert to their outline."))
|
||||||
return
|
return
|
||||||
|
|
||||||
self.threshold = self.options.threshold * PIXELS_PER_MM
|
self.threshold = self.options.threshold * PIXELS_PER_MM
|
||||||
|
@ -38,20 +38,22 @@ class Outline(InkstitchExtension):
|
||||||
self.element_to_outline(element)
|
self.element_to_outline(element)
|
||||||
return
|
return
|
||||||
|
|
||||||
path = element.get_path()
|
|
||||||
path = path.end_points
|
|
||||||
shape = LineString(path).buffer(self.shape_buffer)
|
|
||||||
|
|
||||||
interiors = []
|
|
||||||
for interior in shape.interiors:
|
|
||||||
if Polygon(interior).area < self.threshold:
|
|
||||||
continue
|
|
||||||
interior_path = smooth_path(interior.coords, self.smoothness)
|
|
||||||
if len(interior_path) > 2:
|
|
||||||
interiors.append(Polygon(interior_path))
|
|
||||||
outline = MultiPolygon([Polygon(smooth_path(shape.exterior.coords, self.smoothness))] + interiors)
|
|
||||||
|
|
||||||
d = ''
|
d = ''
|
||||||
for geom in outline.geoms:
|
transform = element.composed_transform()
|
||||||
d += str(inkex.Path(geom.exterior.coords))
|
path = element.get_path().transform(transform).break_apart()
|
||||||
|
for subpath in path:
|
||||||
|
points = subpath.end_points
|
||||||
|
shape = LineString(points).buffer(self.shape_buffer)
|
||||||
|
|
||||||
|
interiors = []
|
||||||
|
for interior in shape.interiors:
|
||||||
|
if Polygon(interior).area < self.threshold:
|
||||||
|
continue
|
||||||
|
interior_path = smooth_path(interior.coords, self.smoothness)
|
||||||
|
if len(interior_path) > 2:
|
||||||
|
interiors.append(Polygon(interior_path))
|
||||||
|
outline = MultiPolygon([Polygon(smooth_path(shape.exterior.coords, self.smoothness))] + interiors)
|
||||||
|
|
||||||
|
for geom in outline.geoms:
|
||||||
|
d += str(Path(geom.exterior.coords).transform(-transform))
|
||||||
element.set('d', d)
|
element.set('d', d)
|
||||||
|
|
Ładowanie…
Reference in New Issue