/// <summary>
        /// Reset the iterator.
        /// </summary>
        public void Reset()
        {
            // Store the point count and the distance function.
            this.iPointsRemaining = Math.Min(iMaxPointsReturned, pRoot.Size);
            _CurrentDistance      = -1;

            // Create an interval heap for the points we check.
            this.pEvaluated = new IntervalHeap();

            // Create a min heap for the things we need to check.
            this.pPending = new MinHeap();
            this.pPending.Insert(0, pRoot);
        }
        /// <summary>
        /// Construct a new nearest neighbour iterator.
        /// </summary>
        /// <param name="pRoot">The root of the tree to begin searching from.</param>
        /// <param name="tSearchPoint">The point in n-dimensional space to search.</param>
        /// <param name="kDistance">The distance function used to evaluate the points.</param>
        /// <param name="iMaxPoints">The max number of points which can be returned by this iterator.  Capped to max in tree.</param>
        /// <param name="fThreshold">Threshold to apply to the search space.  Negative numbers indicate that no threshold is applied.</param>
        public NearestNeighbour(KDNode pRoot, Vector3d tSearchPoint, DistanceFunctions kDistance, int iMaxPoints, double fThreshold)
        {
            // Store the search point.
            this.tSearchPoint = new Vector3d(tSearchPoint);

            // Store the point count, distance function and tree root.
            this.iPointsRemaining   = Math.Min(iMaxPoints, pRoot.Size);
            this.fThreshold         = fThreshold;
            this.kDistanceFunction  = kDistance;
            this.pRoot              = pRoot;
            this.iMaxPointsReturned = iMaxPoints;
            _CurrentDistance        = -1;

            // Create an interval heap for the points we check.
            this.pEvaluated = new IntervalHeap();

            // Create a min heap for the things we need to check.
            this.pPending = new MinHeap();
            this.pPending.Insert(0, pRoot);
        }
		/// <summary> 
		/// Construct a new nearest neighbour iterator. 
		/// </summary> 
		/// <param name="pRoot">The root of the tree to begin searching from.</param> 
		/// <param name="tSearchPoint">The point in n-dimensional space to search.</param> 
		/// <param name="kDistance">The distance function used to evaluate the points.</param> 
		/// <param name="iMaxPoints">The max number of points which can be returned by this iterator.  Capped to max in tree.</param> 
		/// <param name="fThreshold">Threshold to apply to the search space.  Negative numbers indicate that no threshold is applied.</param> 
		public NearestNeighbour(KDNode pRoot, Vector3d tSearchPoint, DistanceFunctions kDistance, int iMaxPoints, double fThreshold)
		{

			// Store the search point. 
			this.tSearchPoint = new Vector3d(tSearchPoint);

			// Store the point count, distance function and tree root. 
			this.iPointsRemaining = Math.Min(iMaxPoints, pRoot.Size);
			this.fThreshold = fThreshold;
			this.kDistanceFunction = kDistance;
			this.pRoot = pRoot;
			this.iMaxPointsReturned = iMaxPoints;
			_CurrentDistance = -1;

			// Create an interval heap for the points we check. 
			this.pEvaluated = new IntervalHeap();

			// Create a min heap for the things we need to check. 
			this.pPending = new MinHeap();
			this.pPending.Insert(0, pRoot);
		}
		/// <summary> 
		/// Reset the iterator. 
		/// </summary> 
		public void Reset()
		{
			// Store the point count and the distance function. 
			this.iPointsRemaining = Math.Min(iMaxPointsReturned, pRoot.Size);
			_CurrentDistance = -1;

			// Create an interval heap for the points we check. 
			this.pEvaluated = new IntervalHeap();

			// Create a min heap for the things we need to check. 
			this.pPending = new MinHeap();
			this.pPending.Insert(0, pRoot);
		}