protected double distanceSum ( LineGeneral2D_F64 line , int c0 , int c1 , List < Point2D_I32 > contour ) { double total = 0 ; if ( c0 < c1 ) { int length = c1 - c0 + 1 ; int samples = Math . min ( maxLineSamples , length ) ; for ( int i = 0 ; i < samples ; i ++ ) { int index = c0 + i * ( length - 1 ) / ( samples - 1 ) ; total += distance ( line , contour . get ( index ) ) ; } } else { int lengthFirst = contour . size ( ) - c0 ; int lengthSecond = c1 + 1 ; int length = lengthFirst + c1 + 1 ; int samples = Math . min ( maxLineSamples , length ) ; int samplesFirst = samples * lengthFirst / length ; int samplesSecond = samples * lengthSecond / length ; for ( int i = 0 ; i < samplesFirst ; i ++ ) { int index = c0 + i * lengthFirst / ( samples - 1 ) ; total += distance ( line , contour . get ( index ) ) ; } for ( int i = 0 ; i < samplesSecond ; i ++ ) { int index = i * lengthSecond / ( samples - 1 ) ; total += distance ( line , contour . get ( index ) ) ; } } return total ; }
Sum of Euclidean distance of contour points along the line