export class Vector2 { constructor( public x: number = 0, public y: number = 0 ) {} static fromArray(arr: number[]): Vector2 { return new Vector2(arr[0], arr[1]); } toArray(): [number, number] { return [this.x, this.y]; } add(other: Vector2): Vector2 { return new Vector2(this.x + other.x, this.y + other.y); } subtract(other: Vector2): Vector2 { return new Vector2(this.x - other.x, this.y - other.y); } multiply(scalar: number): Vector2 { return new Vector2(this.x * scalar, this.y * scalar); } length(): number { return Math.sqrt(this.x * this.x + this.y * this.y); } normalize(): Vector2 { const len = this.length(); if (len === 0) return new Vector2(); return this.multiply(1 / len); } distance(other: Vector2): number { return this.subtract(other).length(); } }