From 02dbc6a51e2ef417f2bd41d6159ba53cc736535d Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 21 Feb 2016 10:23:03 +0800 Subject: Additional bounding box calcuation that considers only actual positions, not the movement of the machine --- gerber/rs274x.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gerber/rs274x.py') diff --git a/gerber/rs274x.py b/gerber/rs274x.py index 92f4c4b..4ab5472 100644 --- a/gerber/rs274x.py +++ b/gerber/rs274x.py @@ -110,6 +110,21 @@ class GerberFile(CamFile): max_y = max(stmt.y, max_y) return ((min_x, max_x), (min_y, max_y)) + + @property + def bounding_box(self): + min_x = min_y = 1000000 + max_x = max_y = -1000000 + + for prim in self.primitives: + bounds = prim.bounding_box + min_x = min(bounds[0][0], min_x) + max_x = max(bounds[0][1], max_x) + + min_y = min(bounds[1][0], min_y) + max_y = max(bounds[1][1], 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