public void Set(int ww, int hh, MB2_TexturePacker.Node r, bool fits, float e, float sq)
 {
     this.w             = ww;
     this.h             = hh;
     this.root          = r;
     this.fitsInMaxSize = fits;
     this.efficiency    = e;
     this.squareness    = sq;
 }
            public MB2_TexturePacker.Node Insert(MB2_TexturePacker.Image im, bool handed)
            {
                int num;
                int num2;

                if (handed)
                {
                    num  = 0;
                    num2 = 1;
                }
                else
                {
                    num  = 1;
                    num2 = 0;
                }
                if (!this.isLeaf())
                {
                    MB2_TexturePacker.Node node = this.child[num].Insert(im, handed);
                    if (node != null)
                    {
                        return(node);
                    }
                    return(this.child[num2].Insert(im, handed));
                }
                else
                {
                    if (this.img != null)
                    {
                        return(null);
                    }
                    if (this.r.w < im.w || this.r.h < im.h)
                    {
                        return(null);
                    }
                    if (this.r.w == im.w && this.r.h == im.h)
                    {
                        this.img = im;
                        return(this);
                    }
                    this.child[num]  = new MB2_TexturePacker.Node();
                    this.child[num2] = new MB2_TexturePacker.Node();
                    int num3 = this.r.w - im.w;
                    int num4 = this.r.h - im.h;
                    if (num3 > num4)
                    {
                        this.child[num].r  = new MB2_TexturePacker.PixRect(this.r.x, this.r.y, im.w, this.r.h);
                        this.child[num2].r = new MB2_TexturePacker.PixRect(this.r.x + im.w, this.r.y, this.r.w - im.w, this.r.h);
                    }
                    else
                    {
                        this.child[num].r  = new MB2_TexturePacker.PixRect(this.r.x, this.r.y, this.r.w, im.h);
                        this.child[num2].r = new MB2_TexturePacker.PixRect(this.r.x, this.r.y + im.h, this.r.w, this.r.h - im.h);
                    }
                    return(this.child[num].Insert(im, handed));
                }
            }
 private static void printTree(MB2_TexturePacker.Node r, string spc)
 {
     if (r.child[0] != null)
     {
         MB2_TexturePacker.printTree(r.child[0], spc + "  ");
     }
     if (r.child[1] != null)
     {
         MB2_TexturePacker.printTree(r.child[1], spc + "  ");
     }
 }
 private static void flattenTree(MB2_TexturePacker.Node r, List <MB2_TexturePacker.Image> putHere)
 {
     if (r.img != null)
     {
         r.img.x = r.r.x;
         r.img.y = r.r.y;
         putHere.Add(r.img);
     }
     if (r.child[0] != null)
     {
         MB2_TexturePacker.flattenTree(r.child[0], putHere);
     }
     if (r.child[1] != null)
     {
         MB2_TexturePacker.flattenTree(r.child[1], putHere);
     }
 }
 private void GetExtent(MB2_TexturePacker.Node r, ref int x, ref int y)
 {
     if (r.img != null)
     {
         if (r.r.x + r.img.w > x)
         {
             x = r.r.x + r.img.w;
         }
         if (r.r.y + r.img.h > y)
         {
             y = r.r.y + r.img.h;
         }
     }
     if (r.child[0] != null)
     {
         this.GetExtent(r.child[0], ref x, ref y);
     }
     if (r.child[1] != null)
     {
         this.GetExtent(r.child[1], ref x, ref y);
     }
 }
        private static void drawGizmosNode(MB2_TexturePacker.Node r)
        {
            Vector3 size   = new Vector3((float)r.r.w, (float)r.r.h, 0f);
            Vector3 center = new Vector3((float)r.r.x + size.x / 2f, (float)(-(float)r.r.y) - size.y / 2f, 0f);

            Gizmos.DrawWireCube(center, size);
            if (r.img != null)
            {
                Gizmos.color = Color.blue;
                size         = new Vector3((float)r.img.w, (float)r.img.h, 0f);
                center       = new Vector3((float)r.img.x + size.x / 2f, (float)(-(float)r.img.y) - size.y / 2f, 0f);
                Gizmos.DrawCube(center, size);
            }
            if (r.child[0] != null)
            {
                Gizmos.color = Color.red;
                MB2_TexturePacker.drawGizmosNode(r.child[0]);
            }
            if (r.child[1] != null)
            {
                Gizmos.color = Color.green;
                MB2_TexturePacker.drawGizmosNode(r.child[1]);
            }
        }
 private bool Probe(MB2_TexturePacker.Image[] imgsToAdd, int idealAtlasW, int idealAtlasH, float imgArea, int maxAtlasDim, MB2_TexturePacker.ProbeResult pr)
 {
     MB2_TexturePacker.Node node = new MB2_TexturePacker.Node();
     node.r = new MB2_TexturePacker.PixRect(0, 0, idealAtlasW, idealAtlasH);
     for (int i = 0; i < imgsToAdd.Length; i++)
     {
         if (node.Insert(imgsToAdd[i], false) == null)
         {
             return(false);
         }
         if (i == imgsToAdd.Length - 1)
         {
             int num  = 0;
             int num2 = 0;
             this.GetExtent(node, ref num, ref num2);
             bool  flag;
             float num8;
             float num9;
             if (this.doPowerOfTwoTextures)
             {
                 int num3 = Mathf.Min(this.CeilToNearestPowerOfTwo(num), maxAtlasDim);
                 int num4 = Mathf.Min(this.CeilToNearestPowerOfTwo(num2), maxAtlasDim);
                 if (num4 < num3 / 2)
                 {
                     num4 = num3 / 2;
                 }
                 if (num3 < num4 / 2)
                 {
                     num3 = num4 / 2;
                 }
                 flag = (num <= maxAtlasDim && num2 <= maxAtlasDim);
                 float num5 = Mathf.Max(1f, (float)num / (float)maxAtlasDim);
                 float num6 = Mathf.Max(1f, (float)num2 / (float)maxAtlasDim);
                 float num7 = (float)num3 * num5 * (float)num4 * num6;
                 num8 = 1f - (num7 - imgArea) / num7;
                 num9 = 1f;
             }
             else
             {
                 num8 = 1f - ((float)(num * num2) - imgArea) / (float)(num * num2);
                 if (num < num2)
                 {
                     num9 = (float)num / (float)num2;
                 }
                 else
                 {
                     num9 = (float)num2 / (float)num;
                 }
                 flag = (num <= maxAtlasDim && num2 <= maxAtlasDim);
             }
             pr.Set(num, num2, node, flag, num8, num9);
             if (this.LOG_LEVEL >= MB2_LogLevel.debug)
             {
                 MB2_Log.LogDebug(string.Concat(new object[]
                 {
                     "Probe success efficiency w=",
                     num,
                     " h=",
                     num2,
                     " e=",
                     num8,
                     " sq=",
                     num9,
                     " fits=",
                     flag
                 }), new object[0]);
             }
             return(true);
         }
     }
     Debug.LogError("Should never get here.");
     return(false);
 }