From 27227e271d0f3ca9b1c78b0d8463f1bcddfa49eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 13 Jul 2016 12:50:16 +0200 Subject: [PATCH] Don't try to calculate min/max for empty bounding box --- src/octoprint/util/gcodeInterpreter.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index 3e06feec..f2e16c2b 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -132,6 +132,20 @@ class MinMax3D(object): True >>> minmax.size == Vector3D(1.0, 0.0, 1.0) True + >>> empty = MinMax3D() + >>> empty.size == Vector3D(0.0, 0.0, 0.0) + True + >>> partial = MinMax3D() + >>> partial.record(Vector3D(2.0, None, 2.0)) + >>> partial.min.x == 2.0 == partial.max.x and partial.min.y == None == partial.max.y and partial.min.z == 2.0 == partial.max.z + True + >>> partial.record(Vector3D(1.0, None, 3.0)) + >>> partial.min.x == 1.0 and partial.min.y == None and partial.min.z == 2.0 + True + >>> partial.max.x == 2.0 and partial.max.y == None and partial.max.z == 3.0 + True + >>> partial.size == Vector3D(1.0, 0.0, 1.0) + True """ def __init__(self): @@ -139,7 +153,7 @@ class MinMax3D(object): self.max = Vector3D(None, None, None) def record(self, coordinate): - for c in ("x", "y", "z"): + for c in "xyz": current_min = getattr(self.min, c) current_max = getattr(self.max, c) value = getattr(coordinate, c) @@ -148,7 +162,13 @@ class MinMax3D(object): @property def size(self): - return abs(self.max - self.min) + result = Vector3D() + for c in "xyz": + min = getattr(self.min, c) + max = getattr(self.max, c) + value = abs(max - min) if min is not None and max is not None else 0.0 + setattr(result, c, value) + return result class AnalysisAborted(Exception):