Search


Search something to see results

MaxRectsPacker

Type Parameters

Index

Constructors

Properties

Accessors

Methods

Constructors

Creates an instance of MaxRectsPacker.

Type Parameters

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

_currentBinIndex: number = 0
bins: Bin<T>[]

The Bin array added to the packer

height: number = EDGE_MAX_VALUE

height of the output atlas (default is 4096)

options: IOption = ...

Options for MaxRect Packer

padding: number = 0

padding between glyphs/images (default is 0)

width: number = EDGE_MAX_VALUE

width of the output atlas (default is 4096)

Accessors

  • get currentBinIndex(): number

    Return current functioning bin index, perior to this wont accept any new elements

    Returns number

Methods

Add a bin/rectangle object with data to packer

Parameters

  • width: number

    width of the input bin/rectangle

  • height: number

    height of the input bin/rectangle

  • data: any

    custom data object

Returns T

Add a bin/rectangle object extends IRectangle to packer

Parameters

  • rect: T

    the rect object add to the packer bin

Returns T

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 bins to the packer, overwrite exist bins

Parameters

  • bins: IBin[]

    MaxRectsBin objects

Returns void

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 all elements inside bins

Parameters

  • quick: boolean = true

    quick repack only dirty bins (default is true)

Returns void

Reset entire packer to initial states, keep settings

Returns void

Output current bins to save

Returns IBin[]

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)

Returns T[]