From e3c8f322395c0cf83706b9dbd8f9e749696f4af8 Mon Sep 17 00:00:00 2001 From: ThomasMiz <32400648+ThomasMiz@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:25:44 -0300 Subject: [PATCH] Add array overload to Pack method on NET5.0 --- RectpackSharp/RectanglePacker.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/RectpackSharp/RectanglePacker.cs b/RectpackSharp/RectanglePacker.cs index 76f43e6..7191b51 100644 --- a/RectpackSharp/RectanglePacker.cs +++ b/RectpackSharp/RectanglePacker.cs @@ -147,6 +147,29 @@ public static void Pack(PackingRectangle[] rectangles, out PackingRectangle boun ReturnList(emptySpaces); } +#if NET5_0_OR_GREATER + /// + /// Finds a way to pack all the given rectangles into a single bin. Performance can be traded for + /// space efficiency by using the optional parameters. + /// + /// The rectangles to pack. The result is saved onto this array. + /// The bounds of the resulting bin. This will always be at X=Y=0. + /// Specifies hints for optimizing performance. + /// Searching stops once a bin is found with this density (usedArea/boundsArea) or better. + /// The amount by which to increment/decrement size when trying to pack another bin. + /// The maximum allowed width for the resulting bin, or null for no limit. + /// The maximum allowed height for the resulting bin, or null for no limit. + /// + /// The values are never touched. Use this to identify your rectangles. + /// + public static void Pack(PackingRectangle[] rectangles, out PackingRectangle bounds, + PackingHints packingHint = PackingHints.FindBest, double acceptableDensity = 1, uint stepSize = 1, + uint? maxBoundsWidth = null, uint? maxBoundsHeight = null) + { + Pack(rectangles.AsSpan(), out bounds, packingHint, acceptableDensity, stepSize, maxBoundsWidth, maxBoundsHeight); + } +#endif + /// /// Tries to find a solution with the smallest bin size possible, packing /// the rectangles in the order in which the were provided.