/* ────────────────────────────────────────────────────────────────
   Vec2 — 2D vector math utilities (pure functions)
──────────────────────────────────────────────────────────────── */
const v2 = {
    create(x = 0, y = 0) {
        return { x, y };
    },
    zero() {
        return { x: 0, y: 0 };
    },
    one() {
        return { x: 1, y: 1 };
    },
    clone(a) {
        return { x: a.x, y: a.y };
    },
    add(a, b) {
        return { x: a.x + b.x, y: a.y + b.y };
    },
    sub(a, b) {
        return { x: a.x - b.x, y: a.y - b.y };
    },
    mul(a, s) {
        return { x: a.x * s, y: a.y * s };
    },
    div(a, s) {
        return { x: a.x / s, y: a.y / s };
    },
    dot(a, b) {
        return a.x * b.x + a.y * b.y;
    },
    cross(a, b) {
        return a.x * b.y - a.y * b.x;
    },
    len(a) {
        return Math.sqrt(a.x * a.x + a.y * a.y);
    },
    lenSq(a) {
        return a.x * a.x + a.y * a.y;
    },
    normalize(a) {
        const l = v2.len(a);
        return l > 0 ? { x: a.x / l, y: a.y / l } : { x: 0, y: 0 };
    },
    dist(a, b) {
        const dx = a.x - b.x;
        const dy = a.y - b.y;
        return Math.sqrt(dx * dx + dy * dy);
    },
    distSq(a, b) {
        const dx = a.x - b.x;
        const dy = a.y - b.y;
        return dx * dx + dy * dy;
    },
    lerp(a, b, t) {
        return {
            x: a.x + (b.x - a.x) * t,
            y: a.y + (b.y - a.y) * t,
        };
    },
    rotate(a, angle) {
        const c = Math.cos(angle);
        const s = Math.sin(angle);
        return {
            x: a.x * c - a.y * s,
            y: a.x * s + a.y * c,
        };
    },
    angle(a) {
        return Math.atan2(a.y, a.x);
    },
    angleBetween(a, b) {
        return Math.atan2(b.y - a.y, b.x - a.x);
    },
    negate(a) {
        return { x: -a.x, y: -a.y };
    },
    perpCW(a) {
        return { x: a.y, y: -a.x };
    },
    perpCCW(a) {
        return { x: -a.y, y: a.x };
    },
    reflect(a, normal) {
        const d = 2 * v2.dot(a, normal);
        return { x: a.x - d * normal.x, y: a.y - d * normal.y };
    },
    equals(a, b, epsilon = 1e-6) {
        return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon;
    },
    min(a, b) {
        return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) };
    },
    max(a, b) {
        return { x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) };
    },
    clamp(v, min, max) {
        return {
            x: Math.max(min.x, Math.min(max.x, v.x)),
            y: Math.max(min.y, Math.min(max.y, v.y)),
        };
    },
    fromAngle(angle, length = 1) {
        return { x: Math.cos(angle) * length, y: Math.sin(angle) * length };
    },
    random(minLen = 0, maxLen = 1) {
        const angle = Math.random() * Math.PI * 2;
        const length = minLen + Math.random() * (maxLen - minLen);
        return v2.fromAngle(angle, length);
    },
};

export { v2 };
//# sourceMappingURL=math.js.map
