Compute the fractional distance from P to GN where the point intersects the region's boundary
333005
static double fractionCauchyToGN(double lengthCauchy , double lengthGN , double lengthPtoGN, double region ) {

		// First triangle has 3 known sides
		double a=lengthGN,b=lengthCauchy,c=lengthPtoGN;

		// Law of cosine to find angle for side GN (a.k.a 'a')
		double cosineA = (a*a - b*b - c*c)/(-2.0*b*c);
		double angleA = Math.acos(cosineA);

		// In the second triangle, that is now being considered, lengthP is known and the side which intersects
		// the region boundary is known, but we need to solve for the length from P to the intersection
		// with the boundary
		a=region;
		double angleB = Math.asin((b/a)*Math.sin(angleA));
		double angleC = Math.PI-angleA-angleB;
		c = Math.sqrt(a*a + b*b - 2.0*a*b*Math.cos(angleC));

		return c/lengthPtoGN;
	}
477259
private void boundaryLineBoundaryLine_(int half_edge, int id_a, int id_b,
			int cluster_index_a, int cluster_index_b) {
		if (m_matrix[MatrixPredicate.BoundaryBoundary] == 0)
			return;

		if (m_topo_graph.getHalfEdgeUserIndex(m_topo_graph
				.getHalfEdgePrev(m_topo_graph.getHalfEdgeTwin(half_edge)),
				m_visited_index) != 1) {
			int cluster = m_topo_graph.getHalfEdgeTo(half_edge);
			int clusterParentage = m_topo_graph.getClusterParentage(cluster);

			if ((clusterParentage & id_a) != 0
					&& (clusterParentage & id_b) != 0) {
				int index_a = m_topo_graph.getClusterUserIndex(cluster,
						cluster_index_a);
				int index_b = m_topo_graph.getClusterUserIndex(cluster,
						cluster_index_b);
				assert (index_a != -1);
				assert (index_b != -1);

				if ((index_a % 2 != 0) && (index_b % 2 != 0)) {
					assert ((m_topo_graph.getClusterParentage(cluster) & id_a) != 0 && (m_topo_graph
							.getClusterParentage(cluster) & id_b) != 0);
					m_matrix[MatrixPredicate.BoundaryBoundary] = 0;
				}
			}
		}
	}
969682
function calculateTouchesDistance(startPoint, endPoint) {
			var diffX = Math.abs(startPoint.x - endPoint.x);
			var diffY = Math.abs(startPoint.y - endPoint.y);
				
			return Math.round(Math.sqrt(diffX*diffX+diffY*diffY));
		}
927238
public long gridDistance(int x, int y) {
        return Math.abs(x - x()) + Math.abs(y - y());
    }
355917
function(p, opt) {

            var segments = this.segments;
            var numSegments = segments.length;
            if (numSegments === 0) return null; // if segments is an empty array

            opt = opt || {};
            var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
            var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
            // not using localOpt

            var closestPointT;
            var minSquaredDistance = Infinity;
            for (var i = 0; i < numSegments; i++) {

                var segment = segments[i];
                var subdivisions = segmentSubdivisions[i];

                if (segment.isVisible) {
                    var segmentClosestPointT = segment.closestPointT(p, { precision: precision, subdivisions: subdivisions });
                    var segmentClosestPoint = segment.pointAtT(segmentClosestPointT);
                    var squaredDistance = (new Line(segmentClosestPoint, p)).squaredLength();

                    if (squaredDistance < minSquaredDistance) {
                        closestPointT = { segmentIndex: i, value: segmentClosestPointT };
                        minSquaredDistance = squaredDistance;
                    }
                }
            }

            if (closestPointT) return closestPointT;

            // if no visible segment, return end of last segment
            return { segmentIndex: numSegments - 1, value: 1 };
        }
144602
public static double JaccardDistance(double[] p, double[] q) {
        double distance = 0;
        int intersection = 0, union = 0;

        for (int x = 0; x < p.length; x++) {
            if ((p[x] != 0) || (q[x] != 0)) {
                if (p[x] == q[x]) {
                    intersection++;
                }

                union++;
            }
        }

        if (union != 0)
            distance = 1.0 - ((double) intersection / (double) union);
        else
            distance = 0;

        return distance;
    }
538639
public static float pointRectDistance (IRectangle r, IPoint p) {
        return FloatMath.sqrt(pointRectDistanceSq(r, p));
    }
1166382
def _compute_distance(self, rup, dists, C):
        
        rval = np.sqrt(dists.repi ** 2 + C['h'] ** 2)
        return C['c1'] * np.log10(rval)
433655
public int findClosest( P p , double maxDistance ) {
		int best = -1;
		bestDistance = maxDistance;

		for( int i = 0; i < points.size(); i++ ) {
			P c = points.get(i);

			double distanceC = distance.distance(p,c);

			if( distanceC <= bestDistance ) {
				bestDistance = distanceC;
				best = i;
			}
		}

		return best;
	}
