/// <summary> /// Adds an item to the <see cref="QuadTree{T}"/>. No duplicates. /// </summary> /// <param name="item">Item to add.</param> public virtual void Add(T item) { if (itemDictionary.ContainsKey(item)) { return; } if (rootTree.Add(item)) { itemDictionary.Add(item, new XY(item.X, item.Y)); } }
/// <summary> /// Recursively adds an item to the quadtree. /// </summary> /// <param name="item">Item to add.</param> /// <returns>True if successful, false if not.</returns> public virtual bool Add(T item) { if (!Boundary.ContainsPoint(item)) { return(false); } if (items.Count < QT_NODE_CAPACITY) { items.Add(item); return(true); } if (northWest == null) { subdivide(); } if (northWest.Add(item)) { return(true); } if (northEast.Add(item)) { return(true); } if (southWest.Add(item)) { return(true); } if (southEast.Add(item)) { return(true); } return(false); // This shouldn't happen }