public boolean process ( List < Point2D_I32 > contour ) { // Reset internal book keeping variables reset ( ) ; if ( loops ) { // Reject pathological case if ( contour . size ( ) < 3 ) return false ; if ( ! findInitialTriangle ( contour ) ) return false ; } else { // Reject pathological case if ( contour . size ( ) < 2 ) return false ; // two end points are the seeds. Plus they can't change addCorner ( 0 ) ; addCorner ( contour . size ( ) - 1 ) ; initializeScore ( contour , false ) ; } savePolyline ( ) ; sequentialSideFit ( contour , loops ) ; if ( fatalError ) return false ; int MIN_SIZE = loops ? 3 : 2 ; double bestScore = Double . MAX_VALUE ; int bestSize = - 1 ; for ( int i = 0 ; i < Math . min ( maxSides - ( MIN_SIZE - 1 ) , polylines . size ) ; i ++ ) { if ( polylines . get ( i ) . score < bestScore ) { bestPolyline = polylines . get ( i ) ; bestScore = bestPolyline . score ; bestSize = i + MIN_SIZE ; } } // There was no good match within the min/max size requirement if ( bestSize < minSides ) { return false ; } // make sure all the sides are within error tolerance for ( int i = 0 , j = bestSize - 1 ; i < bestSize ; j = i , i ++ ) { Point2D_I32 a = contour . get ( bestPolyline . splits . get ( i ) ) ; Point2D_I32 b = contour . get ( bestPolyline . splits . get ( j ) ) ; double length = a . distance ( b ) ; double thresholdSideError = this . maxSideError . compute ( length ) ; if ( bestPolyline . sideErrors . get ( i ) >= thresholdSideError * thresholdSideError ) { bestPolyline = null ; return false ; } } return true ; }
Process the contour and returns true if a polyline could be found .