code: private void stepClosest(KdTree.Node node) {
  
  		if( node == null )
  			return;
  
  		if( node.isLeaf() ) {
  			// a leaf can be empty.
  			if( node.point != null ) {
  				double distSq = distance.distance((P)node.point,target);
  				if( distSq <= bestDistanceSq ) {
  					if( closest == null || distSq < bestDistanceSq ) {
  						closest = node;
  						bestDistanceSq = distSq;
  					}
  				}
  			}
  			return;
  		} else {
  			double distSq = distance.distance((P)node.point,target);
  			if( distSq <= bestDistanceSq ) {
  				if( closest == null || distSq < bestDistanceSq ) {
  					closest = node;
  					bestDistanceSq = distSq;
  				}
  			}
  		}
  
  		// 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);
  
  		// See if it is possible for 'further' to contain a better node
  		double dx = splitValue - targetAtSplit;
  		double dx2 = dx*dx;
  		if( dx2 <= bestDistanceSq ) {
  			if( closest == null || dx2 < bestDistanceSq )
  				stepClosest(further);
  		}
  	}
docs: Recursive step for finding the closest point