protected int optimize ( List < Point2D_I32 > contour , int c0 , int c1 , int c2 ) { double bestDistance = computeCost ( contour , c0 , c1 , c2 , 0 ) ; int bestIndex = 0 ; for ( int i = - searchRadius ; i <= searchRadius ; i ++ ) { if ( i == 0 ) { // if it found a better point in the first half stop the search since that's probably the correct // direction. Could be improved by remember past search direction if ( bestIndex != 0 ) break ; } else { double found = computeCost ( contour , c0 , c1 , c2 , i ) ; if ( found < bestDistance ) { bestDistance = found ; bestIndex = i ; } } } return CircularIndex . addOffset ( c1 , bestIndex , contour . size ( ) ) ; }
Searches around the current c1 point for the best place to put the corner