dockered
This commit is contained in:
38
django/games/objects/pong/Segment.py
Normal file
38
django/games/objects/pong/Segment.py
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
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
|
||||
|
||||
def angle(self) -> float:
|
||||
return math.atan2((self.start.y - self.stop.y), (self.start.x - self.stop.x))
|
||||
|
||||
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})"
|
||||
|
||||
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) -> dict:
|
||||
|
||||
data: dict[str: dict] = {
|
||||
"start": self.start.to_dict(),
|
||||
"stop": self.stop.to_dict(),
|
||||
}
|
||||
|
||||
return data
|
Reference in New Issue
Block a user