gdsfactory.pack

Contents

gdsfactory.pack#

gdsfactory.pack(component_list: list[ComponentSpec], spacing: float = 10.0, aspect_ratio: Float2 = (1.0, 1.0), max_size: tuple[float | None, float | None] = (None, None), sort_by_area: bool = True, density: float = 1.1, precision: float = 0.01, text: ComponentSpec | None = None, text_prefix: str = '', text_mirror: bool = False, text_rotation: int = 0, text_offsets: tuple[Float2, ...] = ((0, 0),), text_anchors: tuple[Anchor, ...] = ('cc',), name_prefix: str | None = None, rotation: int = 0, h_mirror: bool = False, v_mirror: bool = False, add_ports_prefix: bool = True, add_ports_suffix: bool = False) list[Component][source]#

Pack a list of components into as few Components as possible.

Parameters:
  • component_list – list or tuple.

  • spacing – Minimum distance between adjacent shapes.

  • aspect_ratio – (width, height) ratio of the rectangular bin.

  • max_size – Limits the size into which the shapes will be packed.

  • sort_by_area – Pre-sorts the shapes by area.

  • density – Values closer to 1 pack tighter but require more computation.

  • precision – Desired precision for rounding vertex coordinates.

  • text – Optional function to add text labels.

  • text_prefix – for labels. For example. ‘A’ will produce ‘A1’, ‘A2’, …

  • text_mirror – if True mirrors text.

  • text_rotation – Optional text rotation.

  • text_offsets – relative to component size info anchor. Defaults to center.

  • text_anchors – relative to component (ce cw nc ne nw sc se sw center cc).

  • name_prefix – for each packed component (avoids the Unnamed cells warning). Note that the suffix contains a uuid so the name will not be deterministic.

  • rotation – optional component rotation in degrees.

  • h_mirror – horizontal mirror in y axis (x, 1) (1, 0). This is the most common.

  • v_mirror – vertical mirror using x axis (1, y) (0, y).

  • add_ports_prefix – adds port names with prefix.

  • add_ports_suffix – adds port names with suffix.

import gdsfactory as gf
from functools import partial

components = [gf.components.triangle(x=i) for i in range(1, 10)]
c = gf.pack(
    components,
    spacing=20.0,
    max_size=(100, 100),
    text=partial(gf.components.text, justify="center"),
    text_prefix="R",
    name_prefix="demo",
    text_anchors=["nc"],
    text_offsets=[(-10, 0)],
    v_mirror=True,
)
c[0].plot()

(Source code, png, hires.png, pdf)

../_images/gdsfactory-pack-1.png