/// <summary> /// Insert an item into this QuadTree with the specified Bounds /// </summary> /// <param name="item">the item to insert</param> /// <param name="bounds">the bounds of the item</param> /// <returns>true if the item could be inserted, false otherwise</returns> public bool Insert(T item, Bounds bounds) { BoundsLink <T> member = new BoundsLink <T>(item, bounds); bool ret = Insert(member); if (ret) { AllMembers.Add(member); } return(ret); }
private bool Insert(BoundsLink <T> member) { // make sure we intersect with the bounds of this object if (!Bounds.IntersectsWith(member.bounds, true)) { return(false); } if (Members.Count < MaxReferencesPerTree) { Members.Add(member); return(true); } // else we are full, but need to store this object if (!IsDivided) { Subdivide(); } bool Inserted = false; if (SW.Insert(member)) { Inserted = true; } if (NW.Insert(member)) { Inserted = true; } if (NE.Insert(member)) { Inserted = true; } if (SE.Insert(member)) { Inserted = true; } return(Inserted); }