basictypes: StraightLine:

- Fix return type hint for __find_line()
	- Rename Line to StraightLine
	- Getters for m and b in StraightLine
	- intercept in StraightLine
		Find the intercept point of 2 Striaght lines

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-01-30 18:40:59 +03:00
parent 44ae995c2d
commit be9706fef8
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -51,7 +51,7 @@ class PointWithID(Point):
def get_wallid(self):
return self._wall_id
class Line:
class StraightLine:
IDX_M = 0
IDX_B = 1
@ -63,7 +63,7 @@ class Line:
if not self.__matching_wall_ids(p1, p2):
raise WallIDMismatch('Wall ID for points does not match')
def __find_line(self, p1:PointWithID, p2:PointWithID) -> float:
def __find_line(self, p1:PointWithID, p2:PointWithID) -> tuple:
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())
@ -75,6 +75,28 @@ class Line:
if p1.get_wallid() == p2.get_wallid(): return True
return False
def get_m(self)-> float:
return self.m
def get_b(self) -> float:
return self.b
def get_wall_id(self) -> str:
return self.wall_id
def intercept(self, line) -> Point:
# Basically when the two lines have the same cords (x,y)
# As a formula x = (b2 - b1)/ (m1 + m2) to find X, then apply y = mx + b on any line
x = (line.get_b() - self.get_b()) / (line.get_m() + line.get_m())
y = self.get_m()*x + self.get_b() # Inline to reduce overhead
return Point(x, y)
def intercept_list(self, lines) -> list:
# May return a sorted list based on distance
# Consider vectorized (SIMD) implmentaion with numpy
pass
class WallIDMismatch (RuntimeError): ...
# Helper methods