From 5d764a68908bf905741f91e01c1250b5b64edc52 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Fri, 20 Feb 2015 13:57:19 -0200 Subject: Fix GerberFile.bounds when board origin is negative --- gerber/rs274x.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/gerber/rs274x.py b/gerber/rs274x.py index 2dee7cf..c5c89fb 100644 --- a/gerber/rs274x.py +++ b/gerber/rs274x.py @@ -88,22 +88,19 @@ class GerberFile(CamFile): @property def bounds(self): - xbounds = [0.0, 0.0] - ybounds = [0.0, 0.0] - for stmt in [stmt for stmt in self.statements - if isinstance(stmt, CoordStmt)]: + min_x = min_y = 1000000 + max_x = max_y = -1000000 + + for stmt in [stmt for stmt in self.statements if isinstance(stmt, CoordStmt)]: if stmt.x is not None: - if stmt.x < xbounds[0]: - xbounds[0] = stmt.x - elif stmt.x > xbounds[1]: - xbounds[1] = stmt.x + min_x = min(stmt.x, min_x) + max_x = max(stmt.x, max_x) + if stmt.y is not None: - if stmt.y < ybounds[0]: - ybounds[0] = stmt.y - elif stmt.y > ybounds[1]: - ybounds[1] = stmt.y - return (xbounds, ybounds) + min_y = min(stmt.y, min_y) + max_y = max(stmt.y, max_y) + return ((min_x, max_x), (min_y, max_y)) def write(self, filename, settings=None): """ Write data out to a gerber file -- cgit