gdsfactory.pack#
- gdsfactory.pack(component_list, spacing=10.0, aspect_ratio=(1.0, 1.0), max_size=(None, None), sort_by_area=True, density=1.1, precision=0.01, text=None, text_prefix='', text_mirror=False, text_rotation=0, text_offsets=((0, 0),), text_anchors=('cc',), name_prefix=None, rotation=0, h_mirror=False, v_mirror=False, add_ports_prefix=True, add_ports_suffix=False, csvpath=None)[source]#
Pack a list of components into as few Components as possible.
- Parameters:
component_list (Sequence[ComponentSpec]) – list or tuple.
spacing (float) – Minimum distance between adjacent shapes.
aspect_ratio (tuple[float, float]) – (width, height) ratio of the rectangular bin.
max_size (tuple[float | None, float | None]) – Limits the size into which the shapes will be packed.
sort_by_area (bool) – Pre-sorts the shapes by area.
density (float) – Values closer to 1 pack tighter but require more computation.
precision (float) – Desired precision for rounding vertex coordinates.
text (TextFunction | None) – Optional function to add text labels.
text_prefix (str) – for labels. For example. ‘A’ will produce ‘A1’, ‘A2’, …
text_mirror (bool) – if True mirrors text.
text_rotation (int) – Optional text rotation.
text_offsets (tuple[tuple[float, float], ...]) – relative to component size info anchor. Defaults to center.
text_anchors (tuple[Literal['ce', 'cw', 'nc', 'ne', 'nw', 'sc', 'se', 'sw', 'center', 'cc'], ...]) – relative to component (ce cw nc ne nw sc se sw center cc).
name_prefix (str | None) – for each packed component (avoids the Unnamed cells warning). Note that the suffix contains a uuid so the name will not be deterministic.
rotation (int) – optional component rotation in degrees.
h_mirror (bool) – horizontal mirror in y axis (x, 1) (1, 0). This is the most common.
v_mirror (bool) – vertical mirror using x axis (1, y) (0, y).
add_ports_prefix (bool) – adds port names with prefix.
add_ports_suffix (bool) – adds port names with suffix.
csvpath (str | None) – optional path to save the packed component list as a CSV file.
- Return type:
list[Component]
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
)