Skip to content

Commit e3c8f32

Browse files
committed
Add array overload to Pack method on NET5.0
1 parent 8826d15 commit e3c8f32

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

RectpackSharp/RectanglePacker.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ public static void Pack(PackingRectangle[] rectangles, out PackingRectangle boun
147147
ReturnList(emptySpaces);
148148
}
149149

150+
#if NET5_0_OR_GREATER
151+
/// <summary>
152+
/// Finds a way to pack all the given rectangles into a single bin. Performance can be traded for
153+
/// space efficiency by using the optional parameters.
154+
/// </summary>
155+
/// <param name="rectangles">The rectangles to pack. The result is saved onto this array.</param>
156+
/// <param name="bounds">The bounds of the resulting bin. This will always be at X=Y=0.</param>
157+
/// <param name="packingHint">Specifies hints for optimizing performance.</param>
158+
/// <param name="acceptableDensity">Searching stops once a bin is found with this density (usedArea/boundsArea) or better.</param>
159+
/// <param name="stepSize">The amount by which to increment/decrement size when trying to pack another bin.</param>
160+
/// <param name="maxBoundsWidth">The maximum allowed width for the resulting bin, or null for no limit.</param>
161+
/// <param name="maxBoundsHeight">The maximum allowed height for the resulting bin, or null for no limit.</param>
162+
/// <remarks>
163+
/// The <see cref="PackingRectangle.Id"/> values are never touched. Use this to identify your rectangles.
164+
/// </remarks>
165+
public static void Pack(PackingRectangle[] rectangles, out PackingRectangle bounds,
166+
PackingHints packingHint = PackingHints.FindBest, double acceptableDensity = 1, uint stepSize = 1,
167+
uint? maxBoundsWidth = null, uint? maxBoundsHeight = null)
168+
{
169+
Pack(rectangles.AsSpan(), out bounds, packingHint, acceptableDensity, stepSize, maxBoundsWidth, maxBoundsHeight);
170+
}
171+
#endif
172+
150173
/// <summary>
151174
/// Tries to find a solution with the smallest bin size possible, packing
152175
/// the rectangles in the order in which the were provided.

0 commit comments

Comments
 (0)