From 65cb5bf875932d439cb503e17ae325ad23e7d187 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 27 Oct 2016 22:09:59 -0400 Subject: simplify polygon sorting --- embroider.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'embroider.py') diff --git a/embroider.py b/embroider.py index b4434742..2f1dfb1c 100644 --- a/embroider.py +++ b/embroider.py @@ -120,24 +120,6 @@ def flatten(path, flatness): return flattened -def bboxarea(poly): - x0=None - x1=None - y0=None - y1=None - for pt in poly: - if (x0==None or pt[0]x1): x1 = pt[0] - if (y0==None or pt[1]y1): y1 = pt[1] - return (x1-x0)*(y1-y0) - -def area(poly): - return bboxarea(poly) - -def byarea(a,b): - return -cmp(area(a), area(b)) - def cspToShapelyPolygon(path): poly_ary = [] for sub_path in path: @@ -158,7 +140,8 @@ def cspToShapelyPolygon(path): # 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. - poly_ary.sort(byarea) + # 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:])]) #print >> sys.stderr, "polygon valid:", polygon.is_valid -- cgit v1.2.3