Recursive step for finding the closest point
973933
private void stepClosest(KdTree.Node node , FastQueue<KdTreeResult> neighbors ) {

		if( node == null )
			return;

		checkBestDistance(node, neighbors);

		if( node.isLeaf() ) {
			return;
		}

		// select the most promising branch to investigate first
		KdTree.Node nearer,further;

		double splitValue = distance.valueAt((P)node.point, node.split );

		double targetAtSplit = distance.valueAt(target,node.split);
		if( targetAtSplit<= splitValue ) {
			nearer = node.left;
			further = node.right;
		} else {
			nearer = node.right;
			further = node.left;
		}

		stepClosest(nearer,neighbors);

		// See if it is possible for 'further' to contain a better node
		// Or if N matches have yet to be find, if it is possible to meet the maximum distance requirement
		double dx = splitValue - targetAtSplit;
		if( dx*dx <= mostDistantNeighborSq) {
			if( neighbors.size() < searchN || dx*dx < mostDistantNeighborSq) {
				stepClosest(further,neighbors);
			}
		}
	}
478012
def interp(self):
        """"""
        if self.ndim == 0:
            return 'nearest'
        elif all(interp == self.interp_byaxis[0]
                 for interp in self.interp_byaxis):
            return self.interp_byaxis[0]
        else:
            return self.interp_byaxis
562043
public static Point closestInteriorPoint (IRectangle r, IPoint p)  {
        return closestInteriorPoint(r, p, new Point());
    }
270230
@Override
	public ClusteringTreeNode nearestChild(double[] pointA) {
		assert (this.projections.size() > 0 &&
				this.projections.get(0).length == pointA.length);
		int minBucketProjection = -1;
		int minSize = Integer.MAX_VALUE;
		Iterator<double[]> iIterProjections = this.projections.iterator();
		Iterator<CuckooHashing<List<ClusteringTreeNode>>> iIterBuckets = this.buckets
				.iterator();
		int size = this.projections.size();
		for (int i = 0; i < size; i++) {
			long bucketNumber = calcBucketNumber(project(pointA,
					iIterProjections.next()));
			List<ClusteringTreeNode> currentBucket = iIterBuckets.next().get(
					bucketNumber);
			int bucketSize;
			if (currentBucket != null
					&& (bucketSize = currentBucket.size()) <= minSize) {
				minBucketProjection = i;
				minSize = bucketSize;
			}
		}
		if (minBucketProjection == -1) {
			return null;
		}

		long bucketNumber = calcBucketNumber(project(pointA,
				minBucketProjection));
		double minDistance = Double.POSITIVE_INFINITY;
		ClusteringTreeNode min = null;
		// for (int i = -1; i <= 1; i++) {
		List<ClusteringTreeNode> currentBucket = this.buckets.get(
				minBucketProjection).get(bucketNumber);// + i);
		if (currentBucket != null) {
			for (ClusteringTreeNode node : currentBucket) {
				double d = Metric.distance(pointA, node.getCenter());
				if (d < minDistance) {
					minDistance = d;
					min = node;
				}
			}
		}
		// }
		return min;
	}
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;
	}
944943
public void getClosestPoint(Vector2f point, Vector2f result) {
		loc.set(point);
		loc.sub(start);

		float projDistance = vec.dot(loc);

		projDistance /= vec.lengthSquared();

		if (projDistance < 0) {
			result.set(start);
			return;
		}
		if (projDistance > 1) {
			result.set(end);
			return;
		}

		result.x = start.getX() + projDistance * vec.getX();
		result.y = start.getY() + projDistance * vec.getY();
	}
300641
def _closest_location(self, location_map, target):
        """"""

        def dist(a, b):
            return math.sqrt(sum((a[k] - b[k]) ** 2 for k in a.keys()))

        paths = iter(location_map.keys())
        closest = next(paths)
        closest_dist = dist(target, location_map[closest])
        for path in paths:
            cur_dist = dist(target, location_map[path])
            if cur_dist < closest_dist:
                closest = path
                closest_dist = cur_dist
        return closest
294789
def get_closest_points(self, mesh):
        
        min_idx = cdist(self.xyz, mesh.xyz).argmin(axis=0)  # lose shape
        if hasattr(mesh, 'shape'):
            min_idx = min_idx.reshape(mesh.shape)
        lons = self.lons.take(min_idx)
        lats = self.lats.take(min_idx)
        deps = self.depths.take(min_idx)
        return Mesh(lons, lats, deps)
1314249
def find_nearest_index(arr, value):
    """"""
    arr = np.array(arr)
    index = (abs(arr-value)).argmin()
    return index
1371169
def _find_closest_trackpoint(self,R,vR,vT,z,vz,phi,interp=True,xy=False,
                                 usev=False):
        """"""
        return self.find_closest_trackpoint(R,vR,vT,z,vz,phi,
                                            interp=interp,xy=xy,
                                            usev=usev)
39478
public ClusteringTreeNode nearestChild(double[] pointA) {
		assert (this.center.length == pointA.length);
		double minDistance = Double.POSITIVE_INFINITY;
		ClusteringTreeNode min = null;
		for (ClusteringTreeNode node : this.getChildren()) {
			double d = Metric.distance(pointA, node.getCenter());
			if (d < minDistance) {
				minDistance = d;
				min = node;
			}
		}
		return min;
	}
476887
def nearest(self, idx):
        """"""
        hi = self.after(idx)
        lo = self.before(idx)
        if hi is None:
            return lo
        if lo is None:
            return hi
        if abs(hi - idx) < abs(lo - idx):
            return hi
        return lo
128662
def closest_distance_to(self, position: Union[Unit, Point2, Point3]) -> Union[int, float]:
        
        assert self.exists
        if isinstance(position, Unit):
            position = position.position
        return position.distance_to_closest(
            [u.position for u in self]
        )
1373736
def bound(self, p1, p2=None):
    """"""
    r = Rect(p1, p2)
    return Point(min(max(self.x, r.l), r.r), min(max(self.y, r.t), r.b))
396258
def ApproximateDistanceBetweenStops(stop1, stop2):
  """"""
  if (stop1.stop_lat is None or stop1.stop_lon is None or
      stop2.stop_lat is None or stop2.stop_lon is None):
    return None
  return ApproximateDistance(stop1.stop_lat, stop1.stop_lon,
                             stop2.stop_lat, stop2.stop_lon)
558474
function closest(obj, number){		
		if((current = obj.length) < 2)
			return l - 1;
			
		for(var current, previous = Math.abs(obj[--current] - number); current--;)
			if(previous < (previous = Math.abs(obj[current] - number)))
				break;
				
		return obj[current + 1];
	
		var closest = -1,
			prev = Math.abs(obj[0] - number);
		
		for (var i = 1; i < obj.length; i++){
			var diff = Math.abs(obj[i] - number);
			
			if (diff <= prev){
				prev = diff;
				closest = obj[i];
			}
		}
		
		return closest;
	}
734285
function closest (el, sel) {
  if (!el) return
  if (matches(el, sel)) {
    return el
  } else {
    return closest(el.parentNode, sel)
  }
}