From 217baefaf73ff2cb7a61863079ce976a06a66f98 Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Fri, 1 Jan 2021 23:17:38 +0100 Subject: [PATCH 1/3] [FIX] Handle a null point use case --- pycam/Geometry/PointUtils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pycam/Geometry/PointUtils.py b/pycam/Geometry/PointUtils.py index 234afd23..7b59d8fd 100644 --- a/pycam/Geometry/PointUtils.py +++ b/pycam/Geometry/PointUtils.py @@ -76,6 +76,8 @@ def ptransform_by_matrix(a, matrix): def pmul(a, c): c = number(c) + if not a: + return (False, False, False) return (a[0] * c, a[1] * c, a[2] * c) @@ -85,6 +87,13 @@ def pdiv(a, c): def padd(a, b): + if not (a and b): + if a: + return (a[0], a[1], a[2]) + elif b: + return (b[0], b[1], b[2]) + else: + return (None, None, None) return (a[0] + b[0], a[1] + b[1], a[2] + b[2]) From 4a365be1f754c1d5acf03d15ec8ce07bc2a1ea42 Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Fri, 1 Jan 2021 23:18:20 +0100 Subject: [PATCH 2/3] [FIX] Avoid "Division by 0" traceback --- pycam/Geometry/Line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycam/Geometry/Line.py b/pycam/Geometry/Line.py index c0f1572e..92222bdd 100644 --- a/pycam/Geometry/Line.py +++ b/pycam/Geometry/Line.py @@ -189,9 +189,9 @@ def get_intersection(self, line, infinite_lines=False): return None, None # the lines are on one straight candidates = [] - if self.is_point_inside(x3): + if self.is_point_inside(x3) and pnorm(a) != 0: candidates.append((x3, pnorm(c) / pnorm(a))) - elif self.is_point_inside(x4): + elif self.is_point_inside(x4) and pnorm(a) != 0: candidates.append((x4, pdist(line.p2, self.p1) / pnorm(a))) elif line.is_point_inside(x1): candidates.append((x1, 0)) From a904af4c21f90446af9c2ef93f497779fab49869 Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Fri, 1 Jan 2021 23:19:51 +0100 Subject: [PATCH 3/3] [IMP] Handle small lines OpenSCAD handle circles as polygon. setting a high enough number of polygon and a small enough diameter generate really small, but non null, lines. --- pycam/Geometry/Polygon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycam/Geometry/Polygon.py b/pycam/Geometry/Polygon.py index c2457970..c5111cbb 100644 --- a/pycam/Geometry/Polygon.py +++ b/pycam/Geometry/Polygon.py @@ -231,8 +231,8 @@ def copy(self): def append(self, line): if not self.is_connectable(line): raise ValueError("This line does not fit to the polygon") - elif line.len < epsilon: - raise ValueError("A line with zero length may not be part of a polygon") + # elif line.len < epsilon: + # raise ValueError("A line with zero length may not be part of a polygon") else: if not self._points: self._points.append(line.p1)