export class Vector2 {
    x;
    y;
    static zero = Object.freeze(new Vector2(0, 0));
    static one = Object.freeze(new Vector2(1, 1));
    constructor(x = 0, y = 0) {
        this.x = x;
        this.y = y;
    }
    clone() {
        return new Vector2(this.x, this.y);
    }
    add(v) {
        return new Vector2(this.x + v.x, this.y + v.y);
    }
    subtract(v) {
        return new Vector2(this.x - v.x, this.y - v.y);
    }
    multiplyScalar(scalar) {
        return new Vector2(this.x * scalar, this.y * scalar);
    }
    divide(v) {
        return new Vector2(this.x / v.x, this.y / v.y);
    }
    divideScalar(scalar) {
        return new Vector2(this.x / scalar, this.y / scalar);
    }
    dot(v) {
        return this.x * v.x + this.y * v.y;
    }
    lengthSquared() {
        return this.dot(this);
    }
    length() {
        return Math.hypot(this.x, this.y);
    }
    normalize() {
        const len = this.length();
        return len === 0 ? Vector2.zero.clone() : this.multiplyScalar(1 / len);
    }
    distanceTo(v) {
        return this.subtract(v).length();
    }
    lerp(v, t) {
        return new Vector2(this.x + (v.x - this.x) * t, this.y + (v.y - this.y) * t);
    }
    equals(v, epsilon = 1e-10) {
        return Math.abs(this.x - v.x) <= epsilon && Math.abs(this.y - v.y) <= epsilon;
    }
    toArray() {
        return [this.x, this.y];
    }
}
//# sourceMappingURL=Vector2.js.map