316124
private void boundaryLineExteriorLine_(int half_edge, int id_a, int id_b,
			int cluster_index_a, int predicate) {
		if (m_matrix[predicate] == 0)
			return;

		if (m_topo_graph.getHalfEdgeUserIndex(m_topo_graph
				.getHalfEdgePrev(m_topo_graph.getHalfEdgeTwin(half_edge)),
				m_visited_index) != 1) {
			int cluster = m_topo_graph.getHalfEdgeTo(half_edge);
			int clusterParentage = m_topo_graph.getClusterParentage(cluster);

			if ((clusterParentage & id_b) == 0) {
				int index = m_topo_graph.getClusterUserIndex(cluster,
						cluster_index_a);
				assert (index != -1);

				if (index % 2 != 0) {
					assert ((m_topo_graph.getClusterParentage(cluster) & id_a) != 0);
					m_matrix[predicate] = 0;
				}
			}
		}
	}
1361179
function distance(p1, p2) {
        return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) +
                         (p1.y - p2.y) * (p1.y - p2.y));
    }
413808
function closestPointnd(c, positions, x, result) {
  var D = numeric.rep([c.length, c.length], 0.0);
  var dvec = numeric.rep([c.length], 0.0);
  for(var i=0; i<c.length; ++i) {
    var pi = positions[c[i]];
    dvec[i] = numeric.dot(pi, x);
    for(var j=0; j<c.length; ++j) {
      var pj = positions[c[j]];
      D[i][j] = D[j][i] = numeric.dot(pi, pj);
    }
  }
  var A = numeric.rep([c.length, c.length+2], 0.0);
  var b = numeric.rep([c.length+2], 0.0);
  b[0] = 1.0-EPSILON;
  b[1] = -(1.0+EPSILON);
  for(var i=0; i<c.length; ++i) {
    A[i][0]   = 1;
    A[i][1]   = -1
    A[i][i+2] = 1;
  }
  for(var attempts=0; attempts<15; ++attempts) {
    var fortran_poop = numeric.solveQP(D, dvec, A, b);
    if(fortran_poop.message.length > 0) {
      //Quadratic form may be singular, perturb and resolve
      for(var i=0; i<c.length; ++i) {
        D[i][i] += 1e-8;
      }
      continue;
    } else if(isNaN(fortran_poop.value[0])) {
      break;
    } else {
      //Success!
      var solution = fortran_poop.solution;
      for(var i=0; i<x.length; ++i) {
        result[i] = 0.0;
        for(var j=0; j<solution.length; ++j) {
          result[i] += solution[j] * positions[c[j]][i];
        }
      }
      return 2.0 * fortran_poop.value[0] + numeric.dot(x,x);
    }
  }
  for(var i=0; i<x.length; ++i) {
    result[i] = Number.NaN;
  }
  return Number.NaN;
}
1133138
def _distance_squared(self, p2: "Point2") -> Union[int, float]:
        
        return (self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2
930532
protected static NodeInfo findClosestEdge( NodeInfo n , Point2D_F64 p ) {
		double bestDistance = Double.MAX_VALUE;
		NodeInfo best = null;

		for (int i = 0; i < n.edges.size(); i++) {
			Edge e = n.edges.get(i);
			if( e.target.marked )
				continue;

			double d = e.target.ellipse.center.distance2(p);
			if( d < bestDistance ) {
				bestDistance = d;
				best = e.target;
			}
		}

		return best;
	}
218184
function(p) {
        var v = this.b.sub(this.a);
        var t = p.sub(this.a).dot(v) / v.magSquared();
        // Check to see if t is beyond the extents of the line segment
        if (t < 0.0) {
            return this.a.copy();
        } else if (t > 1.0) {
            return this.b.copy();
        }
        // Return the point between 'a' and 'b'
        return this.a.add(v.scaleSelf(t));
    }
800001
private void boundaryLineExteriorPoint_(int cluster, int id_a, int id_b,
			int cluster_index_a) {
		if (m_matrix[MatrixPredicate.BoundaryExterior] == 0)
			return;

		int clusterParentage = m_topo_graph.getClusterParentage(cluster);

		if ((clusterParentage & id_a) != 0 && (clusterParentage & id_b) == 0) {
			int index = m_topo_graph.getClusterUserIndex(cluster,
					cluster_index_a);

			if (index % 2 != 0) {
				m_matrix[MatrixPredicate.BoundaryExterior] = 0;
			}
		}
	}
562054
def _compute_distance_term(self, C, mag, dists):
        
        return ((C['theta2'] + C['theta14'] + C['theta3'] *
                (mag - 7.8)) * np.log(dists.rhypo + self.CONSTS['c4'] *
                np.exp((mag - 6.) * self.CONSTS['theta9'])) +
                (C['theta6'] * dists.rhypo)) + C["theta10"]