MaxRectsBinPack FindBestBinPacker(int width, int height, ref List <RectSize> currRects, ref bool allUsed)
        {
            List <MaxRectsBinPack>  binPackers       = new List <MaxRectsBinPack>();
            List <List <RectSize> > binPackerRects   = new List <List <RectSize> >();
            List <bool>             binPackerAllUsed = new List <bool>();

            //MaxRectsBinPack.FreeRectChoiceHeuristic[] heuristics = { MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestAreaFit,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestShortSideFit,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectBottomLeftRule,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectContactPointRule };

            MaxRectsBinPack.FreeRectChoiceHeuristic[] heuristics = { MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestAreaFit,
                                                                     MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit,
                                                                     MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestShortSideFit,
                                                                     MaxRectsBinPack.FreeRectChoiceHeuristic.RectBottomLeftRule, };

            foreach (var heuristic in heuristics)
            {
                MaxRectsBinPack binPacker     = new MaxRectsBinPack(width, height);
                List <RectSize> activeRects   = new List <RectSize>(currRects);
                bool            activeAllUsed = binPacker.Insert(activeRects, heuristic);

                binPackers.Add(binPacker);
                binPackerRects.Add(activeRects);
                binPackerAllUsed.Add(activeAllUsed);
            }

            int leastWastedPixels = Int32.MaxValue;
            int leastWastedIndex  = -1;

            for (int i = 0; i < binPackers.Count; ++i)
            {
                int wastedPixels = binPackers[i].WastedBinArea();
                if (wastedPixels < leastWastedPixels)
                {
                    leastWastedPixels = wastedPixels;
                    leastWastedIndex  = i;
                    oversizeTextures  = true;
                }
            }

            currRects = binPackerRects[leastWastedIndex];
            allUsed   = binPackerAllUsed[leastWastedIndex];
            return(binPackers[leastWastedIndex]);
        }
        MaxRectsBinPack FindBestBinPacker(int width, int height, ref List<RectSize> currRects, ref bool allUsed)
        {
            List<MaxRectsBinPack> binPackers = new List<MaxRectsBinPack>();
            List<List<RectSize>> binPackerRects = new List<List<RectSize>>();
            List<bool> binPackerAllUsed = new List<bool>();

            //MaxRectsBinPack.FreeRectChoiceHeuristic[] heuristics = { MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestAreaFit,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestShortSideFit,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectBottomLeftRule,
            //                                                         MaxRectsBinPack.FreeRectChoiceHeuristic.RectContactPointRule };

            MaxRectsBinPack.FreeRectChoiceHeuristic[] heuristics = { MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestAreaFit,
                                                                     MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit,
                                                                     MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestShortSideFit,
                                                                     MaxRectsBinPack.FreeRectChoiceHeuristic.RectBottomLeftRule,
                                                                      };

            foreach (var heuristic in heuristics)
            {
                MaxRectsBinPack binPacker = new MaxRectsBinPack(width, height);
                List<RectSize> activeRects = new List<RectSize>(currRects);
                bool activeAllUsed = binPacker.Insert(activeRects, heuristic);

                binPackers.Add(binPacker);
                binPackerRects.Add(activeRects);
                binPackerAllUsed.Add(activeAllUsed);
            }

            int leastWastedPixels = Int32.MaxValue;
            int leastWastedIndex = -1;
            for (int i = 0; i < binPackers.Count; ++i)
            {
                int wastedPixels = binPackers[i].WastedBinArea();
                if (wastedPixels < leastWastedPixels)
                {
                    leastWastedPixels = wastedPixels;
                    leastWastedIndex = i;
                    oversizeTextures = true;
                }
            }

            currRects = binPackerRects[leastWastedIndex];
            allUsed = binPackerAllUsed[leastWastedIndex];
            return binPackers[leastWastedIndex];
        }