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_VALUEwidth of the output atlas (default is 4096)
height: number = EDGE_MAX_VALUEheight of the output atlas (default is 4096)
padding: number = 0padding 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[]): voidAdd 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(): numberStop 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): voidRepack all elements inside bins
Parameters
quick: boolean = truequick repack only dirty bins (default is true)
Returns void
reset
reset(): voidReset entire packer to initial states, keep settings
Returns void
save
Privatesort
sort(rects: T[], logic?: undefined | PACKING_LOGIC): T[]PrivateSort 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_EDGEsorting logic, "area" or "edge" (default is MAX_EDGE)
Creates an instance of MaxRectsPacker.