Exemple #1
0
 /// <summary>
 /// Gets a list of items intersecting a specified rectangle
 /// </summary>
 /// <param name="Rect">The rectangle</param>
 /// <param name="ItemsFound">The list to add found items to (list will not be cleared first)</param>
 public void GetItems(FRect Rect, ref List <QuadTreePositionItem <T> > ItemsList)
 {
     if (ItemsList != null)
     {
         headNode.GetItems(Rect, ref ItemsList);
     }
 }
Exemple #2
0
 public bool Intersects(FRect Rect)
 {
     return(!(Bottom < Rect.Top ||
              Top > Rect.Bottom ||
              Right < Rect.Left ||
              Left > Rect.Right));
 }
Exemple #3
0
 /// <summary>
 /// Tests whether this node contains a rectangle
 /// </summary>
 /// <param name="rect">The rectangle to test</param>
 /// <returns>Whether or not this node contains the specified rectangle</returns>
 public bool ContainsRect(FRect rect)
 {
     return(rect.TopLeft.X >= Rect.TopLeft.X &&
            rect.TopLeft.Y >= Rect.TopLeft.Y &&
            rect.BottomRight.X <= Rect.BottomRight.X &&
            rect.BottomRight.Y <= Rect.BottomRight.Y);
 }
Exemple #4
0
 /// <summary>
 /// Gets a list of items intersecting a specified rectangle
 /// </summary>
 /// <param name="Rect">The rectangle</param>
 /// <param name="ItemsFound">The list to add found items to (list will not be cleared first)</param>
 /// <remarks>ItemsFound is assumed to be initialized, and will not be cleared</remarks>
 public void GetItems(FRect Rect, ref List <QuadTreePositionItem <T> > ItemsFound)
 {
     // test the point against this node
     if (Rect.Intersects(Rect))
     {
         //CreamXProfiler.StartProfiling(ProfilerName.QuadTreeGetItems);
         // test the point in each item
         foreach (QuadTreePositionItem <T> Item in Items)
         {
             //object o = Item.Parent;
             if (Item.Rect.Intersects(Rect))
             {
                 ItemsFound.Add(Item);
             }
         }
         //CreamXProfiler.StopProfiling(ProfilerName.QuadTreeGetItems);
         // query all subtrees
         if (IsPartitioned)
         {
             TopLeftNode.GetItems(Rect, ref ItemsFound);
             TopRightNode.GetItems(Rect, ref ItemsFound);
             BottomLeftNode.GetItems(Rect, ref ItemsFound);
             BottomRightNode.GetItems(Rect, ref ItemsFound);
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// QuadTreeNode constructor
 /// </summary>
 /// <param name="parentNode">The parent node of this QuadTreeNode</param>
 /// <param name="rect">The rectangle of the QuadTreeNode</param>
 /// <param name="maxItems">Maximum number of items in the QuadTreeNode before partitioning</param>
 public QuadTreeNode(QuadTreeNode <T> parentNode, FRect rect, int maxItems)
 {
     ParentNode    = parentNode;
     Rect          = rect;
     MaxItems      = maxItems;
     IsPartitioned = false;
     Items         = new List <QuadTreePositionItem <T> >();
 }
Exemple #6
0
        /// <summary>
        /// Creates a position item in a QuadTree
        /// </summary>
        /// <param name="parent">The parent of this item</param>
        /// <param name="position">The position of this item</param>
        /// <param name="size">The size of this item</param>
        public QuadTreePositionItem(T parent, Vector2 position, Vector2 size)
        {
            this.rect = new FRect(0f, 0f, 1f, 1f);

            this.parent   = parent;
            this.position = position;
            this.size     = size;
            OnMove();
        }
Exemple #7
0
 /// <summary>
 /// QuadTreeNode constructor
 /// </summary>
 /// <param name="rect">The rectangle of the QuadTreeNode</param>
 /// <param name="maxItems">Maximum number of items in the QuadTreeNode before partitioning</param>
 /// <param name="worldResize">The function to return the size</param>
 public QuadTreeNode(FRect rect, int maxItems, ResizeDelegate worldResize)
 {
     ParentNode    = null;
     Rect          = rect;
     MaxItems      = maxItems;
     WorldResize   = worldResize;
     IsPartitioned = false;
     Items         = new List <QuadTreePositionItem <T> >();
 }
Exemple #8
0
        /// <summary>
        /// Resizes the Quadtree field
        /// </summary>
        /// <param name="newWorld">The new field</param>
        /// <remarks>This is an expensive operation, so try to initialize the world to a big enough size</remarks>
        public void Resize(FRect newWorld)
        {
            // Get all of the items in the tree
            List <QuadTreePositionItem <T> > Components = new List <QuadTreePositionItem <T> >();

            GetAllItems(ref Components);

            // Destroy the head node
            headNode.Destroy();
            headNode = null;

            // Create a new head
            headNode = new QuadTreeNode <T>(newWorld, maxItems, Resize);

            // Reinsert the items
            foreach (QuadTreePositionItem <T> m in Components)
            {
                headNode.Insert(m);
            }
        }
Exemple #9
0
 public bool Intersects(FRect Rect)
 {
     return (!(Bottom < Rect.Top ||
                Top > Rect.Bottom ||
                Right < Rect.Left ||
                Left > Rect.Right));
 }
Exemple #10
0
 /// <summary>
 /// QuadTree constructor
 /// </summary>
 /// <param name="worldRect">The world rectangle for this QuadTree (a rectangle containing all items at all times)</param>
 /// <param name="maxItems">Maximum number of items in any cell of the QuadTree before partitioning</param>
 public QuadTree(FRect worldRect, int maxItems)
 {
     this.headNode = new QuadTreeNode <T>(worldRect, maxItems, Resize);
     this.maxItems = maxItems;
 }
Exemple #11
0
 public static Rectangle GetRectangle(FRect rect)
 {
     return(new Rectangle((int)rect.Left, (int)rect.Top, (int)rect.Width, (int)rect.Height));
 }