From 5d73bca7ba1c491fd2386eb20b86fcdbc04d1037 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Tue, 25 Jan 2022 22:14:28 +0300 Subject: [PATCH] basictypes: implement gety/x, line m/b Signed-off-by: HeshamTB --- basictypes.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/basictypes.py b/basictypes.py index c59dac3..4d3055c 100644 --- a/basictypes.py +++ b/basictypes.py @@ -18,10 +18,10 @@ class Point: pass def get_x(self) -> float: - pass + return self._x def get_y(self) -> float: - pass + return self._y def get_r(self) -> float: pass @@ -48,15 +48,24 @@ class PointWithID(Point): class Line: + IDX_M = 0 + IDX_B = 1 + def __init__(self, p1: PointWithID, p2: PointWithID): self.wall_id = p1.get_wallid() - self.__find_slope(p1, p2) + self.m, self.b = self.__find_line(p1, p2) v = ValueError() if not self.__matching_wall_ids(p1, p2): raise WallIDMismatch('Wall ID for points do not match') - def __find_slope(self, p1:PointWithID, p2:PointWithID) -> float: - pass + def __find_line(self, p1:PointWithID, p2:PointWithID) -> float: + # 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: if p1.get_wallid() == p2.get_wallid(): return True