From bd50c08b5db2b5a90c5b01af4eaf7ef0c713d4e4 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 28 Oct 2017 21:27:16 +0100 Subject: [PATCH] fix occasional failure of which_outline() --- embroider.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/embroider.py b/embroider.py index dbf07c1e9..09b89d13b 100644 --- a/embroider.py +++ b/embroider.py @@ -608,13 +608,14 @@ class AutoFill(Fill): outlines of the holes. """ - point = shgeo.Point(*coords) + # I'd use an intersection check, but floating point errors make it + # fail sometimes. - for i, outline in enumerate(self.shape.boundary): - # I'd use an intersection check, but floating point errors make it - # fail sometimes. - if outline.distance(point) < 0.00001: - return i + point = shgeo.Point(*coords) + outlines = list(enumerate(self.shape.boundary)) + closest = min(outlines, key=lambda (index, outline): outline.distance(point)) + + return closest[0] def project(self, coords, outline_index): """project the point onto the specified outline