import { Random } from "./random" ; export { Vector } ; /**
 * Immutable
 */ class Vector { constructor ( private _x , private _y ) { } public add ( otherVector ) { return new Vector ( this . _x + otherVector . _x , this . _y + otherVector . _y ) ; } public subtract ( otherVector ) { return new Vector ( this . _x - otherVector . _x , this . _y - otherVector . _y ) ; } public x ( ) { return this . _x ; } public y ( ) { return this . _y ; } param amount public scale ( amount ) { return new Vector ( this . _x * amount , this . _y * amount ) ; } param otherPoint public dist ( otherPoint ) { return Math . abs ( Math . sqrt ( Math . pow ( otherPoint . _x - this . _x , 2 ) + Math . pow ( otherPoint . _y - this . _y , 2 ) ) ) ; } public midpoint ( otherPoint ) { return new Vector ( ( otherPoint . _x + this . _x ) / 2 , ( otherPoint . _y + this . _y ) / 2 ) ; } public normal ( ) { return this . scale ( 1.0 / this . magnitude ( ) ) ; } public magnitude ( ) { return Math . sqrt ( Math . pow ( this . _x , 2 ) + Math . pow ( this . _y , 2 ) ) ; } public static random ( seed ) { return new Vector ( seed . nextFloat ( ) , seed . nextFloat ( ) ) ; } public static one ( ) { return new Vector ( 1.0 , 1.0 ) ; } public static fromAngle ( angle ) { return new Vector ( Math . cos ( angle ) , Math . sin ( angle ) ) ; } }