private void connectInSameElement ( List < LineSegment2D_F32 > lines ) { for ( int i = 0 ; i < lines . size ( ) ; i ++ ) { LineSegment2D_F32 a = lines . get ( i ) ; int index = findBestCompatible ( a , lines , i + 1 ) ; if ( index == - 1 ) continue ; // remove the line from the index which it is being connected to LineSegment2D_F32 b = lines . remove ( index ) ; // join the two lines by connecting the farthest points from each other Point2D_F32 pt0 = farthestIndex < 2 ? a . a : a . b ; Point2D_F32 pt1 = ( farthestIndex % 2 ) == 0 ? b . a : b . b ; a . a . set ( pt0 ) ; a . b . set ( pt1 ) ; } }
Search for lines in the same region for it to be connected to .