Esempio n. 1
0
 /// <summary>
 /// Draws the quard tree.
 /// </summary>
 /// <param name="tree">Tree.</param>
 public static void drawQuardTree(QuardTree tree)
 {
     Debug.DrawLine(new Vector3(tree.bound.origin.x, tree.bound.origin.y, 0), new Vector3(tree.bound.origin.x + tree.bound.width, tree.bound.origin.y, 0));
     Debug.DrawLine(new Vector3(tree.bound.origin.x, tree.bound.origin.y, 0), new Vector3(tree.bound.origin.x, tree.bound.origin.y + tree.bound.height, 0));
     if (tree.trees.Count > 0)
     {
         for (int i = 0; i < tree.trees.Count; i++)
         {
             drawQuardTree(tree.trees[i]);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refresh(QuardTree root)
        {
            if (root == null)
            {
                root = this;
            }
            List <Rectangle> removed1 = new List <Rectangle>();
            List <Rectangle> removed2 = new List <Rectangle>();

            foreach (Rectangle rectangle in objs)
            {
                int index = GetIndex(rectangle);
                // 如果矩形不属于该象限,则将该矩形重新插入
                if (!GraphicUtil.isInner(rectangle, bound))
                {
                    if (this != root)
                    {
                        removed1.Add(rectangle);
                    }

                    // 如果矩形属于该象限 且 该象限具有子象限,则
                    // 将该矩形安插到子象限中
                }
                else if (trees.Count > 0 &&
                         index != -1)
                {
                    trees[index].Insert(rectangle);
                    removed2.Add(rectangle);
                }
            }

            for (int i = 0; i < removed1.Count; i++)
            {
                root.Insert(removed1[i]);
                objs.Remove(removed1[i]);
            }
            removed1.Clear();

            for (int i = 0; i < removed2.Count; i++)
            {
                objs.Remove(removed2[i]);
            }
            removed2.Clear();
            foreach (QuardTree quardTree in trees)
            {
                quardTree.Refresh(root);
            }
        }