Maximum distance of two objects.

@param mbr1 First object
@param mbr2 Second object
195617
public double maxDist(SpatialComparable mbr1, SpatialComparable mbr2) {
    final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
    final int mindim = dim1 < dim2 ? dim1 : dim2;

    double agg = 0.;
    for(int d = 0; d < mindim; d++) {
      double d1 = mbr1.getMax(d) - mbr2.getMin(d);
      double d2 = mbr2.getMax(d) - mbr1.getMin(d);
      double delta = d1 > d2 ? d1 : d2;
      agg += delta * delta;
    }
    for(int d = mindim; d < dim1; d++) {
      double d1 = Math.abs(mbr1.getMin(d)), d2 = Math.abs(mbr1.getMax(d));
      double delta = d1 > d2 ? d1 : d2;
      agg += delta * delta;
    }
    for(int d = mindim; d < dim2; d++) {
      double d1 = Math.abs(mbr2.getMin(d)), d2 = Math.abs(mbr2.getMax(d));
      double delta = d1 > d2 ? d1 : d2;
      agg += delta * delta;
    }
    return FastMath.sqrt(agg);
  }
1038797
public static void limitDistance(DenseMatrix64F p0, DenseMatrix64F pr, double min, double max)
    {
        double x0 = p0.data[0];
        double y0 = p0.data[1];
        double xr = pr.data[0];
        double yr = pr.data[1];
        double dx = xr-x0;
        double dy = yr-y0;
        double r = Math.sqrt(dx*dx+dy*dy);
        if (r < min || r > max)
        {
            if (r < min)
            {
                r = min;
            }
            else
            {
                r = max;
            }
            double m = dy/dx;
            if (Double.isInfinite(m))
            {
                if (m > 0)
                {
                    pr.data[1] = y0 +  r;
                }
                else
                {
                    pr.data[1] = y0 -  r;
                }
            }
            else
            {
                double x = Math.sqrt((r*r)/(m*m+1));
                double y = m*x;
                pr.data[0] = x0 +  x;
                pr.data[1] = y0 +  y;
            }
        }
    }
266280
public static int distance(int index0, int index1, int size) {
		if( index0 > index1 ) {
			int tmp = index0;
			index0 = index1;
			index1 = tmp;
		}
		int distance0 = index1-index0;
		int distance1 = index0 + size-index1;
		if( distance0 < distance1)
			return distance0;
		else
			return distance1;
	}
722820
public double distance(Object pt1, Object pt2) {
		Object p = newCopy(pt1);
		subtract(p, pt2);
		return magnitude(p);
	}
1355595
private HyperBoundingBox mbr(final int[] entries, final int from, final int to) {
    SpatialEntry first = this.node.getEntry(entries[from]);
    ModifiableHyperBoundingBox mbr = new ModifiableHyperBoundingBox(first);
    for(int i = from + 1; i < to; i++) {
      mbr.extend(this.node.getEntry(entries[i]));
    }
    return mbr;
  }
739999
@Override
  public int compare(S solution1, S solution2) {
    int result = rankComparator.compare(solution1, solution2) ;
    if (result == 0) {
      result = crowdingDistanceComparator.compare(solution1, solution2);
    }

    return result;
  }
1216601
private static boolean compareDistance(final String title1, final String title2, int distance) {
        return StringUtils.getLevenshteinDistance(title1, title2) <= distance;
    }
64077
def skip_connection_distance(a, b):
    """"""
    if a[2] != b[2]:
        return 1.0
    len_a = abs(a[1] - a[0])
    len_b = abs(b[1] - b[0])
    return (abs(a[0] - b[0]) + abs(len_a - len_b)) / (max(a[0], b[0]) + max(len_a, len_b))
637884
def faster_minimum_distance2(hull_a, center_a, hull_b, center_b):
    '''
    
    '''
    #
    # Find the farthest vertex in b from some point within A. Find the
    # vertices within A visible from this point in B. If the point in A
    # is within B or the farthest vertex in B is within A, then the objects
    # intersect.
    #
    if within_hull(center_a, hull_b):
        return 0
    farthest_b = find_farthest(center_a, hull_b)
    if within_hull(hull_b[farthest_b,:], hull_a):
        return 0
    visible_b = find_visible(hull_b, center_a, farthest_b)
    #
    # Do the same for B
    if within_hull(center_b, hull_a):
        return 0
    farthest_a = find_farthest(center_b, hull_a)
    if within_hull(hull_a[farthest_a,:], hull_b):
        return 0
    visible_a = find_visible(hull_a, center_b, farthest_a)
    #
    # Now go from the first in A and last in B measuring distances
    # which should decrease as we move toward the best
    #
    i = visible_a[0]
    i_next = (i+1) % hull_a.shape[0]
    j = visible_b[1]
    j_next = (j+hull_b.shape[0]-1) % hull_b.shape[0]
    a = hull_a[i,:]
    a_next = hull_a[i_next,:]
    b = hull_b[j,:]
    b_next = hull_b[j_next,:]
    d2_min = np.sum((a-b)**2)
    
    while i != visible_a[1] and j != visible_b[0]:
        if lines_intersect(a, a_next, b, b_next):
            return 0
        if (np.dot(b-b_next,a-b_next) > 0 and
            np.dot(b_next-b,a-b) > 0):
            # do the edge if better than the vertex
            d2a = distance2_to_line(b, a, a_next)
        else:
            # try the next vertex of a
            d2a = np.sum((a_next-b)**2)
        if (np.dot(a-a_next,b-a_next) > 0 and
            np.dot(a_next-a,b-a) > 0):
            d2b = distance2_to_line(a, b, b_next)
        else:
            d2b = np.sum((b_next-a)**2)
        if d2a < d2_min and d2a < d2b:
            # The edge of A is closer than the best or the b-edge
            # Take it and advance A
            d2_min = d2a
            a = a_next
            i = i_next
            i_next = (i+1) % hull_a.shape[0]
            a_next = hull_a[i_next,:]
        elif d2b < d2_min:
            # B is better. Take it and advance
            d2_min = d2b
            b = b_next
            j = j_next
            j_next = (j+hull_b.shape[0]-1) % hull_b.shape[0]
            b_next = hull_b[j_next,:]
        else:
            return d2_min
    #
    # Some more to do... either one more i or one more j
    #
    while i != visible_a[1]:
        d2_min = min(d2_min, np.sum((a_next-b)**2))
        a = a_next
        i = i_next
        i_next = (i+1) % hull_a.shape[0]
        a_next = hull_a[i_next,:]
        
    while j != visible_b[0]:
        d2_min = min(d2_min, np.sum((b_next-a)**2))
        b = b_next
        j = j_next
        j_next = (j+ hull_b.shape[0]-1) % hull_b.shape[0]
        b_next = hull_b[j_next,:]
    return d2_min
