library-ts/browser/geometry/Vector2.ts

52 lines
656 B
TypeScript

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 );
}
}