From be1a2e5300fc92b95fc1d7a185167861719281fa Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 14 Feb 2022 14:44:35 +0300 Subject: [PATCH] basictypes: Catch zero division with virtical lines Signed-off-by: HeshamTB --- basictypes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/basictypes.py b/basictypes.py index 0e049e4..281401d 100644 --- a/basictypes.py +++ b/basictypes.py @@ -64,7 +64,10 @@ class StraightLine: raise WallIDMismatch('Wall ID for points does not match') def __find_line(self, p1:PointWithID, p2:PointWithID) -> tuple: - m = (p2.get_y() - p1.get_y()) / (p2.get_x() - p1.get_x()) + try: + m = (p2.get_y() - p1.get_y()) / (p2.get_x() - p1.get_x()) + except ZeroDivisionError: + m = None # Using p1 to find b b = p1.get_y() - (m*p1.get_x()) # y = mx + b @@ -75,6 +78,9 @@ class StraightLine: if p1.get_wallid() == p2.get_wallid(): return True return False + """ + Return slope for non-virtical line. None for virtical lines + """ def get_m(self)-> float: return self.m