pyboxbuilder.compartments.element.pack_elements

pyboxbuilder.compartments.element.pack_elements(elements: Sequence[CompartmentElement], *, max_width: float | None = None, spacing: float = 2.0, margin: float = 0.0, allow_rotate: bool = True) → tuple[CompartmentElement, ...][source]

Auto-pack loose CompartmentElement items into a compact 2D element pack.

Uses a 2D Best-Short-Side-Fit (BSSF) MaxRects layout, optionally testing a 90-degree rotation per asymmetric element and reserving room between slots. Coloured floor-inlay icons positioned relative to another element should be added after packing; every element passed here receives a fresh non-overlapping offset.

Parameters:
elements: Sequence[CompartmentElement]

Elements to place (their existing offset is replaced).

max_width: float | None = None

Maximum pack width in mm; None derives a near-square target.

spacing: float = 2.0

Minimum gap between adjacent element footprints in mm.

margin: float = 0.0

Outer border inset around the entire pack in mm.

allow_rotate: bool = True

Allow 90-degree Z rotation when it improves 2D fit.

Returns:

Packed CompartmentElement tuple in the original input order.