From c1b606feb4d9d4c890771638eeff4cde3393ffa2 Mon Sep 17 00:00:00 2001 From: jpcaram Date: Sun, 14 Dec 2014 19:03:04 -0500 Subject: [PATCH] Temporary fix/workaround for bug #83. Checking for empty list before running cascaded_union. --- camlib.py | 22 +++++++++++----------- setup_ubuntu.sh | 0 2 files changed, 11 insertions(+), 11 deletions(-) mode change 100644 => 100755 setup_ubuntu.sh diff --git a/camlib.py b/camlib.py index b462a143..53644bd5 100644 --- a/camlib.py +++ b/camlib.py @@ -1289,7 +1289,7 @@ class Gerber (Geometry): if quadrant_mode == 'MULTI': center = [i + current_x, j + current_y] - radius = sqrt(i**2 + j**2) + radius = sqrt(i ** 2 + j ** 2) start = arctan2(-j, -i) # Start angle # Numerical errors might prevent start == stop therefore # we check ahead of time. This should result in a @@ -1363,8 +1363,6 @@ class Gerber (Geometry): else: log.warning("Invalid arc in line %d." % line_num) - - ### Operation code alone # Operation code alone, usually just D03 (Flash) # self.opcode_re = re.compile(r'^D0?([123])\*$') @@ -1479,26 +1477,28 @@ class Gerber (Geometry): print "RE:", self.lpol_re.pattern print "MATCH:", self.lpol_re.search(gline) - match = self.lpol_re.search(gline) if match: if len(path) > 1 and current_polarity != match.group(1): # --- Buffered ---- width = self.apertures[last_path_aperture]["size"] - geo = LineString(path).buffer(width/2) + geo = LineString(path).buffer(width / 2) poly_buffer.append(geo) path = [path[-1]] # --- Apply buffer --- print "current_polarity:", current_polarity - if current_polarity == 'D': - print "Union with Cascaded Union of:", poly_buffer - self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer)) - else: - self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer)) - poly_buffer = [] + # If added for testing of bug #83 + # TODO: Remove when bug fixed + if len(poly_buffer) > 0: + if current_polarity == 'D': + print "Union with Cascaded Union of:", poly_buffer + self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer)) + else: + self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer)) + poly_buffer = [] current_polarity = match.group(1) continue diff --git a/setup_ubuntu.sh b/setup_ubuntu.sh old mode 100644 new mode 100755