/* * Copyright (C) 2026 Ortega Froysa, Nicolás * Author: Ortega Froysa, Nicolás * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include template class Vec { public: T x, y; Vec() : x(0), y(0) {} Vec(T x, T y) : x(x), y(y) {} inline void set(T x, T y) { this->x = x; this->y = y; } inline T length() const { return std::sqrt(static_cast(x * x + y * y)); } inline Vec normalized() const { const T len = length(); if (len == 0) return Vec(0, 0); return Vec(x / len, y / len); } inline Vec& operator+=(const Vec &other) { this->x += other.x; this->y += other.y; return *this; } inline Vec& operator*=(const T scalar) { this->x *= scalar; this->y *= scalar; return *this; } inline Vec operator+(const Vec &other) const { return Vec(this->x + other.x, this->y + other.y); } inline Vec operator+(const T scalar) const { return Vec(this->x + scalar, this->y + scalar); } inline Vec& operator-=(const Vec &other) { this->x -= other.x; this->y -= other.y; return *this; } inline Vec& operator-=(const T scalar) { this->x -= scalar; this->y -= scalar; return *this; } inline Vec operator-(const Vec &other) const { return Vec(this->x - other.x, this->y - other.y); } inline Vec operator-(const T scalar) const { return Vec(this->x - scalar, this->y - scalar); } inline Vec operator*(const T scalar) const { return Vec(this->x * scalar, this->y * scalar); } inline Vec operator/(const T scalar) const { return Vec(this->x / scalar, this->y / scalar); } };