public bool Remove(ObjectWithBounds obj) { if (!bounds.Intersects(obj.Bounds)) { return(false); } if (objects.Remove(obj)) { return(true); } if (isDivided) { if (northEast.Remove(obj)) { return(true); } if (northWest.Remove(obj)) { return(true); } if (southEast.Remove(obj)) { return(true); } if (southWest.Remove(obj)) { return(true); } } return(false); }
public bool Insert(ObjectWithBounds obj) { if (!bounds.Intersects(obj.Bounds)) { return(false); } if (!isDivided && objects.Count < capacity) { objects.Add(obj); return(true); } // Need to divide, if not already if (!isDivided) { Subdivide(); } northEast.Insert(obj); northWest.Insert(obj); southEast.Insert(obj); southWest.Insert(obj); return(true); }