import { MathX } from "../math/MathX"; export class Vector2 { x:number = 0; y:number = 0; constructor( x:number = 0, y:number = 0 ) { this.x = x; this.y = y; } clone():Vector2 { return new Vector2( this.x, this.y ); } set( x:number, y:number ) { this.x = x; this.y = y; } add( other:Vector2 ) { this.x += other.x; this.y += other.y; return this; } sub( other:Vector2 ) { this.x -= other.x; this.y -= other.y; return this; } multiply( value:number ) { this.x *= value; this.y *= value; return this; } get length() { return Math.sqrt( this.x * this.x + this.y * this.y ); } clampPolar( x:number, y:number) { this.x = MathX.clamp( this.x, -x, x ); this.y = MathX.clamp( this.y, -y, y ); } }