/// <summary> /// Utilities /// </summary> #if DEBUG_QUADTREE public void DrawDebugLines() { QtAlgo.TraverseAllLeaves(_root, (leaf) => { Color c = Color.black; if (leaf == _focusLeaf) { c = Color.blue; } else if (_swapInQueue.Contains(leaf)) { c = Color.green; } else if (_swapOutQueue.Contains(leaf)) { c = Color.red; } else if (_holdingLeaves.Contains(leaf)) { c = Color.white; } if (_holdingLeaves.Contains(leaf)) { c = Color.yellow; } if (leaf.AffectedObjects != null && leaf.AffectedObjects.Count > 0) { c = Color.magenta; } QTreeUtil.DrawRect(leaf.Bound, 0f, c, 0.2f); }); }
public virtual void Receive(IQtUserData userData) { if (!QtAlgo.Intersects(Bound, userData)) { return; } for (int i = 0; i < SubNodes.Length; ++i) { SubNodes[i].Receive(userData); } }
private bool UpdateFocus(Vector2 focusPoint) { _focusPoint = focusPoint; QtLeaf newLeaf = QtAlgo.FindLeafRecursively(_root, _focusPoint); if (newLeaf == _focusLeaf || newLeaf == null) { return(false); } _focusLeaf = newLeaf; return(true); }
public override void Receive(IQtUserData userData) { if (!QtAlgo.Intersects(Bound, userData)) { return; } //if (Bound.Contains(userData.GetCenter())) //{ // _ownedObjects.Add(userData); //} else //{ // _affectedObjects.Add(userData); //} _affectedObjects.Add(userData); }
private void PerformSwapInOut(QtLeaf activeLeaf) { // 1. the initial in/out leaves generation List <QtLeaf> inLeaves; List <QtLeaf> outLeaves; QtAlgo.GenerateSwappingLeaves(_root, activeLeaf, _holdingLeaves, out inLeaves, out outLeaves); // 2. filter out leaves which are already in the ideal states if (inLeaves != null) { inLeaves.RemoveAll((leaf) => { return(_swapInQueue.Contains(leaf)); }); } // 3. append these new items to in/out queue if (outLeaves != null && outLeaves.Count > 0) { SwapOut(outLeaves); } if (inLeaves != null & inLeaves.Count > 0) { SwapIn(inLeaves); } }
public QuadTree(Rect bound) { _root = new QtNode(bound); QtAlgo.BuildRecursively(_root); }