code: public void findClosestN( P p , double maxDistance , int numNeighbors ,
  							  GrowQueue_I32 outputIndex ,
  							  GrowQueue_F64 outputDistance ) {
  
  		// Compute the distance of each point and save the ones within range
  		distances.reset();
  		indexes.reset();
  
  		for( int i = 0; i < points.size(); i++ ) {
  			P c = points.get(i);
  
  			double distanceC = distance.distance(p,c);
  
  			if( distanceC <= maxDistance ) {
  				distances.add(distanceC);
  				indexes.add(i);
  			}
  		}
  
  		// find the N closest elements
  		numNeighbors = Math.min(distances.size,numNeighbors);
  		if( numNeighbors == 0 )
  			return;
  
  		indexesSort.resize(distances.size);
  		QuickSelect.selectIndex(distances.data,numNeighbors-1,distances.size,indexesSort.data);
  
  		for( int i = 0; i < numNeighbors; i++ ) {
  			int index = indexes.get(indexesSort.get(i));
  			outputIndex.add( index );
  			outputDistance.add( distances.get( indexesSort.get(i) ) );
  		}
  	}
docs: Finds the index of the point which has the smallest Euclidean distance to 'p' and is {@code <} maxDistance
  away.
  
  @param p A point.
  @param maxDistance The maximum distance (Euclidean squared) the neighbor can be.
  @param numNeighbors the requested number of nearest neighbors it should search for
  @param outputIndex Storage for the index of the closest elements
  @param outputDistance Storage for the distance of the closest elements