static Edge selectClosest ( NodeInfo a , NodeInfo b , boolean checkSide ) { double bestScore = Double . MAX_VALUE ; Edge bestEdgeA = null ; Edge edgeAB = a . findEdge ( b ) ; double distAB = a . distance ( b ) ; if ( edgeAB == null ) { return null ; // TODO BUG! FIX! } for ( int i = 0 ; i < a . edges . size ; i ++ ) { Edge edgeA = a . edges . get ( i ) ; NodeInfo aa = a . edges . get ( i ) . target ; if ( aa . marked ) continue ; for ( int j = 0 ; j < b . edges . size ; j ++ ) { Edge edgeB = b . edges . get ( j ) ; NodeInfo bb = b . edges . get ( j ) . target ; if ( bb . marked ) continue ; if ( aa == bb ) { // System.out.println("center "+aa.ellipse.center); if ( checkSide && UtilAngle . distanceCW ( edgeAB . angle , edgeA . angle ) > Math . PI * 0.75 ) continue ; double angle = UtilAngle . dist ( edgeA . angle , edgeB . angle ) ; if ( angle < 0.3 ) continue ; double da = EllipsesIntoClusters . axisAdjustedDistanceSq ( a . ellipse , aa . ellipse ) ; double db = EllipsesIntoClusters . axisAdjustedDistanceSq ( b . ellipse , aa . ellipse ) ; da = Math . sqrt ( da ) ; db = Math . sqrt ( db ) ; // see if they are approximately the same distance double diffRatio = Math . abs ( da - db ) / Math . max ( da , db ) ; if ( diffRatio > 0.3 ) continue ; // TODO reject if too far double d = ( da + db ) / distAB + 0.1 * angle ; if ( d < bestScore ) { bestScore = d ; bestEdgeA = a . edges . get ( i ) ; } break ; } } } return bestEdgeA ; }
Finds the closest that is the same distance from the two nodes and part of an approximate equilateral triangle