public void Insert(T item) { if (!RectUtils.Contains(m_BoundingRect, item.boundingRect)) { Rect intersection = new Rect(); if (!RectUtils.Intersection(item.boundingRect, m_BoundingRect, out intersection)) { // Ignore elements completely outside the quad tree return; } } if (m_ChildrenNodes.Count == 0) { Subdivide(); } // insert into children nodes foreach (QuadTreeNode <T> node in m_ChildrenNodes) { if (RectUtils.Contains(node.BoundingRect, item.boundingRect)) { node.Insert(item); return; } } // item is not completely contained in any of the children nodes // insert here this.m_Elements.Add(item); }
public void Insert(T item) { if (!RectUtils.Contains(this.m_BoundingRect, item.boundingRect)) { Rect intersection = new Rect(); if (!RectUtils.Intersection(item.boundingRect, this.m_BoundingRect, out intersection)) { return; } } if (this.m_ChildrenNodes.Count == 0) { this.Subdivide(); } using (List <QuadTreeNode <T> > .Enumerator enumerator = this.m_ChildrenNodes.GetEnumerator()) { while (enumerator.MoveNext()) { QuadTreeNode <T> current = enumerator.Current; if (RectUtils.Contains(current.BoundingRect, item.boundingRect)) { current.Insert(item); return; } } } this.m_Elements.Add(item); }
public void Insert(T item) { if (!RectUtils.Contains(this.m_BoundingRect, item.boundingRect)) { Rect intersection = new Rect(); if (!RectUtils.Intersection(item.boundingRect, this.m_BoundingRect, out intersection)) { return; } } if (this.m_ChildrenNodes.Count == 0) { this.Subdivide(); } foreach (QuadTreeNode <T> node in this.m_ChildrenNodes) { if (RectUtils.Contains(node.BoundingRect, item.boundingRect)) { node.Insert(item); return; } } this.m_Elements.Add(item); }
public void Insert(T item) { if (!RectUtils.Contains(this.m_BoundingRect, item.boundingRect)) { Rect rect = default(Rect); if (!RectUtils.Intersection(item.boundingRect, this.m_BoundingRect, out rect)) { return; } } if (this.m_ChildrenNodes.Count == 0) { this.Subdivide(); } foreach (QuadTreeNode <T> current in this.m_ChildrenNodes) { if (RectUtils.Contains(current.BoundingRect, item.boundingRect)) { current.Insert(item); return; } } this.m_Elements.Add(item); }