MaxRectsPacker
Type Parameters
- T extends IRectangle = Rectangle
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
new MaxRectsPacker<T extends IRectangle = Rectangle>(
width?: number,
height?: number,
padding?: number,
options?: IOption,
): MaxRectsPacker<T>
Type Parameters
- T extends IRectangle = Rectangle
Parameters
width: number = EDGE_MAX_VALUE
width of the output atlas (default is 4096)
height: number = EDGE_MAX_VALUE
height of the output atlas (default is 4096)
padding: number = 0
padding between glyphs/images (default is 0)
options: IOption = {}
(Optional) packing options
Returns MaxRectsPacker<T>
Properties
Private
_ current Bin Index
bins
The Bin array added to the packer
height
height of the output atlas (default is 4096)
options
Options for MaxRect Packer
padding
padding between glyphs/images (default is 0)
width
width of the output atlas (default is 4096)
Accessors
current Bin Index
- get currentBinIndex(): number
Return current functioning bin index, perior to this wont accept any new elements
Returns number
dirty
- get dirty(): boolean
Returns dirty status of all child bins
Returns boolean
rects
Return all rectangles in this packer
Returns T[]
Methods
add
add Array
addArray(rects: T[]): void
Add an Array of bins/rectangles to the packer.
Javascript
: Any object has property: { width, height, ... } is accepted.
Typescript
: object shall extends MaxrectsPacker.IRectangle
.
note: object has hash
property will have more stable packing result
Parameters
rects: T[]
Array of bin/rectangles
Returns void
load
next
next(): number
Stop adding new element to the current bin and return a new bin.
note: After calling next()
all elements will no longer added to previous bins.
Returns number
The current bin index
repack
repack(quick?: boolean): void
Repack all elements inside bins
Parameters
quick: boolean = true
quick repack only dirty bins (default is true)
Returns void
reset
reset(): void
Reset entire packer to initial states, keep settings
Returns void
save
Private
sort
sort(rects: T[], logic?: undefined | PACKING_LOGIC): T[]
Private
Sort the given rects based on longest edge or surface area.
If rects have the same sort value, will sort by second key hash
if presented.
Parameters
rects: T[]
array of rectangles to sort
logic: undefined | PACKING_LOGIC = PACKING_LOGIC.MAX_EDGE
sorting logic, "area" or "edge" (default is MAX_EDGE)
Creates an instance of MaxRectsPacker.