mklines: find intercept of last line in a list

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-02-14 15:33:53 +03:00
parent 4c4366a5d1
commit dc42010f0b
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -31,8 +31,13 @@ def main():
print('line ', line.get_m(), line.get_b()) print('line ', line.get_m(), line.get_b())
intercepts = list() intercepts = list()
for i, line in enumerate(lines): for i, line in enumerate(lines):
if i == len(lines) - 1: break # Last line is a special case p = None # This is risky
p = lines[i].intercept(lines[i+1]) if i == len(lines) - 1:
print("last")
p = lines[i].intercept(lines[0])
# Last line is a special case
else:
p = lines[i].intercept(lines[i+1])
print(p.get_x(), p.get_y()) print(p.get_x(), p.get_y())
return 0 return 0