32 lines
721 B
Python
32 lines
721 B
Python
from typing import Self
|
|
|
|
import math
|
|
|
|
class Vector:
|
|
x: int
|
|
y: int
|
|
|
|
def __init__(self, x: int, y: int):
|
|
self.x = x
|
|
self.y = y
|
|
|
|
def __add__(self, other: Self) -> Self:
|
|
return Vector(self.x + other.x, self.y + other.y)
|
|
|
|
def __sub__(self, other: Self) -> Self:
|
|
return Vector(self.x - other.x, self.y - other.y)
|
|
|
|
def abs(self) -> Self:
|
|
return Vector(abs(self.x), abs(self.y))
|
|
|
|
def __str__(self) -> str:
|
|
return f'{self.x}, {self.y}'
|
|
|
|
def __eq__(self, value: Self) -> bool:
|
|
return self.x == value.x and self.y == value.y
|
|
|
|
def distance(self, other: Self) -> int:
|
|
return math.sqrt((other.x - self.x)**2 + (other.y - self.y)**2)
|
|
|
|
|