public static double maximizeCountInSpread ( double [ ] data , int size , double maxSpread ) { if ( size <= 0 ) return 0 ; Arrays . sort ( data , 0 , size ) ; int length = 0 ; for ( ; length < size ; length ++ ) { double s = UtilAngle . dist ( data [ 0 ] , data [ length ] ) ; if ( s > maxSpread ) { break ; } } int bestStart = 0 ; int bestLength = length ; int start ; for ( start = 1 ; start < size && length < size ; start ++ ) { length -- ; while ( length < size ) { double s = UtilAngle . dist ( data [ start ] , data [ ( start + length ) % size ] ) ; if ( s > maxSpread ) { break ; } else { length ++ ; } } if ( length > bestLength ) { bestLength = length ; bestStart = start ; } } return data [ ( bestStart + bestLength / 2 ) % size ] ; }
Finds the value which has the largest number of points above and below it within the specified spread