private static void sort ( double [ ] coords1 , int length1 , double [ ] coords2 , int length2 , int [ ] array ) { int temp ; int length = length1 + length2 ; double x1 , y1 , x2 , y2 ; for ( int i = 1 ; i < length ; i ++ ) { if ( array [ i - 1 ] < length1 ) { x1 = coords1 [ 2 * array [ i - 1 ] ] ; y1 = coords1 [ 2 * array [ i - 1 ] + 1 ] ; } else { x1 = coords2 [ 2 * ( array [ i - 1 ] - length1 ) ] ; y1 = coords2 [ 2 * ( array [ i - 1 ] - length1 ) + 1 ] ; } if ( array [ i ] < length1 ) { x2 = coords1 [ 2 * array [ i ] ] ; y2 = coords1 [ 2 * array [ i ] + 1 ] ; } else { x2 = coords2 [ 2 * ( array [ i ] - length1 ) ] ; y2 = coords2 [ 2 * ( array [ i ] - length1 ) + 1 ] ; } int j = i ; while ( j > 0 && compare ( x1 , y1 , x2 , y2 ) <= 0 ) { temp = array [ j ] ; array [ j ] = array [ j - 1 ] ; array [ j - 1 ] = temp ; j -- ; if ( j > 0 ) { if ( array [ j - 1 ] < length1 ) { x1 = coords1 [ 2 * array [ j - 1 ] ] ; y1 = coords1 [ 2 * array [ j - 1 ] + 1 ] ; } else { x1 = coords2 [ 2 * ( array [ j - 1 ] - length1 ) ] ; y1 = coords2 [ 2 * ( array [ j - 1 ] - length1 ) + 1 ] ; } if ( array [ j ] < length1 ) { x2 = coords1 [ 2 * array [ j ] ] ; y2 = coords1 [ 2 * array [ j ] + 1 ] ; } else { x2 = coords2 [ 2 * ( array [ j ] - length1 ) ] ; y2 = coords2 [ 2 * ( array [ j ] - length1 ) + 1 ] ; } } } } }
the array sorting