import MathUtils from './common/detector/MathUtils' ; import Float from './util/Float' ; import { float , int } from '../customTypings' ; author Sean Owen
  export default class ResultPoint { public constructor ( private x , private y ) { } public getX ( ) { return this . x ; } public getY ( ) { return this . y ; } public equals ( other ) { if ( other instanceof ResultPoint ) { const otherPoint = < ResultPoint > other ; return this . x === otherPoint . x && this . y === otherPoint . y ; } return false ; } public hashCode ( ) { return 31 * Float . floatToIntBits ( this . x ) + Float . floatToIntBits ( this . y ) ; } public toString ( ) { return '(' + this . x + ',' + this . y + ')' ; } param patterns public static orderBestPatterns ( patterns ) { const zeroOneDistance = this . distance ( patterns [ 0 ] , patterns [ 1 ] ) ; const oneTwoDistance = this . distance ( patterns [ 1 ] , patterns [ 2 ] ) ; const zeroTwoDistance = this . distance ( patterns [ 0 ] , patterns [ 2 ] ) ; let pointA ; let pointB ; let pointC ; if ( oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance ) { pointB = patterns [ 0 ] ; pointA = patterns [ 1 ] ; pointC = patterns [ 2 ] ; } else if ( zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance ) { pointB = patterns [ 1 ] ; pointA = patterns [ 0 ] ; pointC = patterns [ 2 ] ; } else { pointB = patterns [ 2 ] ; pointA = patterns [ 0 ] ; pointC = patterns [ 1 ] ; } if ( this . crossProductZ ( pointA , pointB , pointC ) < 0.0 ) { const temp = pointA ; pointA = pointC ; pointC = temp ; } patterns [ 0 ] = pointA ; patterns [ 1 ] = pointB ; patterns [ 2 ] = pointC ; } param pattern1 param pattern2 return public static distance ( pattern1 , pattern2 ) { return MathUtils . distance ( pattern1 . x , pattern1 . y , pattern2 . x , pattern2 . y ) ; } /**
     * Returns the z component of the cross product between vectors BC and BA.
     */ private static crossProductZ ( pointA , pointB , pointC ) { const bX = pointB . x ; const bY = pointB . y ; return ( ( pointC . x - bX ) * ( pointA . y - bY ) ) - ( ( pointC . y - bY ) * ( pointA . x - bX ) ) ; } }