Returns a point on the segment nearest to the specified point.
<p>
libGDX (Apache 2.0)
970185
public static Point nearestSegmentPoint(double startX, double startY, double endX, double endY, double pointX, double pointY) {
        double xDiff = endX - startX;
        double yDiff = endY - startY;
        double length2 = xDiff * xDiff + yDiff * yDiff;
        if (length2 == 0) return new Point(startX, startY);
        double t = ((pointX - startX) * (endX - startX) + (pointY - startY) * (endY - startY)) / length2;
        if (t < 0) return new Point(startX, startY);
        if (t > 1) return new Point(endX, endY);
        return new Point(startX + t * (endX - startX), startY + t * (endY - startY));
    }
476825
@Pure
	public final BusItineraryHalt getNearestBusHalt(Point2D<?, ?> point) {
		return getNearestBusHalt(point.getX(), point.getY());
	}
38403
Segment getSegment(int vertex) {
		if (m_segments != null) {
			int vindex = getVertexIndex(vertex);
			return m_segments.get(vindex);
		}
		return null;
	}
1148927
public static KmeansResult nearestCentroid(double[] targetPoint, double[][] centroids)
    {
        int nearestCentroidIndex = 0;
        Double minDistance = Double.MAX_VALUE;
        double[] currentCentroid = null;
        Double currentDistance;
        for (int index = 0; index < centroids.length; index++)
        {
            currentCentroid = centroids[index];
            if (currentCentroid != null)
            {
                currentDistance = MathUtils.distance(targetPoint, currentCentroid);
                if (currentDistance < minDistance)
                {
                    minDistance = currentDistance;
                    nearestCentroidIndex = index;
                }
            }
        }

        currentCentroid = centroids[nearestCentroidIndex];

        KmeansResult result = new KmeansResult();
        result.setDataPoint(targetPoint);
        result.setCentroidIndex(nearestCentroidIndex);
        result.setCentroid(currentCentroid);
        result.setDistance(minDistance);

        return result;
    }
742105
@Nullable
  public Point center() {
    // Store locally since rawCenter() is mutable
    double[] center = rawCenter();
    if (center != null && center.length == 2) {
      return Point.fromLngLat(center[0], center[1]);
    }
    return null;
  }
515645
public Coordinate nearest(Coordinate c) {
		double len = this.getLength();

		double u = (c.getX() - this.c1.getX()) * (this.c2.getX() - this.c1.getX()) + (c.getY() - this.c1.getY())
				* (this.c2.getY() - this.c1.getY());
		u = u / (len * len);

		if (u < 0.00001 || u > 1) {
			// Shortest point not within LineSegment, so take closest end-point.
			LineSegment ls1 = new LineSegment(c, this.c1);
			LineSegment ls2 = new LineSegment(c, this.c2);
			double len1 = ls1.getLength();
			double len2 = ls2.getLength();
			if (len1 < len2) {
				return this.c1;
			}
			return this.c2;
		} else {
			// Intersecting point is on the line, use the formula: P = P1 + u (P2 - P1)
			double x1 = this.c1.getX() + u * (this.c2.getX() - this.c1.getX());
			double y1 = this.c1.getY() + u * (this.c2.getY() - this.c1.getY());
			return new Coordinate(x1, y1);
		}
	}
560296
public Point toWgs84(Point point) {
        if (projection != null) {
            point = toWgs84.transform(point);
        }
        return point;
    }
392118
@Pure
	public Point3f getPointAt(int index) {
		return new Point3f(
				this.coords[index*3],
				this.coords[index*3+1],
				this.coords[index*3+2]);
	}
797202
public DelaunayTriangle neighborCW( TriangulationPoint point )
    {
        if( point == points[0] )
        {
            return neighbors[1];
        }
        else if( point == points[1] )
        {
            return neighbors[2];
        }
        return neighbors[0];
    }
707316
@Pure
	public final BusHub getNearestBusHub(Point2D<?, ?> point) {
		return getNearestBusHub(point.getX(), point.getY());
	}
1019470
public static Point getRenderViewOffset(float partialTick)
	{
		Entity entity = Minecraft.getMinecraft().getRenderViewEntity();
		if (partialTick == 0)
			return new Point(entity.posX, entity.posY, entity.posZ);

		double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTick;
		double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTick;
		double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTick;
		return new Point(x, y, z);
	}
969402
public static Point closestPoint(Geometry geomA, Geometry geomB) {
        if (geomA == null || geomB == null) {
            return null;
        }
        // Return the closest point on geomA. (We would have used index
        // 1 to return the closest point on geomB.)
        return geomA.getFactory().createPoint(DistanceOp.nearestPoints(geomA, geomB)[0]);
    }
123015
def get_nearest_by_coordinates(
        data: list, latitude_key: str, longitude_key: str,
        target_latitude: float, target_longitude: float) -> Any:
    """"""
    return min(
        data,
        key=lambda p: haversine(
            target_latitude,
            target_longitude,
            float(p[latitude_key]),
            float(p[longitude_key])
        ))
1008078
public float distanceSquared(Vector2f point) {
		getClosestPoint(point, closest);
		closest.sub(point);

		float result = closest.lengthSquared();

		return result;
	}
173419
private Point getCellPoint() {
        double x1 = (minX + cellI * deltaX) + (deltaX / 2d);
        double y1 = (minY + cellJ * deltaY) + (deltaY / 2d);
        cellI++;
        return GF.createPoint(new Coordinate(x1, y1));
    }
800857
function closestPoint0d(a, x, result) {
  var d = 0.0;
  for(var i=0; i<x.length; ++i) {
    result[i] = a[i];
    var t = a[i] - x[i];
    d += t * t;
  }
  return d;
}
866471
function closestPoint1d(a, b, x, result) {
  var denom = 0.0;
  var numer = 0.0;
  for(var i=0; i<x.length; ++i) {
    var ai = a[i];
    var bi = b[i];
    var xi = x[i];
    var dd = ai - bi;
    numer += dd * (xi - bi);
    denom += dd * dd;
  }
  var t = 0.0;
  if(Math.abs(denom) > EPSILON) {
    t = numer / denom;
    if(t < 0.0) {
      t = 0.0;
    } else if(t > 1.0) {
      t = 1.0;
    }
  }  
  var ti = 1.0 - t;
  var d = 0;
  for(var i=0; i<x.length; ++i) {
    var r = t * a[i] + ti * b[i];
    result[i] = r;
    var s = x[i] - r;
    d += s * s;
  }
  return d;
}