bludiste/vector2.py
2023-11-22 21:43:16 +01:00

48 lines
1002 B
Python

from __future__ import annotations
class Vector2:
"""
Dvojdimenzionalni vektor
@Author: zbyv
@Date: 22.11.2023
"""
def __init__(self, x: int, y: int) -> None:
self.__x = x
self.__y = y
"""
`x` souradnice tohoto vektoru
"""
@property
def x(self) -> int:
return self.__x
"""
`y` souradnice tohoto vektoru
"""
@property
def y(self) -> int:
return self.__y
"""
Kouzelna metoda pro soucet vektoru
"""
def __add__(self, other: Vector2) -> Vector2:
return Vector2(self.x + other.x, self.y + other.y)
"""
Kouzelna metoda pro porovnani vektoru
"""
def __eq__(self, other: object) -> bool:
if not isinstance(other, Vector2):
return NotImplemented
return self.x == other.x and self.y == other.y
"""
Kouzelna metoda pro prevod vektoru na str
"""
def __str__(self) -> str:
return f"{self.x}; {self.y}"