class Vector2D:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    # norma, normalizacja, w. normalny, ortogonalny
    def norm(self):
        # return (self.x ** 2 + self.y ** 2) ** 0.5
        return (self * self) ** 0.5

    def normalize(self):
        n = self.norm()
        if n == 0:
            raise ZeroDivisionError("Cannot normalize a null vector")
        self.x /= n
        self.y /= n

    def normalized(self):
        new_vector = Vector2D(self.x, self.y)
        new_vector.normalize()
        return new_vector

    def get_orthogonal(self):
        return Vector2D(self.y, -self.x)

    # tutaj operacje arytmetyczne na wektorach:
    # dodawanie ...
    def __add__(self, other_vector):
        new_vector = Vector2D(self.x + other_vector.x, self.y + other_vector.y)
        return new_vector

    def __neg__(self):
        # jednoargumentowy minus
        return Vector2D(-self.x, -self.y)

    def __sub__(self, other_vector):
        # operator odejmowania
        return self + (-other_vector)

    def __mul__(self, other_vector):
        # iloczyn skalarny, operator *
        return self.x * other_vector.x + self.y * other_vector.y

    def __rmul__(self, t):
        # mnozenie wektora przez skalar. self jest wektorem z PRAWEJ
        # strony wyrazenia postaci a * b, a other to drugi operand
        # tego mnozenia - zakładamy, ze jest to liczba (ozn. t - skalar)
        return Vector2D(t * self.x, t * self.y)

    def __matmul__(self, other):
        # __matmul__ to operator @, uzyjemy go do zdefiniowania
        # wyznacznika macierzy rozpietej przez dwa wektory
        return self.x * other.y - self.y * other.x

    def __str__(self):
        # string reprezentujacy wektor
        return f"Vector2D({self.x}, {self.y})"

    def __eq__(self, other_vector):
        return (self.x, self.y) == (other_vector.x, other_vector.y)


if __name__ == "__main__":
    v = Vector2D(3, 4)
    w = Vector2D(2, 1)
    print(w + v)
    print(w - v)
    print(w * v)
    print(w @ v)
    print(v + w == Vector2D(5, 5))

