#pragma once #include template struct Vec { T x; T y; // template explicit operator Vec() { return Vec{.x = x, .y = y}; } // Vec &operator-() { x = -x; y = -y; return *this; } Vec &operator*=(const T &value) { x *= value; y *= value; return *this; } Vec &operator/=(const T &value) { x /= value; y /= value; return *this; } Vec operator*(const T &value) const { auto copy = Vec{*this}; copy *= value; return copy; } Vec operator/(const T &value) const { auto copy = Vec{*this}; copy /= value; return copy; } // Vec &operator+=(const Vec &other) { x += other.x; y += other.y; return *this; } Vec &operator-=(const Vec &other) { x -= other.x; y -= other.y; return *this; } Vec operator+(const Vec &other) const { auto copy = Vec{*this}; copy += other; return copy; } Vec operator-(const Vec &other) const { auto copy = Vec{*this}; copy -= other; return copy; } // bool operator==(const Vec &other) const = default; bool operator!=(const Vec &other) const = default; // int len_sq() const { return dot(*this, *this); } double len() const { return std::sqrt(len_sq()); } Vec norm() { return Vec(*this) / len(); } // int static dot(Vec left, Vec right) { return left.x * right.x + left.y * right.y; } int static cross(Vec left, Vec right) { return left.x * right.y - left.y * right.x; } }; using Veci = Vec; using Vecf = Vec;