import { distance } from 'common/util' ; export default class Vector { x : number ; y : number ; constructor ( x , y ) { this . x = x ; this . y = y ; } getMagnitude ( ) { return distance ( 0 , 0 , this . x , this . y ) ; } add ( v ) { return new Vector ( this . x + v . x , this . y + v . y ) ; } subtract ( v ) { return new Vector ( this . x - v . x , this . y - v . y ) ; } dotProduct ( v ) { return this . x * v . x + this . y * v . y ; } perpendicular ( ) { return new Vector ( this . y , - this . x ) ; } normalize ( ) { let d = this . getMagnitude ( ) ; return d ? new Vector ( this . x / d , this . y / d ) : new Vector ( 0 , 0 ) ; } }