Class MaxRectsBin
- Assembly
- MonoGame.Framework.Content.Pipeline.dll
A bin that can pack rectangles using the MaxRects algorithm with several heuristics.
public class MaxRectsBin
- Inheritance
-
MaxRectsBin
- Inherited Members
Constructors
MaxRectsBin(int, int, GrowRule, float, bool)
Create a MaxRectsBin instance.
public MaxRectsBin(int width = 64, int height = 64, GrowRule grow = GrowRule.Both, float growIncrement = -2, bool allowRotation = false)
Parameters
width
intInitial available width. Defaults to 64.
height
intInitial available height. Defaults to 64.
grow
GrowRuleWhether to allow growing the available space when a rectangle doesn't fit.
growIncrement
floatDetermines how the bin is grown. A positive value means a fixed size increase, a negative value means a factor increase. E.g. -2 will grow the bin by a factor of 2 when it needs to grow.
allowRotation
boolWhether to allow rotating the rectangles.
Properties
AllowRotations
Indicates if rectangle can be rotated.
public bool AllowRotations { get; }
Property Value
BinHeight
Height of the bin.
public int BinHeight { get; }
Property Value
BinWidth
Width of the bin.
public int BinWidth { get; }
Property Value
Grow
Rule to choose in which dimension to grow.
public GrowRule Grow { get; set; }
Property Value
GrowIncrement
Determines how the bin is grown. A positive value means a fixed size increase, a negative value means a factor increase. E.g. -2 will grow the bin by a factor of 2 when it needs to grow.
public float GrowIncrement { get; set; }
Property Value
GrowLimit
The number of times to grow the bin for a single rectangle when it doesn't fit. Defaults to 3.
public int GrowLimit { get; set; }
Property Value
IncludePadding
Determines if padding is included in returned rectangles. Default is false
.
public bool IncludePadding { get; set; }
Property Value
PaddingHeight
Padding to add to both sides in the vertical dimension. Default is 0.
public int PaddingHeight { get; set; }
Property Value
PaddingWidth
Padding to add to both sides in the horizontal dimension. Default is 0.
public int PaddingWidth { get; set; }
Property Value
UsedHeight
The actually used height of the bin.
public int UsedHeight { get; }
Property Value
UsedWidth
The actually used width of the bin.
public int UsedWidth { get; }
Property Value
Methods
GetOccupancy(bool)
Computes the ratio of used surface area.
public float GetOccupancy(bool crop = false)
Parameters
crop
boolIf
true
this uses UsedWidth and UsedHeight instead of BinWidth and BinHeight for available area.
Returns
Insert(Point[], MaxRectsHeuristic)
Place an array of rectangles in the bin.
public Rectangle[] Insert(Point[] sizes, MaxRectsHeuristic heuristic = MaxRectsHeuristic.Bssf)
Parameters
sizes
Point[]Sizes of the rectangles.
heuristic
MaxRectsHeuristicHeuristic to use.
Returns
- Rectangle[]
Bounds of all rectangles after placement.
Exceptions
- ArgumentNullException
If
sizes
isnull
.
Insert(Point[], Rectangle[], int, MaxRectsHeuristic)
Place an array of rectangles in the bin.
public void Insert(Point[] sizes, Rectangle[] bounds, int indexOffset = 0, MaxRectsHeuristic heuristic = MaxRectsHeuristic.Bssf)
Parameters
sizes
Point[]Sizes of the rectangles.
bounds
Rectangle[]Array to fill with rectangle bounds.
indexOffset
intIndex into
bounds
to start filling.heuristic
MaxRectsHeuristicHeuristic to use.
Exceptions
- ArgumentNullException
If
sizes
orbounds
isnull
.- ArgumentException
If
indexOffset
is less than 0.- ArgumentOutOfRangeException
If
bounds
is not large enough to hold all bounds. I.e.bounds.Length - indexOffset < sizes.Length
Insert(int, int, MaxRectsHeuristic)
Insert a rectangle into the bin.
public Rectangle Insert(int width, int height, MaxRectsHeuristic heuristic)
Parameters
width
intWidth of the rectangle.
height
intHeight of the rectangle.
heuristic
MaxRectsHeuristicHeuristic to use.
Returns
- Rectangle
The bounds of the rectangle after placement.
Exceptions
- Exception
If the rectangle did not fit in the bin.