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);
			}
		}
	}
private void stepClosest ( KdTree . Node node , FastQueue < KdTreeResult > neighbors ) { if ( node == null ) return ; checkBestDistance ( node , neighbors ) ; if ( node . isLeaf ( ) ) { return ; } 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 ) ; double dx = splitValue - targetAtSplit ; if ( dx * dx <= mostDistantNeighborSq ) { if ( neighbors . size ( ) < searchN || dx * dx < mostDistantNeighborSq ) { stepClosest ( further , neighbors ) ; } } }
Recursive step for finding the closest point