Пример #1
0
        /// <summary>
        /// Removes an item from <see cref="QuadTree{T}"/> at a specific location.
        /// </summary>
        /// <param name="item">Item that has moved.</param>
        /// <param name="x">Old X coordinate.</param>
        /// <param name="y">Old Y coordinate.</param>
        /// <returns>True if successful, false if not.</returns>
        protected bool removeAt(T item, float x, float y)
        {
            if (rootTree.RemoveAt(item, x, y))
            {
                itemDictionary.Remove(item);
                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Recursively removes an item that changed position.
        /// </summary>
        /// <param name="item">Item that has changed position</param>
        /// <param name="x">Old X coordinate.</param>
        /// <param name="y">Old Y coordinate.</param>
        /// <returns>Item that was removed.</returns>
        public virtual bool RemoveAt(T item, float x, float y)
        {
            if (!Boundary.ContainsPoint(new XY(x, y)))
            {
                return(false);
            }

            if (items.Remove(item))
            {
                return(true);
            }

            if (northWest == null)
            {
                return(false);
            }

            bool removed = false;

            if (northWest.RemoveAt(item, x, y))
            {
                removed = true;
            }
            else if (northEast.RemoveAt(item, x, y))
            {
                removed = true;
            }
            else if (southWest.RemoveAt(item, x, y))
            {
                removed = true;
            }
            else if (southEast.RemoveAt(item, x, y))
            {
                removed = true;
            }

            // If a change was made, check if child trees are empty, if so then remove them.
            if (removed)
            {
                clean();
                return(true);
            }

            return(false);
        }