Ejemplo n.º 1
0
        /// <summary>
        /// Inserts an item into one of this node's children
        /// </summary>
        /// <param name="item">The item to insert in a child</param>
        /// <returns>Whether or not the insert succeeded</returns>
        protected bool InsertInChild(QuadTreePositionItem <T> item)
        {
            if (!IsPartitioned)
            {
                return(false);
            }

            if (TopLeftNode.ContainsRect(item.Rect))
            {
                TopLeftNode.Insert(item);
            }
            else if (TopRightNode.ContainsRect(item.Rect))
            {
                TopRightNode.Insert(item);
            }
            else if (BottomLeftNode.ContainsRect(item.Rect))
            {
                BottomLeftNode.Insert(item);
            }
            else if (BottomRightNode.ContainsRect(item.Rect))
            {
                BottomRightNode.Insert(item);
            }

            else
            {
                return(false); // insert in child failed
            }
            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Inserts an item into the QuadTree
 /// </summary>
 /// <param name="item">The item to insert</param>
 /// <remarks>Checks to see if the world needs resizing and does so if needed</remarks>
 public void Insert(QuadTreePositionItem <T> item)
 {
     // check if the world needs resizing
     if (!headNode.ContainsRect(item.Rect))
     {
         Resize(new FRect(
                    Vector2.Min(headNode.Rect.TopLeft, item.Rect.TopLeft) * 2,
                    Vector2.Max(headNode.Rect.BottomRight, item.Rect.BottomRight) * 2));
     }
     item.node     = null;
     item.quadTree = this;
     headNode.Insert(item);
 }