basictypes: implement gety/x, line m/b

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-01-25 22:14:28 +03:00
parent 5461422c6b
commit 5d73bca7ba
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -18,10 +18,10 @@ class Point:
pass pass
def get_x(self) -> float: def get_x(self) -> float:
pass return self._x
def get_y(self) -> float: def get_y(self) -> float:
pass return self._y
def get_r(self) -> float: def get_r(self) -> float:
pass pass
@ -48,15 +48,24 @@ class PointWithID(Point):
class Line: class Line:
IDX_M = 0
IDX_B = 1
def __init__(self, p1: PointWithID, p2: PointWithID): def __init__(self, p1: PointWithID, p2: PointWithID):
self.wall_id = p1.get_wallid() self.wall_id = p1.get_wallid()
self.__find_slope(p1, p2) self.m, self.b = self.__find_line(p1, p2)
v = ValueError() v = ValueError()
if not self.__matching_wall_ids(p1, p2): if not self.__matching_wall_ids(p1, p2):
raise WallIDMismatch('Wall ID for points do not match') raise WallIDMismatch('Wall ID for points do not match')
def __find_slope(self, p1:PointWithID, p2:PointWithID) -> float: def __find_line(self, p1:PointWithID, p2:PointWithID) -> float:
pass # m = ((point2[1] - point1[1])/(point2[0] - point1[0]))
m = (p2.get_y() - p1.get_y()) / (p2.get_x() - p1.get_x())
# Using p1 to find b
b = p1.get_y() - (m*p1.get_x())
# y = mx + b
# b = y - mx
return m, b
def __matching_wall_ids(self, p1, p2) -> bool: def __matching_wall_ids(self, p1, p2) -> bool:
if p1.get_wallid() == p2.get_wallid(): return True if p1.get_wallid() == p2.get_wallid(): return True