Example #1
0
        /**
         * subquads are numbered as follows:
         *
         *  2 | 3
         *  --+--
         *  0 | 1
         */

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the IntervalNode class.
        /// </summary>
        public IntervalNode(IntervalNode parent, double min, double max)
        {
            _parent = parent;
            _min    = min;
            _max    = max;
            _center = (min + max) / 2;
        }
Example #2
0
        }         // private int GetSubintervalIndex( double min, double max )

        /// <summary>
        /// get the subinterval for the index.
        /// If it doesn't exist, create it
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private IntervalNode GetSubinterval(int index)
        {
            if (_subinterval[index] == null)
            {
                // create a new subquad in the appropriate quadrant
                double submin = 0.0;
                double submax = 0.0;

                switch (index)
                {
                case 0:
                    submin = _min;
                    submax = _center;
                    break;

                case 1:
                    submin = _center;
                    submax = _max;
                    break;
                }

                IntervalNode interval = new IntervalNode(this, submin, submax);
                _subinterval[index] = interval;
            }     // if ( _subinterval[index] == null )
            return(_subinterval[index]);
        }         // private IntervalNode GetSubinterval( int index )
Example #3
0
		/**
		* subquads are numbered as follows:
		*
		*  2 | 3
		*  --+--
		*  0 | 1
		*/

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the IntervalNode class.
		/// </summary>
		public IntervalNode(IntervalNode parent, double min, double max)
		{
			_parent = parent;
			_min = min;
			_max = max;
			_center = (min + max) / 2;
		}
Example #4
0
        }         // public IntervalNode GetIntervalNode( double min, double max )

        /// <summary>
        /// Returns the smallest existing node containing the envelope.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public IntervalNode Find(double min, double max)
        {
            int subintervalIndex = GetSubintervalIndex(min, max);

            if (subintervalIndex == -1 || _subinterval[subintervalIndex] == null)
            {
                return(this);
            }
            // query lies in subnode, so search it recursively
            IntervalNode node = _subinterval[subintervalIndex];

            return(node.Find(min, max));
        }         // public IntervalNode Find( double min, double max )
Example #5
0
        }                                                                            // public ArrayList AddAllItemsFromOverlapping( double min, double max, ArrayList items )

        /// <summary>
        /// Returns the interval containing the envelope.
        /// Creates the interval if it does not already exist.
        /// Note that passing a zero-size interval to this routine results in infinite recursion.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public IntervalNode GetIntervalNode(double min, double max)
        {
            int subintervalIndex = GetSubintervalIndex(min, max);

            if (subintervalIndex != -1)
            {
                // create the quad if it does not exist
                IntervalNode interval = GetSubinterval(subintervalIndex);
                // recursively search the found quad
                return(interval.GetIntervalNode(min, max));
            }
            else
            {
                return(this);
            }
        }         // public IntervalNode GetIntervalNode( double min, double max )
Example #6
0
		} // private int GetSubintervalIndex( double min, double max )


		/// <summary>
		/// get the subinterval for the index.
		/// If it doesn't exist, create it
		/// </summary>
		/// <param name="index"></param>
		/// <returns></returns>
		private IntervalNode GetSubinterval( int index )
		{
			if ( _subinterval[index] == null ) 
			{
				// create a new subquad in the appropriate quadrant
				double submin = 0.0;
				double submax = 0.0;

				switch ( index ) 
				{
					case 0:
						submin = _min;
						submax = _center;
						break;
					case 1:
						submin = _center;
						submax = _max;
						break;
				}

				IntervalNode interval = new IntervalNode( this, submin, submax );
				_subinterval[index] = interval;
			} // if ( _subinterval[index] == null )
			return _subinterval[index];
		} // private IntervalNode GetSubinterval( int index )