Further simplify packing algorithm and increase default width
This commit is contained in:
		
							parent
							
								
									f6ef623bb4
								
							
						
					
					
						commit
						e499cfcbfc
					
				| 
						 | 
				
			
			@ -13,7 +13,7 @@ public static class RectPacker
 | 
			
		|||
        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);
 | 
			
		||||
        ArgumentOutOfRangeException.ThrowIfZero(width);
 | 
			
		||||
| 
						 | 
				
			
			@ -40,15 +40,11 @@ public static class RectPacker
 | 
			
		|||
        for (var i = 0; i < rectCount; i++)
 | 
			
		||||
        {
 | 
			
		||||
            var rect = rectangles[i];
 | 
			
		||||
            if (x + rect.Width > bounds.Width)
 | 
			
		||||
            if (x + rect.Width > width)
 | 
			
		||||
            {
 | 
			
		||||
                x = 0;
 | 
			
		||||
                y += rowMaxH;
 | 
			
		||||
                rowMaxH = rect.Height;
 | 
			
		||||
                if (y + rowMaxH > bounds.Height)
 | 
			
		||||
                {
 | 
			
		||||
                    bounds.Height *= 2;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            rect.X = x;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue