/*
@return: Distance in kilometers between this src location and the specified destination
18266
public double calculateDistance(double srcLat, double srcLong, double destLat, double destLong) {
		float[] results = new float[1];
		Location.distanceBetween(srcLat, srcLong, destLat, destLong, results);
		return results[0] / 1000;
	}
1327374
public double pathLength (Configuration configuration) {
        double distance = 0.0;
        for (int i = 1; i < this.dimension; ++i) {
            distance += distances[configuration.valueAt(i - 1)][configuration.valueAt(i)];
        }
        distance += distances[configuration.valueAt(configuration.getDimension() - 1)][configuration.valueAt(0)];

        return distance;
    }
1204691
def geo_distance(a, b):
    """"""
    a_y = radians(a.y)
    b_y = radians(b.y)
    delta_x = radians(a.x - b.x)
    cos_x = (sin(a_y) * sin(b_y) +
             cos(a_y) * cos(b_y) * cos(delta_x))
    return acos(cos_x) * earth_radius_km
1071225
@Pure
	public double getLength() {
		double length = this.roadSegments.getLength();
		if (isValidPrimitive()) {
			BusItineraryHalt halt = this.validHalts.get(0);
			assert halt != null;
			RoadSegment sgmt = halt.getRoadSegment();
			assert sgmt != null;
			Direction1D dir = this.roadSegments.getRoadSegmentDirectionAt(halt.getRoadSegmentIndex());
			assert dir != null;
			if (dir == Direction1D.SEGMENT_DIRECTION) {
				length -= halt.getPositionOnSegment();
			} else {
				length -= sgmt.getLength() - halt.getPositionOnSegment();
			}

			halt = this.validHalts.get(this.validHalts.size() - 1);
			assert halt != null;
			sgmt = halt.getRoadSegment();
			assert sgmt != null;
			dir = this.roadSegments.getRoadSegmentDirectionAt(halt.getRoadSegmentIndex());
			assert dir != null;
			if (dir == Direction1D.SEGMENT_DIRECTION) {
				length -= sgmt.getLength() - halt.getPositionOnSegment();
			} else {
				length -= halt.getPositionOnSegment();
			}

			if (length < 0.) {
				length = 0.;
			}
		}
		return length;
	}
1258246
public int getManhattanDistance(Point2 that) {
    return Math.abs(x - that.x) + Math.abs(y - that.y);
  }
1229460
def distance_to(location)
      delta_latitude_radians = degrees_to_radians(location.latitude - latitude)
      delta_longitude_radians = degrees_to_radians(location.longitude - longitude)

      a = Math.sin(delta_latitude_radians/2)**2 +
          Math.cos(degrees_to_radians(latitude)) *
          Math.cos(degrees_to_radians(location.latitude)) *
          Math.sin(delta_longitude_radians/2)**2

      c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
      c * earth_radius_in_meters
    end
375320
private double distance(Instance inst1, Instance inst2)
	{
		double dist = 0.0;
		
		for(int i = 0 ; i < inst1.numAttributes() ; i++)
		{
			dist += Math.pow((inst1.value(i) - inst2.value(i)), 2.0);
		}
		
		return Math.sqrt(dist);
	}
1231945
function distance(from, to) {
  const degrees2radians = Math.PI / 180;
  const dLat = degrees2radians * (to[1] - from[1]);
  const dLon = degrees2radians * (to[0] - from[0]);
  const lat1 = degrees2radians * from[1];
  const lat2 = degrees2radians * to[1];

  const a = Math.pow(Math.sin(dLat / 2), 2) +
        Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
  return Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
1034249
function _getDistanceFromLastNewline(str, i) {
    var distance = i;
    var lastNewlineIndex = str.lastIndexOf('\n');
    if (lastNewlineIndex !== -1) {
        distance = (i - lastNewlineIndex - 1);
    }

    return distance;
}
846296
public double getDistance(final DBIDRef o1, final DBIDRef o2) {
    return FastMath.sqrt(getSquaredDistance(o1, o2));
  }
724013
def distance(self, other):
        
        return distance((self.separation, self.pa), (other.separation, other.pa))
337659
function damerauLevenshteinDistance(source, target) {
  if (!source || source.length === 0)
    if (!target || target.length === 0)
      return 0;
    else
      return target.length;
  else if (!target)
    return source.length;

  var sourceLength = source.length;
  var targetLength = target.length;
  var score = [];

  var INF = sourceLength + targetLength;
  score[0] = [INF];
  for (var i=0 ; i <= sourceLength ; i++) { score[i + 1] = []; score[i + 1][1] = i; score[i + 1][0] = INF; }
  for (var i=0 ; i <= targetLength ; i++) { score[1][i + 1] = i; score[0][i + 1] = INF; }

  var sd = {};
  var combinedStrings = source + target;
  var combinedStringsLength = combinedStrings.length;
  for(var i=0 ; i < combinedStringsLength ; i++) {
    var letter = combinedStrings[i];
    if (!sd.hasOwnProperty(letter))
      sd[letter] = 0;
  }

  for (var i=1 ; i <= sourceLength ; i++) {
    var DB = 0;
    for (var j=1 ; j <= targetLength ; j++) {
      var i1 = sd[target[j - 1]];
      var j1 = DB;

      if (source[i - 1] == target[j - 1]) {
        score[i + 1][j + 1] = score[i][j];
        DB = j;
      }
      else
        score[i + 1][j + 1] = Math.min(score[i][j], Math.min(score[i + 1][j], score[i][j + 1])) + 1;

      score[i + 1][j + 1] = Math.min(score[i + 1][j + 1], score[i1][j1] + (i - i1 - 1) + 1 + (j - j1 - 1));
    }
    sd[source[i - 1]] = i;
  }
  return score[sourceLength + 1][targetLength + 1];
}
80205
public final double getDistanceToKm(Position position) {
		double lat1 = toRadians(lat);
		double lat2 = toRadians(position.lat);
		double lon1 = toRadians(lon);
		double lon2 = toRadians(position.lon);
		double deltaLon = lon2 - lon1;
		double cosLat2 = cos(lat2);
		double cosLat1 = cos(lat1);
		double sinLat1 = sin(lat1);
		double sinLat2 = sin(lat2);
		double cosDeltaLon = cos(deltaLon);
		double top = sqrt(sqr(cosLat2 * sin(deltaLon))
				+ sqr(cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosDeltaLon));
		double bottom = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDeltaLon;
		double distance = radiusEarthKm * atan2(top, bottom);
		return abs(distance);
	}
829271
private static int _getDistance111 (@Nonnull final char [] aStr1,
                                      @Nonnegative final int nLen1,
                                      @Nonnull final char [] aStr2,
                                      @Nonnegative final int nLen2)
  {
    // previous cost array, horizontally
    int [] aPrevRow = new int [nLen1 + 1];

    // cost array, horizontally
    int [] aCurRow = new int [nLen1 + 1];

    // init
    for (int i = 0; i <= nLen1; i++)
      aPrevRow[i] = i;

    for (int j = 0; j < nLen2; j++)
    {
      final int ch2 = aStr2[j];
      aCurRow[0] = j + 1;

      for (int i = 0; i < nLen1; i++)
      {
        final int nSubstVal = aStr1[i] == ch2 ? 0 : 1;
        aCurRow[i + 1] = Math.min (Math.min (aCurRow[i] + 1, aPrevRow[i + 1] + 1), aPrevRow[i] + nSubstVal);
      }

      // swap current distance counts to 'previous row' distance counts
      final int [] tmp = aPrevRow;
      aPrevRow = aCurRow;
      aCurRow = tmp;
    }

    // our last action in the above loop was to switch d and p, so p now
    // actually has the most recent cost counts
    return aPrevRow[nLen1];
  }
158300
function distanceToFurthestCorner(x, y, rect) {
    var /** @type {?} */ distX = Math.max(Math.abs(x - rect.left), Math.abs(x - rect.right));
    var /** @type {?} */ distY = Math.max(Math.abs(y - rect.top), Math.abs(y - rect.bottom));
    return Math.sqrt(distX * distX + distY * distY);
}
42109
public double pathLength (Configuration configuration) {
        double distance = 0.0;
        for (int i = 1; i < this.dimension; ++i) {
            distance += this.cities.get(configuration.valueAt(i - 1)).getDistance(this.cities.get(configuration.valueAt(i)));
        }
        distance += this.cities.get(configuration.valueAt(configuration.getDimension() - 1))
                .getDistance(this.cities.get(configuration.valueAt(0)));

        return distance;
    }
1299577
public double getProjectedDistance(Atom point) {
		Atom projected = getProjectedPoint(point);
		if( projected == null) {
			// translation only
			return Double.NaN;
		}


		return Calc.getDistance(point, projected);

	}