/// <summary> /// Insert an item to this node /// </summary> /// <param name="item"></param> public void Insert(IOctTreeElement item) { // if the item is not contained in this quad, there's a problem if (item.Contains(this)) { Trace.TraceWarning("feature is out of the bounds of this Octa-tree node"); return; } // if the subnodes are null create them. if (childNode.Count == 0) CreateSubNodes(); // for each subnode: // if the node contains the item, add the item to that node and return // this recurses into the node that is just large enough to fit this item foreach (OctTreeNode node in childNode) { if (item.isInside(node)) { node.Insert(item); return; } } // if we make it to here, either // 1) none of the subnodes completely contained the item. or // 2) we're at the smallest subnode size allowed // add the item to this node's contents. this.Items.Add(item); }
/// <summary> /// Insert the feature into the QuadTree /// </summary> /// <param name="item"></param> public void Insert(IOctTreeElement item) { if (!item.isInside(root)) { item.isInside(root); throw new Exception("Item Is out of OctTree Range"); } root.Insert(item); }