5.4. binpack

5.4.1. binpack

Copyright @ 2013 Mathias Westerdahl

5.4.1.1. Brief

The bin packing functions are implemented by Jukka Jylanki:

An example of the Skyline Bottom Left packing algorithm which is default in the font creator

../_images/binpack_skyline_bl.png

5.4.1.2. Reference

binpack.MAXRECTS_BAF = 4

Positions the rectangle into the smallest free rect into which it fits.

binpack.MAXRECTS_BL = 5

Does the Tetris placement.

binpack.MAXRECTS_BLSF = 3

Positions the rectangle against the long side of a free rectangle into which it fits the best.

binpack.MAXRECTS_BSSF = 2

Positions the rectangle against the short side of a free rectangle into which it fits the best.

binpack.MAXRECTS_CP = 6

Chooses the placement where the rectangle touches other rects as much as possible.

class binpack.Rect[source]

A rectangle struct (x, y, w, h)

binpack.SKYLINE_BL = 0

Bottom left

binpack.SKYLINE_MW = 1

Min Waste

binpack.create_packer(type, width, height, allow_rotate)[source]

Creates a packer instance for use with consecutive calls to pack_rect()

Parameters:
  • type

    The packing algorithm. Must be one of:

    • SKYLINE_BL
    • SKYLINE_MW
    • MAXRECTS_BSSF
    • MAXRECTS_BLSF
    • MAXRECTS_BAF
    • MAXRECTS_BL
    • MAXRECTS_CP
  • width – The width of the packing bin (won’t change)
  • height – The height of the packing bin (won’t change)
  • allow_rotate – Tells the packer if it is allowed to rotate the rects.
Returns:

Returns the packer instance. Must be destroyed with destroy_packer()

binpack.destroy_packer(packer)[source]

Destroys the packer instance

Parameters:packer – The packer instance
binpack.get_occupancy(packer)[source]

Returns the occupancy as a value between 0.0 and 1.0

Parameters:packer – The packer instance
Returns:The current occupancy as a unit value
binpack.pack_rect(packer, w, h)[source]

Packs a rectangle in the bin.

Parameters:
  • w – The width of the rect
  • h – The height of the rect
Returns:

Returns (0, 0, 0, 0) if the bin is full Returns (x, y, W, H) if the rect was packed Returns (x, y, H, W) if the rect was packed and rotated