basictypes: Catch zero division with virtical lines

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-02-14 14:44:35 +03:00
parent 131283890f
commit be1a2e5300
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -64,7 +64,10 @@ class StraightLine:
raise WallIDMismatch('Wall ID for points does not match') raise WallIDMismatch('Wall ID for points does not match')
def __find_line(self, p1:PointWithID, p2:PointWithID) -> tuple: def __find_line(self, p1:PointWithID, p2:PointWithID) -> tuple:
try:
m = (p2.get_y() - p1.get_y()) / (p2.get_x() - p1.get_x()) m = (p2.get_y() - p1.get_y()) / (p2.get_x() - p1.get_x())
except ZeroDivisionError:
m = None
# Using p1 to find b # Using p1 to find b
b = p1.get_y() - (m*p1.get_x()) b = p1.get_y() - (m*p1.get_x())
# y = mx + b # y = mx + b
@ -75,6 +78,9 @@ class StraightLine:
if p1.get_wallid() == p2.get_wallid(): return True if p1.get_wallid() == p2.get_wallid(): return True
return False return False
"""
Return slope for non-virtical line. None for virtical lines
"""
def get_m(self)-> float: def get_m(self)-> float:
return self.m return self.m