Skip to content

pack_layout

pack_layout(
objects: collections.abc.Sequence[
photonforge.Component
| photonforge.Reference
| photonforge.Circle
| photonforge.Path
| photonforge.Polygon
| photonforge.Rectangle
],
gap: float | collections.abc.Sequence[float] = 0,
max_size: collections.abc.Sequence[float] = (0, 0),
aspect_ratio: float = 0,
grow_factor: float = 1.1,
sorting: Literal['best', 'area'] | None = 'best',
allow_rotation: bool = False,
method: Literal['bl', 'blsf', 'bssf', 'baf', 'cp'] = 'blsf',
include_ports: bool = True,
layer: tuple[int] = (0, 0),
name: str = 'PACK_{i}',
) -> list[photonforge.Component]

Arrange components or other structures in a grid layout.

Args

  • objects: Sequence of objects to arrange. They can be instances of Component, Reference, or 2D structures.
  • gap: Horizontal and vertical gaps added between objects.
  • max_size: Maximal size of the packed component. If not all objects fit in a single pack, multiple are used.
  • aspect_ratio: Desired width:height ratio for the pack.
  • grow_factor: Controls pack size increment. Values closer to 1 can result in tighter packs at the cost of more computation.
  • sorting: Sorting option for the list of objects. If None, objects are packed in the order they are listed; 'area' will pack from largest to smallest, and "best" will try to choose the best object to pack at each iteration.
  • allow_rotation: If True, objects may be rotated by 90°.
  • method: Heuristic used to select a free slot during packing. See below for information about the options.
  • include_ports: Whether or not to include ports when computing component bounds.
  • layer: If arranging geometrical structures, add them to this layer.
  • name: Name template for the resulting components. Variable i is used to indicate the pack index in the case of multiple packs.

Returns

List of components with the packed objects.

Note

The available methods for selecting a free slot for packing are:

Bottom left rule ("bl"): Use the left-most position among the lowest upper y-value options.

Best long side fit ("blsf"): Use the position that minimizes the leftover length on the long side.

Best short side fit ("bssf"): Use the position that minimizes the leftover length on the short side.

Best area fit ("baf"): Use the smallest available area that fits.

Contact point rule ("cp"): Use the position that maximizes the length of the perimeter that touches other objects.

Reference: Jukka Jylänki, A Thousand Ways to Pack the Bin – A Practical Approach to Two-Dimensional Rectangle Bin Packing, 2010.