예제 #1
0
 public VMObstacleSetOld(VMObstacleSetOld last)
 {
     if (last.Root != null)
     {
         Count = last.Count;
         Root  = new VMObstacleSetNodeOld(last.Root);
     }
 }
예제 #2
0
        public bool Delete(VMEntityObstacle rect, VMObstacleSetNodeOld parent, VMObstacleSetOld set)
        {
            if (rect.Parent == (Rect as VMEntityObstacle).Parent)
            {
                if (parent == null)
                {
                    set.Root = null;
                }
                else
                {
                    if (parent.LeftChild == this)
                    {
                        parent.LeftChild = null;
                    }
                    if (parent.RightChild == this)
                    {
                        parent.RightChild = null;
                    }
                }
                if (LeftChild != null)
                {
                    set.RecursiveReAdd(LeftChild);
                }
                if (RightChild != null)
                {
                    set.RecursiveReAdd(RightChild);
                }
                return(true);
            }
            //search in child nodes.
            //binary search to find equal opposing edges.

            bool rightSide = false;

            switch (Dimension)
            {
            case IntersectRectDimension.Top:
                rightSide = rect.y1 > Rect.y1; break;

            case IntersectRectDimension.Left:
                rightSide = rect.x1 > Rect.x1; break;

            case IntersectRectDimension.Bottom:
                rightSide = rect.y2 > Rect.y2; break;

            case IntersectRectDimension.Right:
                rightSide = rect.x2 > Rect.x2; break;
            }

            return((rightSide && RightChild != null && RightChild.Delete(rect, this, set)) ||
                   (!rightSide && LeftChild != null && LeftChild.Delete(rect, this, set)));
        }