Beispiel #1
0
 public TreeLeaf Insert(int w, int h, int id = -1)
 {
     //return Root.Insert ( w, h );
     if (Root == null)
     {
         Root = new TreeLeaf(new Rect(0, 0, w, h), id)
         {
             Root = this,
             Used = true
         };
         Root.Child[0] = new TreeLeaf(new Rect(0, h, RC.W, RC.H - h));
         Root.Child[1] = new TreeLeaf(new Rect(w, 0, RC.W - w, h));
     }
     else
     {
         return(Root.Insert(w, h));
     }
     return(Root);
 }
Beispiel #2
0
        public TreeLeaf Insert(int w, int h)
        {
            if (Used)
            {
                TreeLeaf rn = Child[0].Insert(w, h);
                if (rn != null)
                {
                    rn.Root = Root;
                    return(rn);
                }
                rn = Child[1].Insert(w, h);
                if (rn != null)
                {
                    rn.Root = Root;
                    return(rn);
                }
            }
            else
            {
                if (w <= RC.W && h <= RC.H)
                {
                    Used = true;

                    Child[0]      = new TreeLeaf(new Rect(RC.X, RC.Y + h, RC.W, RC.H - h));
                    Child[1]      = new TreeLeaf(new Rect(RC.X + w, RC.Y, RC.W - w, h));
                    Child[0].Root = Root;
                    Child[1].Root = Root;
                    RC.W          = w;
                    RC.H          = h;
                    return(this);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }