binpack#

class Block(id: str, width: int, height: int, dependencies: list[Block] | None = None)#

Bases: object

norm() float#
class Node(origin: tuple[int, int], size: tuple[int, int])#

Bases: object

Defines an object Node for use in the packer function. Represents the space that a block is placed.

Parameters:
  • size – The width and height of the node.

  • origin – (x, y) coordinate of the top left of the node.

used#

Boolean to determine if a node has been used.

down#

A node located beneath the current node.

right#

A node located to the right of the current node.

class Bin(blocks: Sequence[Block] | None = None, width: int | None = None)#

Bases: object

add(block: Block) None#
update(blocks: list[Block] | set[Block]) None#
clear() None#
norm() float#
pack_by_count_atomic(blocks: Sequence[Block], count: int = 8) list[Bin]#

Partition blocks into count blocks.

A note on the value of count:

  • If count == ONE_PER_BIN, tests are put into individual batches

  • If count == AUTO, tests are put into batches automatically

  • If count >= 1, tests are put into at most count batches, though it may be less.

pack_by_count(blocks: Sequence[Block], count: int = 8, grouper: Callable[[Sequence[Block]], list[list[Block]]] | None = None) list[Bin]#

Pack blocks into count bins such that each bin has no intra-dependencies. Bin can depend on other bins.

A note on the value of count:

  • If count == ONE_PER_BIN, tests are put into individual batches

  • If count == AUTO, tests are batched such that each batch contains no inter-batch dependencies

  • If count >= 1, tests are put into at most count batches, though it may be less.

pack_to_height(blocks: Sequence[Block], height: int = 1800, width: int | None = None, grouper: Callable[[Sequence[Block]], list[list[Block]]] | None = None) list[Bin]#

Partition blocks by tiling in the 2D space defined by width x height

groupby_dep(blocks: Sequence[Block]) list[set[Block]]#

Group cases such that a case and any of its dependencies are in the same group

class Packer#

Bases: object

Pack a list of blocks

pack(blocks: list[Block], width: int | None = None, height: int | None = None) None#

Initiates the packing.

find_node(node: Node, size: tuple[int, int]) Node | None#
split_node(node: Node, size: tuple[int, int]) Node#
grow_node(size: tuple[int, int]) Node | None#
grow_right(size: tuple[int, int]) Node | None#
grow_down(size: tuple[int, int]) Node | None#
perimeter(blocks: list[Block]) tuple[int, int]#