Exemplo n.º 1
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.QuadBounds))
            {
                destTree = childTL;
            }
            else if (childTR.QuadRect.Contains(item.Data.QuadBounds))
            {
                destTree = childTR;
            }
            else if (childBL.QuadRect.Contains(item.Data.QuadBounds))
            {
                destTree = childBL;
            }
            else if (childBR.QuadRect.Contains(item.Data.QuadBounds))
            {
                destTree = childBR;
            }

            return(destTree);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 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(double x, double y, double width, double height)
 {
     quadTreeRoot = new QuadTreeNode <T>(new PreciseRectangle(x, y, width, height));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="rect">The area this QuadTree object will encompass.</param>
 public QuadTree(PreciseRectangle rect)
 {
     quadTreeRoot = new QuadTreeNode <T>(rect);
 }
Exemplo n.º 5
0
 private QuadTreeNode(QuadTreeNode <T> parent, PreciseRectangle rect)
     : this(rect) {
     this.parent = parent;
 }