gtn/engine/math.py

34 lines
833 B
Python

"""
Définis des classes utiles.
"""
class Vec2:
"""
Un vecteur 2D
"""
def __init__(self, x: float, y: float) -> None:
self.x = x
self.y = y
def __add__(self, other: "Vec2") -> "Vec2":
return Vec2(self.x + other.x, self.y + other.y)
def __sub__(self, other: "Vec2") -> "Vec2":
return Vec2(self.x - other.x, self.y - other.y)
def __mul__(self, other: "Vec2") -> "Vec2":
return Vec2(self.x * other.x, self.y * other.y)
def __div__(self, other: "Vec2") -> "Vec2":
return Vec2(self.x / other.x, self.y / other.y)
def __eq__(self, other: object) -> bool:
if isinstance(other, Vec2):
return self.x == other.x and self.y == other.y
return False
def __repr__(self) -> str:
return f"Vec2({self.x}, {self.y})"