game: add: goal work

This commit is contained in:
2024-02-08 12:38:56 +01:00
committed by AdrienLSH
parent ef9b918130
commit c60d0ba08b
5 changed files with 150 additions and 71 deletions

View File

@ -1,13 +1,23 @@
from .Point import Point
from .Vector import Vector
import math
class Segment:
def __init__(self, start: Point, stop: Point) -> None:
self.start: Point = start
self.stop: Point = stop
self.length: float = math.dist((self.start.x, self.start.y), (self.stop.x, self.stop.y))
def angle(self):
return math.atan2((self.start.x - self.start.y), (self.stop.x - self.stop.y))
def length(self):
return self.start.distance(self.stop)
def is_on(self, C: Point):
return (self.start.distance(C) + self.stop.distance(C) == self.length())
def __repr__(self) -> str:
return f"Segment(start: {self.start}, stop: {self.stop})"
@ -18,7 +28,7 @@ class Segment:
def copy(self):
return Segment(self.start.copy(), self.stop.copy())
def to_dict(self):
def to_dict(self) -> dict:
data: dict[str: dict] = {
"start": self.start.to_dict(),