private boolean connectTry ( LineSegment2D_F32 target , int x , int y ) { if ( ! grid . isInBounds ( x , y ) ) return false ; List < LineSegment2D_F32 > lines = grid . get ( x , y ) ; int index = findBestCompatible ( target , lines , 0 ) ; if ( index == - 1 ) return false ; LineSegment2D_F32 b = lines . remove ( index ) ; // join the two lines by connecting the farthest points from each other Point2D_F32 pt0 = farthestIndex < 2 ? target . a : target . b ; Point2D_F32 pt1 = ( farthestIndex % 2 ) == 0 ? b . a : b . b ; target . a . set ( pt0 ) ; target . b . set ( pt1 ) ; // adding the merged one back in allows it to be merged with other lines down // the line. It will be compared against others in 'target's grid though lines . add ( target ) ; return true ; }
See if there is a line that matches in this adjacent region .