New edge distance calculation where no validEdgeDistance check would be necessary
<p>

@return the normalized distance of the query point "r" to the project point "c" onto the line
segment a-b
353774
public double calcNormalizedEdgeDistanceNew(double r_lat_deg, double r_lon_deg,
                                                double a_lat_deg, double a_lon_deg,
                                                double b_lat_deg, double b_lon_deg, boolean reduceToSegment) {
        double shrinkFactor = calcShrinkFactor(a_lat_deg, b_lat_deg);

        double a_lat = a_lat_deg;
        double a_lon = a_lon_deg * shrinkFactor;

        double b_lat = b_lat_deg;
        double b_lon = b_lon_deg * shrinkFactor;

        double r_lat = r_lat_deg;
        double r_lon = r_lon_deg * shrinkFactor;

        double delta_lon = b_lon - a_lon;
        double delta_lat = b_lat - a_lat;

        if (delta_lat == 0)
            // special case: horizontal edge
            return calcNormalizedDist(a_lat_deg, r_lon_deg, r_lat_deg, r_lon_deg);

        if (delta_lon == 0)
            // special case: vertical edge        
            return calcNormalizedDist(r_lat_deg, a_lon_deg, r_lat_deg, r_lon_deg);

        double norm = delta_lon * delta_lon + delta_lat * delta_lat;
        double factor = ((r_lon - a_lon) * delta_lon + (r_lat - a_lat) * delta_lat) / norm;

        // make new calculation compatible to old
        if (reduceToSegment) {
            if (factor > 1)
                factor = 1;
            else if (factor < 0)
                factor = 0;
        }
        // x,y is projection of r onto segment a-b
        double c_lon = a_lon + factor * delta_lon;
        double c_lat = a_lat + factor * delta_lat;
        return calcNormalizedDist(c_lat, c_lon / shrinkFactor, r_lat_deg, r_lon_deg);
    }
967325
public Point interpolate(double distance) {
        if (distance < 0) {
            return null;
        }

        for (LineSegment segment : this.segments) {
            double length = segment.length();
            if (distance <= length) {
                return segment.pointAlongLineSegment(distance);
            }
            distance -= length;
        }
        return null;
    }
1297979
public double distance(Coordinate c) {
		Coordinate nearest = this.nearest(c);
		LineSegment ls = new LineSegment(c, nearest);
		return ls.getLength();
	}
856716
public double getLinkSlope() {
        if ((int) linkSlope == -1) {
            // hillslopeFeature.getAttribute(baricenterElevationAttribute);
            double startElev = (Double) linkFeature.getAttribute(NetworkChannel.STARTELEVNAME);
            double endElev = (Double) linkFeature.getAttribute(NetworkChannel.ENDELEVNAME);
            linkSlope = (startElev - endElev) / getLinkLength();

            if (linkSlope <= 0) {
                /*
                 * if < 0 then probably it is very flat and the dem si not precise. The slope is
                 * set.
                 */
                linkSlope = 0.001;
            }
        }
        return linkSlope;
    }
285916
@Pure
	public CrossRoad getFirstJunctionPoint() {
		RoadConnection point = getFirstPoint();
		double distance = 0;
		RoadSegment beforeSegment = null;
		RoadSegment afterSegment = null;
		int beforeSegmentIndex = -1;
		int afterSegmentIndex = -1;
		boolean found = false;
		if (point != null) {
			int index = 0;
			for (final RoadSegment sgmt : this) {
				if (found) {
					afterSegment = sgmt;
					afterSegmentIndex = index;
					//stop now
					break;
				}

				point = sgmt.getOtherSidePoint(point);
				beforeSegment = sgmt;
				beforeSegmentIndex = index;
				distance += sgmt.getLength();
				final int count = point.getConnectedSegmentCount();
				if (count != 2) {
					found = true;
				}
				++index;
			}
		}

		if (found) {
			return new CrossRoad(point, beforeSegment, beforeSegmentIndex,
					afterSegment, afterSegmentIndex, distance, distance);
		}

		return null;
	}
298991
@Override
	@Pure
	public double getDistance(Point2D<?, ?> point) {
		double mind = Double.MAX_VALUE;
		for (final Point2d p : points()) {
			final double d = p.getDistance(point);
			if (d < mind) {
				mind = d;
			}
		}
		return mind;
	}
1173625
public static LineString computeDirection(Geometry geometry) throws IllegalArgumentException {
        if(geometry == null){
            return null;
        }
        // Convert geometry into triangle
        Triangle triangle = TINFeatureFactory.createTriangle(geometry);
        // Compute slope vector
        Vector3D normal = TriMarkers.getNormalVector(triangle);
        Vector3D vector = new Vector3D(normal.getX(), normal.getY(), 0).normalize();
        // Compute equidistant point of triangle's sides
        Coordinate inCenter = triangle.centroid();
        // Interpolate Z value
        inCenter.setOrdinate(2, Triangle.interpolateZ(inCenter, triangle.p0, triangle.p1, triangle.p2));
        // Project slope from triangle center to triangle borders
        final LineSegment[] sides = new LineSegment[] {new LineSegment(triangle.p0, triangle.p1),
                new LineSegment(triangle.p1, triangle.p2), new LineSegment(triangle.p2, triangle.p0)};
        Coordinate pointIntersection = null;
        double nearestIntersection = Double.MAX_VALUE;
        for(LineSegment side : sides) {
            Coordinate intersection  = CoordinateUtils.vectorIntersection(inCenter, vector, side.p0,
                    new Vector3D(side.p0,side.p1).normalize());
            double distInters = intersection == null ? Double.MAX_VALUE : side.distance(intersection);
            if(intersection != null && distInters < nearestIntersection) {
                pointIntersection = new Coordinate(intersection.x, intersection.y,
                        Triangle.interpolateZ(intersection, triangle.p0, triangle.p1, triangle.p2));
                nearestIntersection = distInters;
            }
        }
        if (pointIntersection != null) {
            return gf.createLineString(new Coordinate[]{inCenter, pointIntersection});
        }
        return gf.createLineString(new Coordinate[] {});
    }
