public void UpdateItem(IQuadTreeItem item) { var newPosInfo = item.currentPosInQuadTree; GetPosInfo(item.size, item.center, ref newPosInfo); if (newPosInfo.Equals(item.lastPosInQuadTree)) { return; } var currentParent = _root; if (item.lastPosInQuadTree.posInDepths != null) { for (int i = 0; i < item.lastPosInQuadTree.storeDepth; i++) { var currentDepthPosInfo = item.lastPosInQuadTree.posInDepths[i]; currentParent.totalItemsCount -= 1; if (i == item.lastPosInQuadTree.storeDepth - 1) { currentParent.childNodes[currentDepthPosInfo.rowIndex, currentDepthPosInfo.columnIndex].RemoveItem(item); } else { currentParent = currentParent.childNodes[currentDepthPosInfo.rowIndex, currentDepthPosInfo.columnIndex]; } } } if (this.debug) { Debug.Log("Remove item in:" + item.lastPosInQuadTree); Debug.Log("Add item in:" + newPosInfo); } //item.currentPosInQuadTree.Copy( newPosInfo ); var lastPos = item.lastPosInQuadTree; lastPos.Copy(newPosInfo); item.lastPosInQuadTree = lastPos; currentParent = _root; if (item.lastPosInQuadTree.inRoot) { _root.AddItem(item); return; } for (int i = 0; i < newPosInfo.storeDepth; i++) { var currentDepthPosInfo = newPosInfo.posInDepths[i]; currentParent.totalItemsCount += 1; if (i == newPosInfo.storeDepth - 1) { currentParent.childNodes[currentDepthPosInfo.rowIndex, currentDepthPosInfo.columnIndex].AddItem(item); } else { currentParent = currentParent.childNodes[currentDepthPosInfo.rowIndex, currentDepthPosInfo.columnIndex]; } } }
public void RemoveItem(IQuadTreeItem item) { totalItemsCount -= 1; items.Remove(item); }
public void AddItem(IQuadTreeItem item) { items.Add(item); totalItemsCount += 1; }