45 lines
884 B
Python
45 lines
884 B
Python
from __future__ import annotations
|
|
|
|
class Vector2:
|
|
"""
|
|
Dvojdimenzionalni vektor
|
|
|
|
@Author: zbyv
|
|
@Date: 22.11.2023
|
|
"""
|
|
def __init__(self, x, y) -> None:
|
|
self.__x = x
|
|
self.__y = y
|
|
|
|
"""
|
|
`x` souradnice tohoto vektoru
|
|
"""
|
|
@property
|
|
def x(self):
|
|
return self.__x
|
|
|
|
"""
|
|
`y` souradnice tohoto vektoru
|
|
"""
|
|
@property
|
|
def y(self):
|
|
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) -> bool:
|
|
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}"
|