import { IPoint } from "../interfaces/IPoint" ; export class MathUtil { public static getDistance ( sourcePoint , targetPoint ) { return Math . sqrt ( Math . pow ( sourcePoint . x - targetPoint . x , 2 ) + Math . pow ( sourcePoint . y - targetPoint . y , 2 ) ) ; } public static subtract ( sourcePoint , targetPoint ) { return { x : targetPoint . x - sourcePoint . x , y : targetPoint . y - sourcePoint . y } ; } public static scale ( point , factor ) { return { x : point . x / factor , y : point . y / factor } ; } public static getLength ( point ) { return Math . sqrt ( point . x * point . x + point . y * point . y ) ; } public static normalize ( vector ) { const vectorLength = MathUtil . getLength ( vector ) ; return MathUtil . scale ( vector , vectorLength ) ; } }