Example #1
0
        public bool Move(T node)
        {
            if (!Contains(node))
            {
                // We did not have the node previously
                return(false);
            }

            // We had the node previously
            if (parent != null && !CompletelyContains(node))
            {
                // Node has moved out of our scope
                Remove(node);
                // Bubbles the "Add" function until it finds either the root or a leaf that completely contains the node
                return(parent.BubbleAdd(node));
            }

            if (leafs[0] != null)
            {
                // Find the new leaf (if any) to put the node in
                foreach (QuadLeaf <T> leaf in leafs)
                {
                    if (leaf.Move(node))
                    {
                        return(true);
                    }
                }
            }

            // The node didn't move past our own bounds, and we are the smallest leaf
            // OR the node now doesn't fit any leaf and we are the root
            return(true);
        }