boolean increaseNumberOfSidesByOne ( List < Point2D_I32 > contour , boolean loops ) { // System.out.println("increase number of sides by one. list = "+list.size()); Element < Corner > selected = selectCornerToSplit ( loops ) ; // No side can be split if ( selected == null ) return false ; // Update the corner who's side was just split selected . object . sideError = selected . object . splitError0 ; // split the selected side and add a new corner Corner c = corners . grow ( ) ; c . reset ( ) ; c . index = selected . object . splitLocation ; c . sideError = selected . object . splitError1 ; Element < Corner > cornerE = list . insertAfter ( selected , c ) ; // see if the new side could be convex if ( convex && ! isSideConvex ( contour , selected ) ) return false ; else { // compute the score for sides which just changed computePotentialSplitScore ( contour , cornerE , list . size ( ) < minSides ) ; computePotentialSplitScore ( contour , selected , list . size ( ) < minSides ) ; // Save the results // printCurrent(contour); savePolyline ( ) ; return true ; } }
Increase the number of sides in the polyline . This is done greedily selecting the side which would improve the score by the most of it was split .