diff options
| author | Lex Neva <github.com@lexneva.name> | 2019-06-19 14:47:11 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2019-06-22 18:12:50 -0400 |
| commit | ebb4ebb42ccc89631e6d5830460f455c86e97af7 (patch) | |
| tree | fd4cb1594b9621712ed56bb3ac9566d31eee628a /lib/elements | |
| parent | 68609cc912d76e8e51258eeea9999542cb2f0e94 (diff) | |
rework fill shape parsing code (fixes #469)
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/fill.py | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/lib/elements/fill.py b/lib/elements/fill.py index 357adf4b..4bdfa3ff 100644 --- a/lib/elements/fill.py +++ b/lib/elements/fill.py @@ -104,34 +104,12 @@ class Fill(EmbroideryElement): @property @cache def shape(self): - poly_ary = [] - for sub_path in self.paths: - point_ary = [] - last_pt = None - for pt in sub_path: - if (last_pt is not None): - vp = (pt[0] - last_pt[0], pt[1] - last_pt[1]) - dp = math.sqrt(math.pow(vp[0], 2.0) + math.pow(vp[1], 2.0)) - # dbg.write("dp %s\n" % dp) - if (dp > 0.01): - # I think too-close points confuse shapely. - point_ary.append(pt) - last_pt = pt - else: - last_pt = pt - if len(point_ary) > 2: - poly_ary.append(point_ary) - - if not poly_ary: - self.fatal(_("shape %s is so small that it cannot be filled with stitches. Please make it bigger or delete it.") % self.node.get('id')) - # shapely's idea of "holes" are to subtract everything in the second set # from the first. So let's at least make sure the "first" thing is the # biggest path. - # TODO: actually figure out which things are holes and which are shells - poly_ary.sort(key=lambda point_list: shgeo.Polygon(point_list).area, reverse=True) - - polygon = shgeo.MultiPolygon([(poly_ary[0], poly_ary[1:])]) + paths = self.paths + paths.sort(key=lambda point_list: shgeo.Polygon(point_list).area, reverse=True) + polygon = shgeo.MultiPolygon([(paths[0], paths[1:])]) if not polygon.is_valid: self.fatal(_("shape is not valid. This can happen if the border crosses over itself.")) |
