Exemple #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;
        }
Exemple #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>
        private 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.BoundingBox2D))
            {
                destTree = childTL;
            }
            else if (childTR.QuadRect.Contains(item.Data.BoundingBox2D))
            {
                destTree = childTR;
            }
            else if (childBL.QuadRect.Contains(item.Data.BoundingBox2D))
            {
                destTree = childBL;
            }
            else if (childBR.QuadRect.Contains(item.Data.BoundingBox2D))
            {
                destTree = childBR;
            }

            return(destTree);
        }
Exemple #3
0
 public void Dispose()
 {
     Data  = default(T);
     Owner = null;
 }
Exemple #4
0
 private QuadTreeNode(QuadTreeNode <T> parent, BoundingBox2D rect)
     : this(rect)
 {
     this.parent = parent;
 }
Exemple #5
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="rect">The area this QuadTree object will encompass.</param>
 public QuadTree(BoundingBox2D rect)
 {
     quadTreeRoot       = new QuadTreeNode <T>(rect);
     quadTreeObjectPool = new PoolNew <QuadTreeObject <T> >(typeof(QuadTreeObject <T>), 1000);
     objectRemovedCount = 0;
 }
Exemple #6
0
 public virtual void Reallocate()
 {
     Destroyed = false;
     Data      = default(T);
     Owner     = null;
 }