Further simplify packing algorithm and increase default width

This commit is contained in:
Jarrod Doyle 2024-08-28 22:18:20 +01:00
parent f6ef623bb4
commit e499cfcbfc
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 2 additions and 6 deletions

View File

@ -13,7 +13,7 @@ public static class RectPacker
public ushort Height; public ushort Height;
} }
public static Rect Pack(Rect[] rectangles, ushort width = 1024, ushort minHeight = 512) public static Rect Pack(Rect[] rectangles, ushort width = 2048, ushort minHeight = 512)
{ {
ArgumentNullException.ThrowIfNull(rectangles); ArgumentNullException.ThrowIfNull(rectangles);
ArgumentOutOfRangeException.ThrowIfZero(width); ArgumentOutOfRangeException.ThrowIfZero(width);
@ -40,15 +40,11 @@ public static class RectPacker
for (var i = 0; i < rectCount; i++) for (var i = 0; i < rectCount; i++)
{ {
var rect = rectangles[i]; var rect = rectangles[i];
if (x + rect.Width > bounds.Width) if (x + rect.Width > width)
{ {
x = 0; x = 0;
y += rowMaxH; y += rowMaxH;
rowMaxH = rect.Height; rowMaxH = rect.Height;
if (y + rowMaxH > bounds.Height)
{
bounds.Height *= 2;
}
} }
rect.X = x; rect.X = x;