Exemple #1
0
 public VMObstacleSetOld(VMObstacleSetOld last)
 {
     if (last.Root != null)
     {
         Count = last.Count;
         Root  = new VMObstacleSetNodeOld(last.Root);
     }
 }
Exemple #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)));
        }
Exemple #3
0
 public void RecursiveReAdd(VMObstacleSetNodeOld node)
 {
     Count--;
     Add(node.Rect);
     if (node.LeftChild != null)
     {
         RecursiveReAdd(node.LeftChild);
     }
     if (node.RightChild != null)
     {
         RecursiveReAdd(node.RightChild);
     }
 }
Exemple #4
0
 public VMObstacleSetNodeOld(VMObstacleSetNodeOld last)
 {
     Rect      = last.Rect;
     Dimension = last.Dimension;
     if (last.LeftChild != null)
     {
         LeftChild = new VMObstacleSetNodeOld(last.LeftChild);
     }
     if (last.RightChild != null)
     {
         RightChild = new VMObstacleSetNodeOld(last.RightChild);
     }
 }
Exemple #5
0
        public void AddAsChild(VMObstacle rect)
        {
            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;
            }
            if (rightSide)
            {
                if (RightChild != null)
                {
                    RightChild.AddAsChild(rect);
                }
                else
                {
                    RightChild = new VMObstacleSetNodeOld
                    {
                        Dimension = (IntersectRectDimension)(((int)Dimension + 1) % 4),
                        Rect      = rect
                    };
                }
            }
            else
            {
                if (LeftChild != null)
                {
                    LeftChild.AddAsChild(rect);
                }
                else
                {
                    LeftChild = new VMObstacleSetNodeOld
                    {
                        Dimension = (IntersectRectDimension)(((int)Dimension + 1) % 4),
                        Rect      = rect
                    };
                }
            }
        }
Exemple #6
0
 public void Add(VMObstacle rect)
 {
     Count++;
     if (Root == null)
     {
         Root = new VMObstacleSetNodeOld
         {
             Dimension = IntersectRectDimension.Left,
             Rect      = rect
         };
     }
     else
     {
         Root.AddAsChild(rect);
     }
 }