2024-12-08 14:39:16 -06:00

33 lines
791 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 inverse(self) -> Self:
return Vector(-self.x, -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)