kopia lustrzana https://github.com/inkstitch/inkstitch
Merge pull request #732 from inkstitch/kaalleen/fix-break-apart-small-path-issue
fix break apart small path issuepull/792/head
commit
e5e16edc0d
|
@ -21,7 +21,7 @@ class BreakApart(InkstitchExtension):
|
|||
InkstitchExtension.__init__(self, *args, **kwargs)
|
||||
self.OptionParser.add_option("-m", "--method", type="int", default=1, dest="method")
|
||||
|
||||
def effect(self):
|
||||
def effect(self): # noqa: C901
|
||||
if not self.selected:
|
||||
inkex.errormsg(_("Please select one or more fill areas to break apart."))
|
||||
return
|
||||
|
@ -38,10 +38,13 @@ class BreakApart(InkstitchExtension):
|
|||
|
||||
# we don't want to touch valid elements
|
||||
paths = element.flatten(element.parse_path())
|
||||
try:
|
||||
paths.sort(key=lambda point_list: Polygon(point_list).area, reverse=True)
|
||||
polygon = MultiPolygon([(paths[0], paths[1:])])
|
||||
if self.geom_is_valid(polygon):
|
||||
continue
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
polygons = self.break_apart_paths(paths)
|
||||
polygons = self.ensure_minimum_size(polygons, 5)
|
||||
|
@ -54,13 +57,15 @@ class BreakApart(InkstitchExtension):
|
|||
def break_apart_paths(self, paths):
|
||||
polygons = []
|
||||
for path in paths:
|
||||
if len(path) < 3:
|
||||
continue
|
||||
linestring = LineString(path)
|
||||
polygon = Polygon(path).buffer(0)
|
||||
if not linestring.is_simple:
|
||||
linestring = unary_union(linestring)
|
||||
for polygon in polygonize(linestring):
|
||||
polygons.append(polygon)
|
||||
else:
|
||||
polygon = Polygon(path).buffer(0)
|
||||
polygons.append(polygon)
|
||||
return polygons
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue