int closestPoint ( Point2D_F64 target ) { double bestDistance = Double . MAX_VALUE ; int bestIndex = - 1 ; for ( int i = 0 ; i < contour . size ( ) ; i ++ ) { Point2D_I32 c = contour . get ( i ) ; double d = UtilPoint2D_F64 . distanceSq ( target . x , target . y , c . x , c . y ) ; if ( d < bestDistance ) { bestDistance = d ; bestIndex = i ; } } return bestIndex ; }
Returns the closest point on the contour to the provided point in space