#pragma once
#include <cmath>

namespace MC {

struct Vec2 {
    double x = 0.0;
    double y = 0.0;

    Vec2() = default;
    Vec2(double x, double y) : x(x), y(y) {}

    Vec2  operator+(const Vec2& o) const { return {x + o.x, y + o.y}; }
    Vec2  operator-(const Vec2& o) const { return {x - o.x, y - o.y}; }
    Vec2  operator*(double s)      const { return {x * s,   y * s};   }
    Vec2& operator+=(const Vec2& o)      { x += o.x; y += o.y; return *this; }

    double dot(const Vec2& o)  const { return x * o.x + y * o.y; }
    double length()            const { return std::sqrt(x*x + y*y); }
    double lengthSq()          const { return x*x + y*y; }
    Vec2   normalized()        const { double l = length(); return l > 1e-9 ? Vec2{x/l, y/l} : Vec2{}; }

    double distanceTo(const Vec2& o) const { return (*this - o).length(); }

    // Rotate by angle (degrees)
    Vec2 rotated(double deg) const {
        double r = deg * M_PI / 180.0;
        double c = std::cos(r), s = std::sin(r);
        return { x*c - y*s, x*s + y*c };
    }
};

} // namespace MC
