示例#1
0
        /// <summary>
        /// Clears the QuadTree of all objects, including any objects living in its children.
        /// </summary>
        internal void clear()
        {
            // Clear out the children, if we have any
            if (_childTL != null)
            {
                _childTL.clear();
                _childTR.clear();
                _childBL.clear();
                _childBR.clear();
            }

            // Clear any objects at this level
            if (_objects != null)
            {
                _objects.Clear();
                _objects = null;
            }

            // Set the children to null
            _childTL = null;
            _childTR = null;
            _childBL = null;
            _childBR = null;
        }
示例#2
0
        /// <summary>
        /// Get the child Quad that would contain an object.
        /// </summary>
        /// <param name="item">The object to get a child for.</param>
        /// <returns></returns>
        QuadTreeNode <T> getDestinationTree(QuadTreeObject <T> item)
        {
            // If a child can't contain an object, it will live in this Quad
            QuadTreeNode <T> destTree = this;

            if (_childTL.quadRect.Contains(item.data.bounds))
            {
                destTree = _childTL;
            }
            else if (_childTR.quadRect.Contains(item.data.bounds))
            {
                destTree = _childTR;
            }
            else if (_childBL.quadRect.Contains(item.data.bounds))
            {
                destTree = _childBL;
            }
            else if (_childBR.quadRect.Contains(item.data.bounds))
            {
                destTree = _childBR;
            }

            return(destTree);
        }
示例#3
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="x">The top-left position of the area rectangle.</param>
 /// <param name="y">The top-right position of the area rectangle.</param>
 /// <param name="width">The width of the area rectangle.</param>
 /// <param name="height">The height of the area rectangle.</param>
 public QuadTree(int x, int y, int width, int height)
 {
     _quadTreeRoot = new QuadTreeNode <T>(new Rectangle(x, y, width, height));
 }
示例#4
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="rect">The area this QuadTree object will encompass.</param>
 public QuadTree(Rectangle rect)
 {
     _quadTreeRoot = new QuadTreeNode <T>(rect);
 }
示例#5
0
 QuadTreeNode(QuadTreeNode <T> parent, Rectangle rect) : this( rect )
 {
     _parent = parent;
 }