42_ft_transcendence/games/objects/Segment.py
2024-03-31 10:59:33 +02:00

28 lines
762 B
Python

from .Point import Point
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 __repr__(self) -> str:
return f"Segment(start: {self.start}, stop: {self.stop})"
def __str__(self) -> str:
return f"Segment(start: {self.start}, stop: {self.stop})"
def copy(self):
return Segment(self.start.copy(), self.stop.copy())
def to_dict(self):
data: dict[str: dict] = {
"start": self.start.to_dict(),
"stop": self.stop.to_dict(),
}
return data