Exemple #1
0
        /// <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);
            });
        }
Exemple #2
0
 public virtual void Receive(IQtUserData userData)
 {
     if (!QtAlgo.Intersects(Bound, userData))
     {
         return;
     }
     for (int i = 0; i < SubNodes.Length; ++i)
     {
         SubNodes[i].Receive(userData);
     }
 }
Exemple #3
0
        private bool UpdateFocus(Vector2 focusPoint)
        {
            _focusPoint = focusPoint;

            QtLeaf newLeaf = QtAlgo.FindLeafRecursively(_root, _focusPoint);

            if (newLeaf == _focusLeaf || newLeaf == null)
            {
                return(false);
            }
            _focusLeaf = newLeaf;

            return(true);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
 public QuadTree(Rect bound)
 {
     _root = new QtNode(bound);
     QtAlgo.BuildRecursively(_root);
 }