Exemplo n.º 1
0
            /// <summary>
            /// Removes an item from this Quadrant.
            /// Returns true if item was found and removed, false otherwise.
            /// </summary>
            public bool Remove(T item, Rect bounds)
            {
                bool removed;

                if (TopRight != null && topRightBounds.Contains(bounds))
                {
                    removed = TopRight.Remove(item, bounds);
                }
                else if (TopLeft != null && topLeftBounds.Contains(bounds))
                {
                    removed = TopLeft.Remove(item, bounds);
                }
                else if (BottomRight != null && bottomRightBounds.Contains(bounds))
                {
                    removed = BottomRight.Remove(item, bounds);
                }
                else if (BottomLeft != null && bottomLeftBounds.Contains(bounds))
                {
                    removed = BottomLeft.Remove(item, bounds);
                }
                else
                {
                    removed = ItemsInQuadrant.Remove(item);
                }

                if (removed)
                {
                    Count--;
                }
                return(removed);
            }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a new item into the Quadrant.
 /// </summary>
 public void Add(T item, Rect bounds)
 {
     if (!LastLevelQuadrant)
     {
         if (topRightBounds.Contains(bounds))
         {
             TopRight ??= new Quadrant(topRightBounds);
             TopRight.Add(item, bounds);
         }
         else if (topLeftBounds.Contains(bounds))
         {
             TopLeft ??= new Quadrant(topLeftBounds);
             TopLeft.Add(item, bounds);
         }
         else if (bottomRightBounds.Contains(bounds))
         {
             BottomRight ??= new Quadrant(bottomRightBounds);
             BottomRight.Add(item, bounds);
         }
         else if (bottomLeftBounds.Contains(bounds))
         {
             BottomLeft ??= new Quadrant(bottomLeftBounds);
             BottomLeft.Add(item, bounds);
         }
         else
         {
             ItemsInQuadrant.Add(item);
         }
     }
     else
     {
         ItemsInQuadrant.Add(item);
     }
     Count++;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Clears this collection.
 /// </summary>
 public void Clear()
 {
     TopRight    = null;
     TopLeft     = null;
     BottomRight = null;
     BottomLeft  = null;
     ItemsInQuadrant.Clear();
     Count = 0;
 }
Exemplo n.º 4
0
            /// <summary>
            /// Checks if specified item is inside this collection.
            /// </summary>
            public bool Contains(T item)
            {
                var bounds = item.Bounds;

                return(TopRight != null && TopRight.Extent.IntersectsWith(bounds) && TopRight.Contains(item) ||
                       TopLeft != null && TopLeft.Extent.IntersectsWith(bounds) && TopLeft.Contains(item) ||
                       BottomRight != null && BottomRight.Extent.IntersectsWith(bounds) && BottomRight.Contains(item) ||
                       BottomLeft != null && BottomLeft.Extent.IntersectsWith(bounds) && BottomLeft.Contains(item) ||
                       ItemsInQuadrant.Contains(item));
            }