class Vector2 { constructor(x = 0, y = 0) { this.x = x; this.y = y; } static from(obj) { return new Vector2(obj.x, obj.y); } copy() { return new Vector2(this.x, this.y); } add(vector) { return new Vector2(this.x + vector.x, this.y + vector.y); } subtract(vector) { return new Vector2(this.x - vector.x, this.y - vector.y); } multiply(scalar) { return new Vector2(this.x * scalar, this.y * scalar); } divide(scalar) { return new Vector2(this.x / scalar, this.y / scalar); } magnitude() { return Math.sqrt(this.x * this.x + this.y * this.y); } normalize() { const mag = this.magnitude(); if (mag === 0) return new Vector2(0, 0); return this.divide(mag); } distance(vector) { const dx = this.x - vector.x; const dy = this.y - vector.y; return Math.sqrt(dx * dx + dy * dy); } dot(vector) { return this.x * vector.x + this.y * vector.y; } angle() { return Math.atan2(this.y, this.x); } static fromAngle(angle, magnitude = 1) { return new Vector2( Math.cos(angle) * magnitude, Math.sin(angle) * magnitude ); } lerp(target, t) { return new Vector2( this.x + (target.x - this.x) * t, this.y + (target.y - this.y) * t ); } limit(maxMagnitude) { const mag = this.magnitude(); if (mag > maxMagnitude) { return this.normalize().multiply(maxMagnitude); } return this.copy(); } }