summaryrefslogtreecommitdiff
path: root/lib/elements
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2019-07-28 10:02:28 +0200
committerGitHub <noreply@github.com>2019-07-28 10:02:28 +0200
commitd5e873f8c50789b94e24d27a30c72f65ba9c08a3 (patch)
treeffa31c0f808f67857cdf7f86ecd2a9da41590a06 /lib/elements
parent833a8a971d8a73fbc42468a89d083e37a0bd6d8d (diff)
parente81e819602a3823ec344d412ba2e5213349fb2c4 (diff)
Merge pull request #481
show various bugs the door
Diffstat (limited to 'lib/elements')
-rw-r--r--lib/elements/element.py3
-rw-r--r--lib/elements/fill.py39
-rw-r--r--lib/elements/satin_column.py4
-rw-r--r--lib/elements/utils.py2
4 files changed, 20 insertions, 28 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 10b1852a..e85657cd 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -283,5 +283,6 @@ class EmbroideryElement(object):
# L10N used when showing an error message to the user such as
# "Some Path (path1234): error: satin column: One or more of the rungs doesn't intersect both rails."
- print >> sys.stderr, "%s: %s %s" % (name, _("error:"), message.encode("UTF-8"))
+ error_msg = "%s: %s %s" % (name, _("error:"), message)
+ print >> sys.stderr, "%s" % (error_msg.encode("UTF-8"))
sys.exit(1)
diff --git a/lib/elements/fill.py b/lib/elements/fill.py
index 357adf4b..7ccf7b27 100644
--- a/lib/elements/fill.py
+++ b/lib/elements/fill.py
@@ -1,6 +1,7 @@
import math
from shapely import geometry as shgeo
+from shapely.validation import explain_validity
from ..i18n import _
from ..stitches import legacy_fill
@@ -104,37 +105,23 @@ 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."))
+ why = explain_validity(polygon)
+
+ # I Wish this weren't so brittle...
+ if "Hole lies outside shell" in why:
+ self.fatal(_("this object is made up of unconnected shapes. This is not allowed because "
+ "Ink/Stitch doesn't know what order to stitch them in. Please break this "
+ "object up into separate shapes."))
+ else:
+ self.fatal(_("shape is not valid. This can happen if the border crosses over itself."))
return polygon
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index bfa39384..d3c4d3d3 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -325,6 +325,10 @@ class SatinColumn(EmbroideryElement):
self.fatal(_("satin column: object %s has a fill (but should not)") % node_id)
if not self.rungs:
+ if len(self.rails) < 2:
+ self.fatal(_("satin column: object %(id)s has too few paths. A satin column should have at least two paths (the rails).") %
+ dict(id=node_id))
+
if len(self.rails[0]) != len(self.rails[1]):
self.fatal(_("satin column: object %(id)s has two paths with an unequal number of points (%(length1)d and %(length2)d)") %
dict(id=node_id, length1=len(self.rails[0]), length2=len(self.rails[1])))
diff --git a/lib/elements/utils.py b/lib/elements/utils.py
index 87dfa877..5c71de2e 100644
--- a/lib/elements/utils.py
+++ b/lib/elements/utils.py
@@ -16,7 +16,7 @@ def node_to_elements(node):
elif node.tag == SVG_PATH_TAG:
element = EmbroideryElement(node)
- if element.get_boolean_param("satin_column"):
+ if element.get_boolean_param("satin_column") and element.get_style("stroke"):
return [SatinColumn(node)]
else:
elements = []