/// <summary> /// Add an object to the quad tree. /// It will be distributed to the appropriate leaf and updated when it moves. /// </summary> public void Add(T item) { if (item == null) { return; } Debug.Assert(!Contains(item)); var wrappedObject = new QuadTreeObject <T>(item); _wrappedDictionary.Add(item, wrappedObject); Insert(wrappedObject); wrappedObject.AttachToQuadTree(); }
/// <summary> /// Remove an object from the tree, whichever leaf it is located in. /// </summary> public bool Remove(T item) { if (item == null) { return(false); } if (!Contains(item)) { return(false); } // Remove from the tree. QuadTreeObject <T> wrappedItem = _wrappedDictionary[item]; wrappedItem.DetachFromQuadTree(); _wrappedDictionary.Remove(item); // Remove the item from its owner. wrappedItem.Owner.Remove(wrappedItem); wrappedItem.Owner.RemoveEmptyLeavesUpwards(); return(true); }