diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2021-02-06 17:54:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-06 17:54:00 +0100 |
| commit | 40320ce7ee5d6cf3c74e5a018d4ecb33917a2ab1 (patch) | |
| tree | 0d8e7e51e48b2ceb6e025588ff2165827232bf36 | |
| parent | 364071fb0b632e7a347858747d1b8c1dda2a6a88 (diff) | |
reduce crossing border issues (#993)
| -rw-r--r-- | lib/elements/fill.py | 25 | ||||
| -rw-r--r-- | lib/extensions/auto_satin.py | 2 |
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/elements/fill.py b/lib/elements/fill.py index 83a224e4..2e94847a 100644 --- a/lib/elements/fill.py +++ b/lib/elements/fill.py @@ -138,22 +138,39 @@ class Fill(EmbroideryElement): paths.sort(key=lambda point_list: shgeo.Polygon(point_list).area, reverse=True) polygon = shgeo.MultiPolygon([(paths[0], paths[1:])]) + # There is a great number of "crossing border" errors on fill shapes + # If the polygon fails, we can try to run buffer(0) on the polygon in the + # hope it will fix at least some of them + if not self.shape_is_valid(polygon): + why = explain_validity(polygon) + message = re.match(r".+?(?=\[)", why) + if message.group(0) == "Self-intersection": + buffered = polygon.buffer(0) + # we do not want to break apart into multiple objects (possibly in the future?!) + # best way to distinguish the resulting polygon is to compare the area size of the two + # and make sure users will not experience significantly altered shapes without a warning + if math.isclose(polygon.area, buffered.area): + polygon = shgeo.MultiPolygon([buffered]) + return polygon - def validation_errors(self): + def shape_is_valid(self, shape): # Shapely will log to stdout to complain about the shape unless we make # it shut up. logger = logging.getLogger('shapely.geos') level = logger.level logger.setLevel(logging.CRITICAL) - valid = self.shape.is_valid + valid = shape.is_valid logger.setLevel(level) - if not valid: + return valid + + def validation_errors(self): + if not self.shape_is_valid(self.shape): why = explain_validity(self.shape) - message, x, y = re.findall(r".+?(?=\[)|-?\d+\.\d+", why) + message, x, y = re.findall(r".+?(?=\[)|-?\d+(?:\.\d+)?", why) # I Wish this weren't so brittle... if "Hole lies outside shell" in message: diff --git a/lib/extensions/auto_satin.py b/lib/extensions/auto_satin.py index 14fa1758..a447a493 100644 --- a/lib/extensions/auto_satin.py +++ b/lib/extensions/auto_satin.py @@ -2,7 +2,7 @@ import sys import inkex -from ..elements import SatinColumn +from ..elements import SatinColumn, Stroke from ..i18n import _ from ..stitches.auto_satin import auto_satin from .commands import CommandsExtension |