707630
@Pure
	public double distanceLine(Point3D point) {
		return distanceLinePoint(
				getX1(), getY1(), getZ1(),
				getX2(), getY2(), getZ2(),
				point.getX(), point.getY(), point.getZ());
	}
173418
private static double getEdgeFragmentCost(Node node, Arborescence<Node> arborescence,
                                              Map<Node, Map<Node, Fragment>> edgeToFragment) {

        Fragment fragment = getEdgeFragment(node, arborescence, edgeToFragment);
        if (fragment != null) return fragment.fragmentCost();

        return 0D;
    }
900198
public int distance(CLDR.Locale desired, CLDR.Locale supported) {
    return distance(desired, supported, DEFAULT_THRESHOLD);
  }
1119242
public Coordinate[] getCoordinatesDistance() {
        if (geomA == null || geomB == null) {
            return null;
        }
        if (geomA.isEmpty() || geomB.isEmpty()) {
            return null;
        }
        if (geomA.equals(geomB)) {
            sameGeom = true;           
        }

        if (maxDistanceFilter == null) {
            computeMaxDistance();
        }
        return maxDistanceFilter.getCoordinatesDistance();

    }
624473
public double getDistance(Coordinate coordinate) {
		double distance = Double.MAX_VALUE;
		if (!isEmpty()) {
			for (LineString lineString : lineStrings) {
				double d = lineString.getDistance(coordinate);
				if (d < distance) {
					distance = d;
				}
			}
		}
		return distance;
	}
280546
def edge_lengths(self):
        
        simplex = self.simplices.T

        # simplex is vectors a, b, c defining the corners
        a = self.points[simplex[0]]
        b = self.points[simplex[1]]
        c = self.points[simplex[2]]

        # norm to calculate length
        ab = np.linalg.norm(b - a, axis=1)
        bc = np.linalg.norm(c - a, axis=1)
        ac = np.linalg.norm(a - c, axis=1)

        return ab, bc, ac
1186423
public Point pointAlongLineSegment(double distance) {
        if (start.x == end.x) {
            // we have a vertical line
            if (start.y > end.y) {
                return new Point(end.x, end.y + distance);
            } else {
                return new Point(start.x, start.y + distance);
            }
        } else {
            double slope = (end.y - start.y) / (end.x - start.x);
            double dx = Math.sqrt((distance * distance) / (1 + (slope * slope)));
            if (end.x < start.x) {
                dx *= -1;
            }
            return new Point(start.x + dx, start.y + slope * dx);
        }
    }
1121842
public float distance(DataPoint point) {
        switch (functionName) {
            case "euclidean":
                float ret = Nd4j.getExecutioner().execAndReturn(new EuclideanDistance(this.point, point.point))
                                .getFinalResult().floatValue();
                return invert ? -ret : ret;

            case "cosinesimilarity":
                float ret2 = Nd4j.getExecutioner().execAndReturn(new CosineSimilarity(this.point, point.point))
                                .getFinalResult().floatValue();
                return invert ? -ret2 : ret2;

            case "manhattan":
                float ret3 = Nd4j.getExecutioner().execAndReturn(new ManhattanDistance(this.point, point.point))
                                .getFinalResult().floatValue();
                return invert ? -ret3 : ret3;
            case "dot":
                float dotRet = (float) Nd4j.getBlasWrapper().dot(this.point, point.point);
                return invert ? -dotRet : dotRet;
            default:
                float ret4 = Nd4j.getExecutioner().execAndReturn(new EuclideanDistance(this.point, point.point))
                                .getFinalResult().floatValue();
                return invert ? -ret4 : ret4;

        }
    }
77900
public Double getDistance() {
        if (geomA == null || geomB == null) {
            return null;
        }
        if (geomA.isEmpty() || geomB.isEmpty()) {
            return 0.0;
        }
        if (geomA.equals(geomB)) {
            sameGeom = true;
        }
        if (maxDistanceFilter == null) {
            computeMaxDistance();
        }
        return maxDistanceFilter.getDistance();

    }
1245970
@Override
  public double getDistance(S solution, L solutionList) {
    List<Double> listOfDistances = knnDistances(solution, solutionList) ;
    listOfDistances.sort(Comparator.naturalOrder());

    int limit = Math.min(k, listOfDistances.size()) ;

    double result ;
    if (limit == 0) {
      result = 0.0 ;
    } else {
      double sum = 0.0;
      for (int i = 0; i < limit; i++) {
        sum += listOfDistances.get(i);
      }
      result = sum/limit ;
    }
    return result;
  }