389567
public static int distanceP(int index0, int index1, int size) {
		int difference = index1-index0;
		if( difference < 0 ) {
			difference = size+difference;
		}
		return difference;
	}
972639
public final double distance(E e1, E e2) {
    return distance(e1.getRoutingObjectID(), e2.getRoutingObjectID());
  }
1276597
private double preNormMBR(SpatialComparable mbr, final int start, final int end) {
    double agg = 0.;
    for(int d = start; d < end; d++) {
      double delta = mbr.getMin(d);
      delta = delta >= 0 ? delta : -mbr.getMax(d);
      if(delta > 0.) {
        agg += FastMath.pow(delta, p);
      }
    }
    return agg;
  }
888464
public static int compactDistance(String s1, String s2) {
    if (s1.length() == 0)
      return s2.length();
    if (s2.length() == 0)
      return s1.length();

    // the maximum edit distance there is any point in reporting.
    int maxdist = Math.min(s1.length(), s2.length()) / 2;
    
    // we allocate just one column instead of the entire matrix, in
    // order to save space.  this also enables us to implement the
    // algorithm somewhat faster.  the first cell is always the
    // virtual first row.
    int s1len = s1.length();
    int[] column = new int[s1len + 1];

    // first we need to fill in the initial column. we use a separate
    // loop for this, because in this case our basis for comparison is
    // not the previous column, but a virtual first column.
    int ix2 = 0;
    char ch2 = s2.charAt(ix2);
    column[0] = 1; // virtual first row
    for (int ix1 = 1; ix1 <= s1len; ix1++) {
      int cost = s1.charAt(ix1 - 1) == ch2 ? 0 : 1;

      // Lowest of three: above (column[ix1 - 1]), aboveleft: ix1 - 1,
      // left: ix1. Latter cannot possibly be lowest, so is
      // ignored.
      column[ix1] = Math.min(column[ix1 - 1], ix1 - 1) + cost;
    }

    // okay, now we have an initialized first column, and we can
    // compute the rest of the matrix.
    int above = 0;
    for (ix2 = 1; ix2 < s2.length(); ix2++) {
      ch2 = s2.charAt(ix2);
      above = ix2 + 1; // virtual first row

      int smallest = s1len * 2; // used to implement cutoff
      for (int ix1 = 1; ix1 <= s1len; ix1++) {
        int cost = s1.charAt(ix1 - 1) == ch2 ? 0 : 1;

        // above:     above
        // aboveleft: column[ix1 - 1]
        // left:      column[ix1]
        int value = Math.min(Math.min(above, column[ix1 - 1]), column[ix1]) +
                    cost;
        column[ix1 - 1] = above; // write previous
        above = value;           // keep current
        smallest = Math.min(smallest, value);
      }
      column[s1len] = above;

      // check if we can stop because we'll be going over the max distance
      if (smallest > maxdist)
        return smallest;
    }

    // ok, we're done
    return above;
  }
1160535
public static double getDistance(double x1, double y1, double x2, double y2, int w2, int h2)
    {
        final double maxX = x2 + w2;
        final double maxY = y2 + h2;

        double min = getDistance(x1, y1, x2, y2);
        for (double x = x2; Double.compare(x, maxX) <= 0; x++)
        {
            for (double y = y2; Double.compare(y, maxY) <= 0; y++)
            {
                final double dist = getDistance(x1, y1, x, y);
                if (dist < min)
                {
                    min = dist;
                }
            }
        }
        return min;
    }
707725
public static boolean overlaps(List<ByteBuffer> minColumnNames1, List<ByteBuffer> maxColumnNames1, List<ByteBuffer> minColumnNames2, List<ByteBuffer> maxColumnNames2, CellNameType comparator)
    {
        if (minColumnNames1.isEmpty() || maxColumnNames1.isEmpty() || minColumnNames2.isEmpty() || maxColumnNames2.isEmpty())
            return true;

        return !(compare(maxColumnNames1, minColumnNames2, comparator) < 0 || compare(minColumnNames1, maxColumnNames2, comparator) > 0);
    }
1071786
private static double distanceRadians(double lat1, double lng1, double lat2, double lng2) {
        return arcHav(havDistance(lat1, lat2, lng1 - lng2));
    }
436747
public static int distance (int x1, int y1, int x2, int y2) {
        return (int)Math.sqrt(distanceSq(x1, y1, x2, y2));
    }