Exemplo n.º 1
0
        public bool Delete(ref VMObstacleSetNode node, VMEntityObstacle rect, ref VMObstacleSetNode parent)
        {
            if (rect.Parent == (node.Rect as VMEntityObstacle).Parent)
            {
                if (parent.Index == node.Index)
                {
                    Root = -1;
                }
                else
                {
                    if (parent.LeftChild == node.Index)
                    {
                        parent.LeftChild = -1;
                    }
                    if (parent.RightChild == node.Index)
                    {
                        parent.RightChild = -1;
                    }
                }
                if (node.LeftChild != -1)
                {
                    RecursiveReAdd(Nodes[node.LeftChild]);
                }
                if (node.RightChild != -1)
                {
                    RecursiveReAdd(Nodes[node.RightChild]);
                }
                Reclaim(node.Index);
                return(true);
            }
            //search in child nodes.
            //binary search to find equal opposing edges.

            bool rightSide = false;

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

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

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

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

            return((rightSide && node.RightChild != -1 && Delete(ref Nodes[node.RightChild], rect, ref node)) ||
                   (!rightSide && node.LeftChild != -1 && Delete(ref Nodes[node.LeftChild], rect, ref node)));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 3
0
 public bool Delete(VMEntityObstacle rect)
 {
     if (Root == null)
     {
         return(false);
     }
     else
     {
         var result = Root.Delete(rect, null, this);
         if (!result)
         {
         }
         return(result);
     }
 }
Exemplo n.º 4
0
 public bool Delete(VMEntityObstacle rect)
 {
     if (Root == -1)
     {
         return(false);
     }
     else
     {
         var result = Delete(ref Nodes[Root], rect, ref Nodes[Root]);
         if (result)
         {
             Count--;
         }
         return(result);
     }
 }