tk2dEditor.Atlas.MaxRectsBinPack.FindPositionForNewNodeBottomLeft C# (CSharp) Method

FindPositionForNewNodeBottomLeft() private method

private FindPositionForNewNodeBottomLeft ( int width, int height, int &bestY, int &bestX ) : Rect
width int
height int
bestY int
bestX int
return Rect
        Rect FindPositionForNewNodeBottomLeft(int width, int height, ref int bestY, ref int bestX)
        {
            Rect bestNode = new Rect();
            // memset(&bestNode, 0, sizeof(Rect)); // done in constructor

            bestY = Int32.MaxValue;

            for (int i = 0; i < freeRectangles.Count; ++i)
            {
                // Try to place the rectangle in upright (non-flipped) orientation.
                if (freeRectangles[i].width >= width && freeRectangles[i].height >= height)
                {
                    int topSideY = freeRectangles[i].y + height;
                    if (topSideY < bestY || (topSideY == bestY && freeRectangles[i].x < bestX))
                    {
                        bestNode.x = freeRectangles[i].x;
                        bestNode.y = freeRectangles[i].y;
                        bestNode.width = width;
                        bestNode.height = height;
                        bestY = topSideY;
                        bestX = freeRectangles[i].x;
                    }
                }
                if (freeRectangles[i].width >= height && freeRectangles[i].height >= width)
                {
                    int topSideY = freeRectangles[i].y + width;
                    if (topSideY < bestY || (topSideY == bestY && freeRectangles[i].x < bestX))
                    {
                        bestNode.x = freeRectangles[i].x;
                        bestNode.y = freeRectangles[i].y;
                        bestNode.width = height;
                        bestNode.height = width;
                        bestY = topSideY;
                        bestX = freeRectangles[i].x;
                    }
                }
            }
            return bestNode;
        }