Skip to content

cross_section

cross_section

CrossSections for KFactory.

AsymmetricCrossSection

Bases: TAsymmetricCrossSection[int]

dbu-flavored wrapper around an AsymmetricalCrossSection.

Source code in kfactory/cross_section.py
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
class AsymmetricCrossSection(TAsymmetricCrossSection[int]):
    """dbu-flavored wrapper around an `AsymmetricalCrossSection`."""

    def add_bbox(
        self,
        c: KCell | DKCell | VKCell,
        ref: kdb.LayerInfo
        | int
        | kdb.Box
        | kdb.DBox
        | ProtoInstance[Any]
        | None = None,
        *,
        top: int | None = None,
        bottom: int | None = None,
        right: int | None = None,
        left: int | None = None,
    ) -> None:
        """Draw bbox_sections using padding in integer dbu.

        Args:
            c: Target KCell, DKCell, or VKCell, including subclasses. Must share
                this cross section's KCLayout, as must any instance reference.
            ref: None for the whole target, a layer/index in c, an explicit
                Box (dbu) or DBox (micrometers), or an instance's transformed
                bounds in c's coordinate system. Cell references are not accepted.
            top: Top padding override for every bbox layer.
            bottom: Bottom padding override for every bbox layer.
            right: Right padding override for every bbox layer.
            left: Left padding override for every bbox layer.

        None padding uses each layer's stored offset; zero suppresses padding.
        Real targets use integer geometry; VKCell targets use micrometers.
        All layers use the same original bounds. Empty references draw nothing;
        neither the cross section nor the reference box is modified.

        Warning:
            Logs a warning when a non-VKCell target has pending virtual instances,
            even with an explicit reference. Call insert_vinsts() first to avoid
            inaccurate geometry. This method does not materialize instances.

        Raises:
            LockedError: The target cell is locked.
            TypeError: The target or reference type is unsupported.
            ValueError: The target or instance reference uses another KCLayout.
        """
        from .kcell import DKCell, KCell, VKCell

        if not isinstance(c, KCell | DKCell | VKCell):
            raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
        if c.kcl is not self.kcl:
            raise ValueError(
                "The cross section and target must share the same KCLayout"
            )
        if c.locked:
            raise LockedError(c)
        if isinstance(c, VKCell):
            self.to_dtype().add_bbox(
                c,
                ref,
                top=self.kcl.to_um(top),
                bottom=self.kcl.to_um(bottom),
                right=self.kcl.to_um(right),
                left=self.kcl.to_um(left),
            )
            return
        bbox = _bbox_reference(c, ref)
        _add_bbox(
            c,
            bbox if isinstance(bbox, kdb.Box) else self.kcl.to_dbu(bbox),
            {
                self.kcl.layer(layer): offset
                for layer, offset in self.bbox_sections.items()
            },
            top=top,
            bottom=bottom,
            right=right,
            left=left,
        )

    @overload
    def __init__(self, kcl: KCLayout, *, base: AsymmetricalCrossSection) -> None: ...

    @overload
    def __init__(
        self,
        kcl: KCLayout,
        section_min: int,
        section_max: int,
        layer: kdb.LayerInfo,
        sections: Sequence[CrossSectionLayer] = (),
        name: str | None = None,
        radius: int | None = None,
        radius_min: int | None = None,
        bbox_sections: dict[kdb.LayerInfo, int] | None = None,
    ) -> None: ...

    def __init__(
        self,
        kcl: KCLayout,
        section_min: int | None = None,
        section_max: int | None = None,
        layer: kdb.LayerInfo | None = None,
        sections: Sequence[CrossSectionLayer] = (),
        name: str | None = None,
        radius: int | None = None,
        radius_min: int | None = None,
        bbox_sections: dict[kdb.LayerInfo, int] | None = None,
        base: AsymmetricalCrossSection | None = None,
    ) -> None:
        if base is None:
            if section_min is None or section_max is None or layer is None:
                raise ValueError(
                    "If no base is given, section_min, section_max, and layer"
                    " must be defined"
                )
            base = kcl.get_asymmetrical_cross_section(
                AsymmetricalCrossSection(
                    layer=layer,
                    section_min=section_min,
                    section_max=section_max,
                    sections=tuple(sections),
                    name=name or "",
                    radius=radius,
                    radius_min=radius_min,
                    bbox_sections=bbox_sections or {},
                )
            )
        self.kcl = kcl
        self._base = base

    @property
    def width(self) -> int:
        return self._base.width

    @property
    def section_min(self) -> int:
        return self._base.section_min

    @property
    def section_max(self) -> int:
        return self._base.section_max

    @property
    def sections(self) -> tuple[CrossSectionLayer, ...]:
        return self._base.sections

    def get_sections(self) -> tuple[CrossSectionLayer, ...]:
        """Absolute signed dbu strips of the realised profile, main strip first."""
        return self._base.get_sections()

    @property
    def radius(self) -> int | None:
        return self._base.radius

    @property
    def radius_min(self) -> int | None:
        return self._base.radius_min

    @property
    def bbox_sections(self) -> dict[kdb.LayerInfo, int]:
        return self._base.bbox_sections.copy()

    def get_xmin_xmax(self) -> tuple[int, int]:
        return (self._base.get_xmin(), self._base.get_xmax())

add_bbox

add_bbox(c: KCell | DKCell | VKCell, ref: LayerInfo | int | Box | DBox | ProtoInstance[Any] | None = None, *, top: int | None = None, bottom: int | None = None, right: int | None = None, left: int | None = None) -> None

Draw bbox_sections using padding in integer dbu.

Parameters:

Name Type Description Default
c KCell | DKCell | VKCell

Target KCell, DKCell, or VKCell, including subclasses. Must share this cross section's KCLayout, as must any instance reference.

required
ref LayerInfo | int | Box | DBox | ProtoInstance[Any] | None

None for the whole target, a layer/index in c, an explicit Box (dbu) or DBox (micrometers), or an instance's transformed bounds in c's coordinate system. Cell references are not accepted.

None
top int | None

Top padding override for every bbox layer.

None
bottom int | None

Bottom padding override for every bbox layer.

None
right int | None

Right padding override for every bbox layer.

None
left int | None

Left padding override for every bbox layer.

None

None padding uses each layer's stored offset; zero suppresses padding. Real targets use integer geometry; VKCell targets use micrometers. All layers use the same original bounds. Empty references draw nothing; neither the cross section nor the reference box is modified.

Warning

Logs a warning when a non-VKCell target has pending virtual instances, even with an explicit reference. Call insert_vinsts() first to avoid inaccurate geometry. This method does not materialize instances.

Raises:

Type Description
LockedError

The target cell is locked.

TypeError

The target or reference type is unsupported.

ValueError

The target or instance reference uses another KCLayout.

Source code in kfactory/cross_section.py
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
def add_bbox(
    self,
    c: KCell | DKCell | VKCell,
    ref: kdb.LayerInfo
    | int
    | kdb.Box
    | kdb.DBox
    | ProtoInstance[Any]
    | None = None,
    *,
    top: int | None = None,
    bottom: int | None = None,
    right: int | None = None,
    left: int | None = None,
) -> None:
    """Draw bbox_sections using padding in integer dbu.

    Args:
        c: Target KCell, DKCell, or VKCell, including subclasses. Must share
            this cross section's KCLayout, as must any instance reference.
        ref: None for the whole target, a layer/index in c, an explicit
            Box (dbu) or DBox (micrometers), or an instance's transformed
            bounds in c's coordinate system. Cell references are not accepted.
        top: Top padding override for every bbox layer.
        bottom: Bottom padding override for every bbox layer.
        right: Right padding override for every bbox layer.
        left: Left padding override for every bbox layer.

    None padding uses each layer's stored offset; zero suppresses padding.
    Real targets use integer geometry; VKCell targets use micrometers.
    All layers use the same original bounds. Empty references draw nothing;
    neither the cross section nor the reference box is modified.

    Warning:
        Logs a warning when a non-VKCell target has pending virtual instances,
        even with an explicit reference. Call insert_vinsts() first to avoid
        inaccurate geometry. This method does not materialize instances.

    Raises:
        LockedError: The target cell is locked.
        TypeError: The target or reference type is unsupported.
        ValueError: The target or instance reference uses another KCLayout.
    """
    from .kcell import DKCell, KCell, VKCell

    if not isinstance(c, KCell | DKCell | VKCell):
        raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
    if c.kcl is not self.kcl:
        raise ValueError(
            "The cross section and target must share the same KCLayout"
        )
    if c.locked:
        raise LockedError(c)
    if isinstance(c, VKCell):
        self.to_dtype().add_bbox(
            c,
            ref,
            top=self.kcl.to_um(top),
            bottom=self.kcl.to_um(bottom),
            right=self.kcl.to_um(right),
            left=self.kcl.to_um(left),
        )
        return
    bbox = _bbox_reference(c, ref)
    _add_bbox(
        c,
        bbox if isinstance(bbox, kdb.Box) else self.kcl.to_dbu(bbox),
        {
            self.kcl.layer(layer): offset
            for layer, offset in self.bbox_sections.items()
        },
        top=top,
        bottom=bottom,
        right=right,
        left=left,
    )

get_sections

get_sections() -> tuple[CrossSectionLayer, ...]

Absolute signed dbu strips of the realised profile, main strip first.

Source code in kfactory/cross_section.py
1096
1097
1098
def get_sections(self) -> tuple[CrossSectionLayer, ...]:
    """Absolute signed dbu strips of the realised profile, main strip first."""
    return self._base.get_sections()

AsymmetricalCrossSection pydantic-model

Bases: BaseModel

Cross section composed of independent layer strips at signed bounds.

The main strip (layer, section_min, section_max) is the port reference; sections holds any additional strips. All bounds are signed integer dbu relative to the port centerline (x = 0). Strip edges are always grid-aligned regardless of width parity.

Fields:

  • layer (LayerInfo)
  • section_min (dbu)
  • section_max (dbu)
  • sections (tuple[CrossSectionLayer, ...])
  • name (str)
  • radius (dbu | None)
  • radius_min (dbu | None)
  • bbox_sections (dict[LayerInfo, dbu])

Validators:

  • _normalize
  • _validate
Source code in kfactory/cross_section.py
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
class AsymmetricalCrossSection(BaseModel, frozen=True, arbitrary_types_allowed=True):
    """Cross section composed of independent layer strips at signed bounds.

    The main strip (`layer`, `section_min`, `section_max`) is the port
    reference; `sections` holds any additional strips. All bounds are signed
    integer dbu relative to the port centerline (`x = 0`). Strip edges are
    always grid-aligned regardless of width parity.
    """

    layer: kdb.LayerInfo
    section_min: dbu
    section_max: dbu
    sections: tuple[CrossSectionLayer, ...] = ()
    name: str = ""
    radius: dbu | None = None
    radius_min: dbu | None = None
    bbox_sections: dict[kdb.LayerInfo, dbu] = Field(default_factory=dict)

    @model_validator(mode="before")
    @classmethod
    def _normalize(cls, data: Any) -> Any:
        if not isinstance(data, dict):
            return data
        sections = data.get("sections", ())
        coerced: list[CrossSectionLayer] = []
        for s in sections:
            if isinstance(s, CrossSectionLayer):
                coerced.append(s)
            else:
                coerced.append(CrossSectionLayer.model_validate(s))
        data["sections"] = _normalize_sections(coerced)
        if not data.get("name"):
            data["name"] = _asym_auto_name(
                data["layer"],
                data["section_min"],
                data["section_max"],
                data["sections"],
                data.get("bbox_sections") or {},
            )
        return data

    def auto_name(self) -> str:
        """Deterministic structural name (hash of geometry, excluding radius)."""
        return _asym_auto_name(
            self.layer,
            self.section_min,
            self.section_max,
            self.sections,
            self.bbox_sections,
        )

    @property
    def is_named(self) -> bool:
        """Whether an explicit name was given (vs. the derived structural name)."""
        return self.name != self.auto_name()

    @model_validator(mode="after")
    def _validate(self) -> Self:
        if self.section_min >= self.section_max:
            raise ValueError(
                "section_min must be strictly less than section_max"
                f" (got section_min={self.section_min},"
                f" section_max={self.section_max})."
            )
        return self

    @property
    def width(self) -> int:
        """Main strip width in dbu (`section_max - section_min`)."""
        return self.section_max - self.section_min

    @property
    def main_layer(self) -> kdb.LayerInfo:
        """Main layer of the cross section (parity with SymmetricalCrossSection)."""
        return self.layer

    def to_dtype(self, kcl: KCLayout) -> DAsymmetricalCrossSection:
        return DAsymmetricalCrossSection(
            layer=self.layer,
            section_min=kcl.to_um(self.section_min),
            section_max=kcl.to_um(self.section_max),
            sections=tuple(
                DCrossSectionLayer(
                    layer=s.layer,
                    section_min=kcl.to_um(s.section_min),
                    section_max=kcl.to_um(s.section_max),
                )
                for s in self.sections
            ),
            name=self.name,
            radius=kcl.to_um(self.radius),
            radius_min=kcl.to_um(self.radius_min),
            bbox_sections={k: kcl.to_um(v) for k, v in self.bbox_sections.items()},
        )

    def is_symmetric(self) -> bool:
        """Whether this cross section is symmetric."""
        return False

    def get_sections(self) -> tuple[CrossSectionLayer, ...]:
        """Absolute signed dbu strips of the realised profile, main strip first.

        The counterpart of `SymmetricalCrossSection.get_sections`: here the
        strips are already absolute, so this is the main strip followed by the
        normalized `sections`.
        """
        return (
            CrossSectionLayer(
                layer=self.layer,
                section_min=self.section_min,
                section_max=self.section_max,
            ),
            *self.sections,
        )

    def _all_strips(self) -> tuple[tuple[int, int], ...]:
        """Return (section_min, section_max) for main + every aux section."""
        return (
            (self.section_min, self.section_max),
            *((s.section_min, s.section_max) for s in self.sections),
        )

    def get_xmin(self) -> int:
        return min(lo for lo, _ in self._all_strips())

    def get_xmax(self) -> int:
        return max(hi for _, hi in self._all_strips())

    def model_copy(
        self, *, update: Mapping[str, Any] | None = {"name": None}, deep: bool = False
    ) -> AsymmetricalCrossSection:
        return super().model_copy(update=update, deep=deep)

    def __eq__(self, o: object) -> bool:
        if isinstance(o, (SymmetricalCrossSection, TCrossSection)):
            return False
        if isinstance(o, TAsymmetricCrossSection):
            return self == o.base
        if isinstance(o, AsymmetricalCrossSection):
            # radius/radius_min are non-identifying metadata.
            return (
                self.layer == o.layer
                and self.section_min == o.section_min
                and self.section_max == o.section_max
                and self.sections == o.sections
                and self.name == o.name
                and self.bbox_sections == o.bbox_sections
            )
        return NotImplemented

    def __hash__(self) -> int:
        return hash(
            (
                self.layer,
                self.section_min,
                self.section_max,
                self.sections,
                self.name,
                tuple(sorted(self.bbox_sections.items(), key=lambda kv: kv[0].name)),
            )
        )

    def _sort_key(
        self,
    ) -> tuple[
        str, int, int, int, int, tuple[tuple[str, int, int, int, int], ...], str
    ]:
        return (
            self.layer.name,
            self.layer.layer,
            self.layer.datatype,
            self.section_min,
            self.section_max,
            tuple(s._sort_key() for s in self.sections),
            self.name,
        )

    def __lt__(self, other: object) -> bool:
        if not isinstance(other, AsymmetricalCrossSection):
            return NotImplemented
        return self._sort_key() < other._sort_key()

    def __le__(self, other: object) -> bool:
        if not isinstance(other, AsymmetricalCrossSection):
            return NotImplemented
        return self._sort_key() <= other._sort_key()

    def __gt__(self, other: object) -> bool:
        if not isinstance(other, AsymmetricalCrossSection):
            return NotImplemented
        return self._sort_key() > other._sort_key()

    def __ge__(self, other: object) -> bool:
        if not isinstance(other, AsymmetricalCrossSection):
            return NotImplemented
        return self._sort_key() >= other._sort_key()

is_named property

is_named: bool

Whether an explicit name was given (vs. the derived structural name).

main_layer property

main_layer: LayerInfo

Main layer of the cross section (parity with SymmetricalCrossSection).

width property

width: int

Main strip width in dbu (section_max - section_min).

auto_name

auto_name() -> str

Deterministic structural name (hash of geometry, excluding radius).

Source code in kfactory/cross_section.py
524
525
526
527
528
529
530
531
532
def auto_name(self) -> str:
    """Deterministic structural name (hash of geometry, excluding radius)."""
    return _asym_auto_name(
        self.layer,
        self.section_min,
        self.section_max,
        self.sections,
        self.bbox_sections,
    )

get_sections

get_sections() -> tuple[CrossSectionLayer, ...]

Absolute signed dbu strips of the realised profile, main strip first.

The counterpart of SymmetricalCrossSection.get_sections: here the strips are already absolute, so this is the main strip followed by the normalized sections.

Source code in kfactory/cross_section.py
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
def get_sections(self) -> tuple[CrossSectionLayer, ...]:
    """Absolute signed dbu strips of the realised profile, main strip first.

    The counterpart of `SymmetricalCrossSection.get_sections`: here the
    strips are already absolute, so this is the main strip followed by the
    normalized `sections`.
    """
    return (
        CrossSectionLayer(
            layer=self.layer,
            section_min=self.section_min,
            section_max=self.section_max,
        ),
        *self.sections,
    )

is_symmetric

is_symmetric() -> bool

Whether this cross section is symmetric.

Source code in kfactory/cross_section.py
578
579
580
def is_symmetric(self) -> bool:
    """Whether this cross section is symmetric."""
    return False

CrossSection

Bases: TCrossSection[int]

Source code in kfactory/cross_section.py
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
class CrossSection(TCrossSection[int]):
    def add_bbox(
        self,
        c: KCell | DKCell | VKCell,
        ref: kdb.LayerInfo
        | int
        | kdb.Box
        | kdb.DBox
        | ProtoInstance[Any]
        | None = None,
        *,
        top: int | None = None,
        bottom: int | None = None,
        right: int | None = None,
        left: int | None = None,
    ) -> None:
        """Draw bbox_sections using padding in integer dbu.

        Args:
            c: Target KCell, DKCell, or VKCell, including subclasses. Must share
                this cross section's KCLayout, as must any instance reference.
            ref: None for the whole target, a layer/index in c, an explicit
                Box (dbu) or DBox (micrometers), or an instance's transformed
                bounds in c's coordinate system. Cell references are not accepted.
            top: Top padding override for every bbox layer.
            bottom: Bottom padding override for every bbox layer.
            right: Right padding override for every bbox layer.
            left: Left padding override for every bbox layer.

        None padding uses each layer's stored offset; zero suppresses padding.
        Real targets use integer geometry; VKCell targets use micrometers.
        All layers use the same original bounds. Empty references draw nothing;
        neither the cross section nor the reference box is modified.

        Warning:
            Logs a warning when a non-VKCell target has pending virtual instances,
            even with an explicit reference. Call insert_vinsts() first to avoid
            inaccurate geometry. This method does not materialize instances.

        Raises:
            LockedError: The target cell is locked.
            TypeError: The target or reference type is unsupported.
            ValueError: The target or instance reference uses another KCLayout.
        """
        from .kcell import DKCell, KCell, VKCell

        if not isinstance(c, KCell | DKCell | VKCell):
            raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
        if c.kcl is not self.kcl:
            raise ValueError(
                "The cross section and target must share the same KCLayout"
            )
        if c.locked:
            raise LockedError(c)
        if isinstance(c, VKCell):
            self.to_dtype().add_bbox(
                c,
                ref,
                top=self.kcl.to_um(top),
                bottom=self.kcl.to_um(bottom),
                right=self.kcl.to_um(right),
                left=self.kcl.to_um(left),
            )
            return
        bbox = _bbox_reference(c, ref)
        _add_bbox(
            c,
            bbox if isinstance(bbox, kdb.Box) else self.kcl.to_dbu(bbox),
            {
                self.kcl.layer(layer): offset
                for layer, offset in self.bbox_sections.items()
            },
            top=top,
            bottom=bottom,
            right=right,
            left=left,
        )

    @overload
    def __init__(self, kcl: KCLayout, *, base: SymmetricalCrossSection) -> None: ...

    @overload
    def __init__(
        self,
        kcl: KCLayout,
        width: int,
        layer: kdb.LayerInfo,
        sections: Sequence[tuple[kdb.LayerInfo, int, int] | tuple[kdb.LayerInfo, int]],
        radius: int | None = None,
        radius_min: int | None = None,
        name: str | None = None,
        bbox_layers: Sequence[kdb.LayerInfo] | None = None,
        bbox_offsets: Sequence[int] | None = None,
    ) -> None: ...

    def __init__(
        self,
        kcl: KCLayout,
        width: int | None = None,
        layer: kdb.LayerInfo | None = None,
        sections: Sequence[tuple[kdb.LayerInfo, int, int] | tuple[kdb.LayerInfo, int]]
        | None = None,
        radius: int | None = None,
        radius_min: int | None = None,
        name: str | None = None,
        bbox_layers: Sequence[kdb.LayerInfo] | None = None,
        bbox_offsets: Sequence[int] | None = None,
        base: SymmetricalCrossSection | None = None,
    ) -> None:
        if not base:
            if bbox_layers:
                if not bbox_offsets:
                    bbox_offsets = [0 for _ in range(len(bbox_layers))]
                elif len(bbox_offsets) != len(bbox_layers):
                    raise ValueError(
                        "Length of the bbox_layers list and the bbox_offsets list"
                        " must be the same "
                        f"{len(bbox_layers)=}, {len(bbox_offsets)=}"
                    )
            else:
                bbox_layers = []
                bbox_offsets = []
            if width is None or layer is None or sections is None:
                raise ValueError(
                    "If no base is given, width, layer, and sections must be defined"
                )
            base = kcl.get_symmetrical_cross_section(
                SymmetricalCrossSection(
                    width=width,
                    enclosure=LayerEnclosure(
                        sections=sections,
                        main_layer=layer,
                        bbox_sections=list(
                            zip(bbox_layers, bbox_offsets)  # noqa: B905
                        ),
                    ),
                    name=name,
                    radius=radius,
                    radius_min=radius_min,
                )
            )
        self.kcl = kcl
        self._base = base

    @property
    def sections(self) -> dict[kdb.LayerInfo, list[tuple[int | None, int]]]:
        items = self._base.enclosure.layer_sections.items()
        return {
            layer: [(section.d_min, section.d_max) for section in sections.sections]
            for layer, sections in items
        }

    def get_sections(self) -> tuple[CrossSectionLayer, ...]:
        """Absolute signed dbu strips of the realised profile, main strip first.

        Unlike `sections`, which returns the enclosure's edge-relative bands,
        this resolves them against the core width and includes the main strip.
        """
        return self._base.get_sections()

    @property
    def bbox_sections(self) -> dict[kdb.LayerInfo, int]:
        return self._base.bbox_sections.copy()

    @property
    def width(self) -> int:
        return self._base.width

    @property
    def radius(self) -> int | None:
        return self._base.radius

    @property
    def radius_min(self) -> int | None:
        return self._base.radius_min

    def get_xmin_xmax(self) -> tuple[int, int]:
        return (self._base.get_xmin(), self._base.get_xmax())

    def model_copy(
        self, *, update: Mapping[str, Any] = {"name": None}, deep: bool
    ) -> CrossSection:
        return CrossSection(
            kcl=self.kcl, base=self.base.model_copy(update=update, deep=deep)
        )

add_bbox

add_bbox(c: KCell | DKCell | VKCell, ref: LayerInfo | int | Box | DBox | ProtoInstance[Any] | None = None, *, top: int | None = None, bottom: int | None = None, right: int | None = None, left: int | None = None) -> None

Draw bbox_sections using padding in integer dbu.

Parameters:

Name Type Description Default
c KCell | DKCell | VKCell

Target KCell, DKCell, or VKCell, including subclasses. Must share this cross section's KCLayout, as must any instance reference.

required
ref LayerInfo | int | Box | DBox | ProtoInstance[Any] | None

None for the whole target, a layer/index in c, an explicit Box (dbu) or DBox (micrometers), or an instance's transformed bounds in c's coordinate system. Cell references are not accepted.

None
top int | None

Top padding override for every bbox layer.

None
bottom int | None

Bottom padding override for every bbox layer.

None
right int | None

Right padding override for every bbox layer.

None
left int | None

Left padding override for every bbox layer.

None

None padding uses each layer's stored offset; zero suppresses padding. Real targets use integer geometry; VKCell targets use micrometers. All layers use the same original bounds. Empty references draw nothing; neither the cross section nor the reference box is modified.

Warning

Logs a warning when a non-VKCell target has pending virtual instances, even with an explicit reference. Call insert_vinsts() first to avoid inaccurate geometry. This method does not materialize instances.

Raises:

Type Description
LockedError

The target cell is locked.

TypeError

The target or reference type is unsupported.

ValueError

The target or instance reference uses another KCLayout.

Source code in kfactory/cross_section.py
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
def add_bbox(
    self,
    c: KCell | DKCell | VKCell,
    ref: kdb.LayerInfo
    | int
    | kdb.Box
    | kdb.DBox
    | ProtoInstance[Any]
    | None = None,
    *,
    top: int | None = None,
    bottom: int | None = None,
    right: int | None = None,
    left: int | None = None,
) -> None:
    """Draw bbox_sections using padding in integer dbu.

    Args:
        c: Target KCell, DKCell, or VKCell, including subclasses. Must share
            this cross section's KCLayout, as must any instance reference.
        ref: None for the whole target, a layer/index in c, an explicit
            Box (dbu) or DBox (micrometers), or an instance's transformed
            bounds in c's coordinate system. Cell references are not accepted.
        top: Top padding override for every bbox layer.
        bottom: Bottom padding override for every bbox layer.
        right: Right padding override for every bbox layer.
        left: Left padding override for every bbox layer.

    None padding uses each layer's stored offset; zero suppresses padding.
    Real targets use integer geometry; VKCell targets use micrometers.
    All layers use the same original bounds. Empty references draw nothing;
    neither the cross section nor the reference box is modified.

    Warning:
        Logs a warning when a non-VKCell target has pending virtual instances,
        even with an explicit reference. Call insert_vinsts() first to avoid
        inaccurate geometry. This method does not materialize instances.

    Raises:
        LockedError: The target cell is locked.
        TypeError: The target or reference type is unsupported.
        ValueError: The target or instance reference uses another KCLayout.
    """
    from .kcell import DKCell, KCell, VKCell

    if not isinstance(c, KCell | DKCell | VKCell):
        raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
    if c.kcl is not self.kcl:
        raise ValueError(
            "The cross section and target must share the same KCLayout"
        )
    if c.locked:
        raise LockedError(c)
    if isinstance(c, VKCell):
        self.to_dtype().add_bbox(
            c,
            ref,
            top=self.kcl.to_um(top),
            bottom=self.kcl.to_um(bottom),
            right=self.kcl.to_um(right),
            left=self.kcl.to_um(left),
        )
        return
    bbox = _bbox_reference(c, ref)
    _add_bbox(
        c,
        bbox if isinstance(bbox, kdb.Box) else self.kcl.to_dbu(bbox),
        {
            self.kcl.layer(layer): offset
            for layer, offset in self.bbox_sections.items()
        },
        top=top,
        bottom=bottom,
        right=right,
        left=left,
    )

get_sections

get_sections() -> tuple[CrossSectionLayer, ...]

Absolute signed dbu strips of the realised profile, main strip first.

Unlike sections, which returns the enclosure's edge-relative bands, this resolves them against the core width and includes the main strip.

Source code in kfactory/cross_section.py
1591
1592
1593
1594
1595
1596
1597
def get_sections(self) -> tuple[CrossSectionLayer, ...]:
    """Absolute signed dbu strips of the realised profile, main strip first.

    Unlike `sections`, which returns the enclosure's edge-relative bands,
    this resolves them against the core width and includes the main strip.
    """
    return self._base.get_sections()

CrossSectionLayer pydantic-model

Bases: BaseModel

Single strip in an asymmetrical cross section.

A strip on layer spanning [section_min, section_max] in dbu relative to the port centerline (offset=0). Both bounds are signed integer dbu, so edges are always grid-aligned. The strip's width is the derived section_max - section_min.

Fields:

  • layer (LayerInfo)
  • section_min (dbu)
  • section_max (dbu)

Validators:

  • _validate_bounds
Source code in kfactory/cross_section.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
class CrossSectionLayer(BaseModel, frozen=True, arbitrary_types_allowed=True):
    """Single strip in an asymmetrical cross section.

    A strip on `layer` spanning `[section_min, section_max]` in dbu relative to
    the port centerline (`offset=0`). Both bounds are signed integer dbu, so
    edges are always grid-aligned. The strip's width is the derived
    `section_max - section_min`.
    """

    layer: kdb.LayerInfo
    section_min: dbu
    section_max: dbu

    @model_validator(mode="after")
    def _validate_bounds(self) -> Self:
        if self.section_min >= self.section_max:
            raise ValueError(
                "section_min must be strictly less than section_max (got"
                f" section_min={self.section_min},"
                f" section_max={self.section_max})."
            )
        return self

    @property
    def width(self) -> int:
        """Width of the strip in dbu (`section_max - section_min`)."""
        return self.section_max - self.section_min

    def _sort_key(self) -> tuple[str, int, int, int, int]:
        return (
            self.layer.name,
            self.layer.layer,
            self.layer.datatype,
            self.section_min,
            self.section_max,
        )

    def __lt__(self, other: object) -> bool:
        if not isinstance(other, CrossSectionLayer):
            return NotImplemented
        return self._sort_key() < other._sort_key()

    def __le__(self, other: object) -> bool:
        if not isinstance(other, CrossSectionLayer):
            return NotImplemented
        return self._sort_key() <= other._sort_key()

    def __gt__(self, other: object) -> bool:
        if not isinstance(other, CrossSectionLayer):
            return NotImplemented
        return self._sort_key() > other._sort_key()

    def __ge__(self, other: object) -> bool:
        if not isinstance(other, CrossSectionLayer):
            return NotImplemented
        return self._sort_key() >= other._sort_key()

width property

width: int

Width of the strip in dbu (section_max - section_min).

CrossSectionModel pydantic-model

Bases: BaseModel

Fields:

Source code in kfactory/cross_section.py
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
class CrossSectionModel(BaseModel):
    cross_sections: dict[str, SymmetricalCrossSection | AsymmetricalCrossSection] = (
        Field(default_factory=dict)
    )
    kcl: KCLayout

    def __getitem__(
        self, name: str
    ) -> SymmetricalCrossSection | AsymmetricalCrossSection:
        return self.cross_sections[name]

    def get_asymmetrical_cross_section(
        self,
        cross_section: str | AsymmetricalCrossSection | DAsymmetricalCrossSection,
    ) -> AsymmetricalCrossSection:
        if isinstance(cross_section, str):
            xs = self.cross_sections[cross_section]
            if not isinstance(xs, AsymmetricalCrossSection):
                raise TypeError(
                    f"Cross section {cross_section!r} is symmetric; use "
                    "get_(symmetrical_)cross_section."
                )
            return xs
        if isinstance(cross_section, DAsymmetricalCrossSection):
            cross_section = cross_section.to_itype(self.kcl)
        registered = self._register(cross_section)
        assert isinstance(registered, AsymmetricalCrossSection)
        return registered

    def _register(
        self, cross_section: SymmetricalCrossSection | AsymmetricalCrossSection
    ) -> SymmetricalCrossSection | AsymmetricalCrossSection:
        """Register/resolve a cross section by its canonical (structural) name.

        Entries are keyed by their `auto_name()` and, when named, additionally by
        the explicit name. Existence is a single `get(auto_name())`.
        """
        auto = cross_section.auto_name()
        canonical = self.cross_sections.get(auto)
        if canonical is None:
            if cross_section.is_named and cross_section.name in self.cross_sections:
                raise CrossSectionNamingConflictError(
                    f"Cross section name {cross_section.name!r} is already "
                    "registered for a different structural signature."
                )
            self.cross_sections[auto] = cross_section
            if cross_section.is_named:
                self.cross_sections[cross_section.name] = cross_section
            return cross_section
        if not cross_section.is_named:
            return _resolve_radius(canonical, cross_section)
        if canonical.is_named:
            if canonical.name == cross_section.name:
                return _resolve_radius(canonical, cross_section)
            raise CrossSectionNamingConflictError(
                f"Cannot register cross section {cross_section.name!r}: the same "
                f"structural signature is already registered as {canonical.name!r}."
                " A structure can have at most one name."
            )
        # Promote the unnamed canonical to the named one (radius must match).
        _resolve_radius(canonical, cross_section)
        self.cross_sections[auto] = cross_section
        self.cross_sections[cross_section.name] = cross_section
        return cross_section

    def get_cross_section(
        self,
        cross_section: str
        | SymmetricalCrossSection
        | DSymmetricalCrossSection
        | CrossSectionSpecDict
        | DCrossSectionSpecDict
        | CrossSection
        | DCrossSection,
    ) -> SymmetricalCrossSection:
        if isinstance(cross_section, str):
            xs = self.cross_sections[cross_section]
            if not isinstance(xs, SymmetricalCrossSection):
                raise TypeError(
                    f"Cross section {cross_section!r} is asymmetric; use "
                    "get_asymmetrical_cross_section."
                )
            return xs
        if isinstance(cross_section, TCrossSection):
            cross_section = cross_section.base
        if isinstance(cross_section, SymmetricalCrossSection):
            canonical_enc = self.kcl.get_enclosure(cross_section.enclosure)
            if cross_section.enclosure != canonical_enc:
                return self.get_cross_section(
                    SymmetricalCrossSection(
                        enclosure=canonical_enc,
                        # Preserve named/unnamed provenance: re-derive the auto
                        # name from the canonical enclosure when unnamed.
                        name=cross_section.name if cross_section.is_named else None,
                        width=cross_section.width,
                        radius=cross_section.radius,
                        radius_min=cross_section.radius_min,
                    )
                )
        elif isinstance(cross_section, DSymmetricalCrossSection):
            cross_section = cross_section.to_itype(self.kcl)

        elif cross_section.get("unit", "dbu") == "dbu":
            cross_section = SymmetricalCrossSection(
                width=cross_section["width"],  # ty:ignore[invalid-argument-type]
                enclosure=self.kcl.layer_enclosures.get_enclosure(
                    LayerEnclosureSpec(
                        sections=cross_section.get("sections", []),  # ty:ignore[invalid-argument-type]
                        main_layer=cross_section["layer"],
                        name=cross_section.get("enclosure", {}).get("name"),
                    ),
                    kcl=self.kcl,
                ),
                name=cross_section.get("name", None),
            )
        else:
            cross_section = SymmetricalCrossSection(
                width=self.kcl.to_dbu(cross_section["width"]),
                enclosure=self.kcl.layer_enclosures.get_enclosure(
                    LayerEnclosureSpec(
                        sections=[
                            (section[0], self.kcl.to_dbu(section[1]))
                            if len(section) == 2
                            else (
                                section[0],
                                self.kcl.to_dbu(section[1]),
                                self.kcl.to_dbu(section[2]),
                            )
                            for section in cross_section.get("sections", [])
                        ],
                        main_layer=cross_section["layer"],
                        name=cross_section.get("enclosure", {}).get("name"),
                    ),
                    kcl=self.kcl,
                ),
                name=cross_section.get("name", None),
            )
        registered = self._register(cross_section)
        assert isinstance(registered, SymmetricalCrossSection)
        return registered

    def __repr__(self) -> str:
        return repr(self.cross_sections)

DAsymmetricCrossSection

Bases: TAsymmetricCrossSection[float]

um-flavored wrapper around an AsymmetricalCrossSection.

Source code in kfactory/cross_section.py
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
class DAsymmetricCrossSection(TAsymmetricCrossSection[float]):
    """um-flavored wrapper around an `AsymmetricalCrossSection`."""

    def add_bbox(
        self,
        c: KCell | DKCell | VKCell,
        ref: kdb.LayerInfo
        | int
        | kdb.Box
        | kdb.DBox
        | ProtoInstance[Any]
        | None = None,
        *,
        top: float | None = None,
        bottom: float | None = None,
        right: float | None = None,
        left: float | None = None,
    ) -> None:
        """Draw bbox_sections using padding in micrometers.

        Args:
            c: Target KCell, DKCell, or VKCell, including subclasses. Must share
                this cross section's KCLayout, as must any instance reference.
            ref: None for the whole target, a layer/index in c, an explicit
                Box (dbu) or DBox (micrometers), or an instance's transformed
                bounds in c's coordinate system. Cell references are not accepted.
            top: Top padding override for every bbox layer.
            bottom: Bottom padding override for every bbox layer.
            right: Right padding override for every bbox layer.
            left: Left padding override for every bbox layer.

        None padding uses each layer's stored offset; zero suppresses padding.
        Real targets use integer geometry; VKCell targets use micrometers.
        All layers use the same original bounds. Empty references draw nothing;
        neither the cross section nor the reference box is modified.

        Warning:
            Logs a warning when a non-VKCell target has pending virtual instances,
            even with an explicit reference. Call insert_vinsts() first to avoid
            inaccurate geometry. This method does not materialize instances.

        Raises:
            LockedError: The target cell is locked.
            TypeError: The target or reference type is unsupported.
            ValueError: The target or instance reference uses another KCLayout.
        """
        from .kcell import DKCell, KCell, VKCell

        if not isinstance(c, KCell | DKCell | VKCell):
            raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
        if c.kcl is not self.kcl:
            raise ValueError(
                "The cross section and target must share the same KCLayout"
            )
        if c.locked:
            raise LockedError(c)
        if isinstance(c, KCell | DKCell):
            self.to_itype().add_bbox(
                c,
                ref,
                top=self.kcl.to_dbu(top),
                bottom=self.kcl.to_dbu(bottom),
                right=self.kcl.to_dbu(right),
                left=self.kcl.to_dbu(left),
            )
            return
        bbox = _bbox_reference(c, ref)
        _add_bbox_virtual(
            c,
            bbox if isinstance(bbox, kdb.DBox) else self.kcl.to_um(bbox),
            {
                self.kcl.layer(layer): offset
                for layer, offset in self.bbox_sections.items()
            },
            top=top,
            bottom=bottom,
            right=right,
            left=left,
        )

    @overload
    def __init__(self, kcl: KCLayout, *, base: AsymmetricalCrossSection) -> None: ...

    @overload
    def __init__(
        self,
        kcl: KCLayout,
        section_min: float,
        section_max: float,
        layer: kdb.LayerInfo,
        sections: Sequence[DCrossSectionLayer] = (),
        name: str | None = None,
        radius: float | None = None,
        radius_min: float | None = None,
        bbox_sections: dict[kdb.LayerInfo, float] | None = None,
    ) -> None: ...

    def __init__(
        self,
        kcl: KCLayout,
        section_min: float | None = None,
        section_max: float | None = None,
        layer: kdb.LayerInfo | None = None,
        sections: Sequence[DCrossSectionLayer] = (),
        name: str | None = None,
        radius: float | None = None,
        radius_min: float | None = None,
        bbox_sections: dict[kdb.LayerInfo, float] | None = None,
        base: AsymmetricalCrossSection | None = None,
    ) -> None:
        if base is None:
            if section_min is None or section_max is None or layer is None:
                raise ValueError(
                    "If no base is given, section_min, section_max, and layer"
                    " must be defined"
                )
            base = kcl.get_asymmetrical_cross_section(
                DAsymmetricalCrossSection(
                    layer=layer,
                    section_min=section_min,
                    section_max=section_max,
                    sections=tuple(sections),
                    name=name,
                    radius=radius,
                    radius_min=radius_min,
                    bbox_sections=bbox_sections or {},
                ).to_itype(kcl)
            )
        self.kcl = kcl
        self._base = base

    @property
    def width(self) -> float:
        return self.kcl.to_um(self._base.width)

    @property
    def section_min(self) -> float:
        return self.kcl.to_um(self._base.section_min)

    @property
    def section_max(self) -> float:
        return self.kcl.to_um(self._base.section_max)

    @property
    def sections(self) -> tuple[DCrossSectionLayer, ...]:
        return _to_dsections(self.kcl, self._base.sections)

    def get_sections(self) -> tuple[DCrossSectionLayer, ...]:
        """Absolute signed um strips of the realised profile, main strip first."""
        return _to_dsections(self.kcl, self._base.get_sections())

    @property
    def radius(self) -> float | None:
        return self.kcl.to_um(self._base.radius)

    @property
    def radius_min(self) -> float | None:
        return self.kcl.to_um(self._base.radius_min)

    @property
    def bbox_sections(self) -> dict[kdb.LayerInfo, float]:
        return {k: self.kcl.to_um(v) for k, v in self._base.bbox_sections.items()}

    def get_xmin_xmax(self) -> tuple[float, float]:
        return (
            self.kcl.to_um(self._base.get_xmin()),
            self.kcl.to_um(self._base.get_xmax()),
        )

add_bbox

add_bbox(c: KCell | DKCell | VKCell, ref: LayerInfo | int | Box | DBox | ProtoInstance[Any] | None = None, *, top: float | None = None, bottom: float | None = None, right: float | None = None, left: float | None = None) -> None

Draw bbox_sections using padding in micrometers.

Parameters:

Name Type Description Default
c KCell | DKCell | VKCell

Target KCell, DKCell, or VKCell, including subclasses. Must share this cross section's KCLayout, as must any instance reference.

required
ref LayerInfo | int | Box | DBox | ProtoInstance[Any] | None

None for the whole target, a layer/index in c, an explicit Box (dbu) or DBox (micrometers), or an instance's transformed bounds in c's coordinate system. Cell references are not accepted.

None
top float | None

Top padding override for every bbox layer.

None
bottom float | None

Bottom padding override for every bbox layer.

None
right float | None

Right padding override for every bbox layer.

None
left float | None

Left padding override for every bbox layer.

None

None padding uses each layer's stored offset; zero suppresses padding. Real targets use integer geometry; VKCell targets use micrometers. All layers use the same original bounds. Empty references draw nothing; neither the cross section nor the reference box is modified.

Warning

Logs a warning when a non-VKCell target has pending virtual instances, even with an explicit reference. Call insert_vinsts() first to avoid inaccurate geometry. This method does not materialize instances.

Raises:

Type Description
LockedError

The target cell is locked.

TypeError

The target or reference type is unsupported.

ValueError

The target or instance reference uses another KCLayout.

Source code in kfactory/cross_section.py
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
def add_bbox(
    self,
    c: KCell | DKCell | VKCell,
    ref: kdb.LayerInfo
    | int
    | kdb.Box
    | kdb.DBox
    | ProtoInstance[Any]
    | None = None,
    *,
    top: float | None = None,
    bottom: float | None = None,
    right: float | None = None,
    left: float | None = None,
) -> None:
    """Draw bbox_sections using padding in micrometers.

    Args:
        c: Target KCell, DKCell, or VKCell, including subclasses. Must share
            this cross section's KCLayout, as must any instance reference.
        ref: None for the whole target, a layer/index in c, an explicit
            Box (dbu) or DBox (micrometers), or an instance's transformed
            bounds in c's coordinate system. Cell references are not accepted.
        top: Top padding override for every bbox layer.
        bottom: Bottom padding override for every bbox layer.
        right: Right padding override for every bbox layer.
        left: Left padding override for every bbox layer.

    None padding uses each layer's stored offset; zero suppresses padding.
    Real targets use integer geometry; VKCell targets use micrometers.
    All layers use the same original bounds. Empty references draw nothing;
    neither the cross section nor the reference box is modified.

    Warning:
        Logs a warning when a non-VKCell target has pending virtual instances,
        even with an explicit reference. Call insert_vinsts() first to avoid
        inaccurate geometry. This method does not materialize instances.

    Raises:
        LockedError: The target cell is locked.
        TypeError: The target or reference type is unsupported.
        ValueError: The target or instance reference uses another KCLayout.
    """
    from .kcell import DKCell, KCell, VKCell

    if not isinstance(c, KCell | DKCell | VKCell):
        raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
    if c.kcl is not self.kcl:
        raise ValueError(
            "The cross section and target must share the same KCLayout"
        )
    if c.locked:
        raise LockedError(c)
    if isinstance(c, KCell | DKCell):
        self.to_itype().add_bbox(
            c,
            ref,
            top=self.kcl.to_dbu(top),
            bottom=self.kcl.to_dbu(bottom),
            right=self.kcl.to_dbu(right),
            left=self.kcl.to_dbu(left),
        )
        return
    bbox = _bbox_reference(c, ref)
    _add_bbox_virtual(
        c,
        bbox if isinstance(bbox, kdb.DBox) else self.kcl.to_um(bbox),
        {
            self.kcl.layer(layer): offset
            for layer, offset in self.bbox_sections.items()
        },
        top=top,
        bottom=bottom,
        right=right,
        left=left,
    )

get_sections

get_sections() -> tuple[DCrossSectionLayer, ...]

Absolute signed um strips of the realised profile, main strip first.

Source code in kfactory/cross_section.py
1263
1264
1265
def get_sections(self) -> tuple[DCrossSectionLayer, ...]:
    """Absolute signed um strips of the realised profile, main strip first."""
    return _to_dsections(self.kcl, self._base.get_sections())

DAsymmetricalCrossSection pydantic-model

Bases: BaseModel

um based AsymmetricalCrossSection.

Fields:

  • layer (LayerInfo)
  • section_min (float)
  • section_max (float)
  • sections (tuple[DCrossSectionLayer, ...])
  • name (str | None)
  • radius (float | None)
  • radius_min (float | None)
  • bbox_sections (dict[LayerInfo, float])

Validators:

  • _validate_bounds
Source code in kfactory/cross_section.py
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
class DAsymmetricalCrossSection(BaseModel, arbitrary_types_allowed=True):
    """um based AsymmetricalCrossSection."""

    layer: kdb.LayerInfo
    section_min: float
    section_max: float
    sections: tuple[DCrossSectionLayer, ...] = ()
    name: str | None = None
    radius: float | None = None
    radius_min: float | None = None
    bbox_sections: dict[kdb.LayerInfo, float] = Field(default_factory=dict)

    @model_validator(mode="after")
    def _validate_bounds(self) -> Self:
        if self.section_min >= self.section_max:
            raise ValueError(
                "section_min must be strictly less than section_max"
                f" (got section_min={self.section_min},"
                f" section_max={self.section_max})."
            )
        return self

    @property
    def width(self) -> float:
        """Main strip width in um (`section_max - section_min`)."""
        return self.section_max - self.section_min

    def is_symmetric(self) -> bool:
        """Whether this cross section is symmetric."""
        return False

    def to_itype(self, kcl: KCLayout) -> AsymmetricalCrossSection:
        return AsymmetricalCrossSection(
            layer=self.layer,
            section_min=kcl.to_dbu(self.section_min),
            section_max=kcl.to_dbu(self.section_max),
            sections=tuple(s.to_itype(kcl) for s in self.sections),
            name=self.name or "",
            radius=kcl.to_dbu(self.radius),
            radius_min=kcl.to_dbu(self.radius_min),
            bbox_sections={k: kcl.to_dbu(v) for k, v in self.bbox_sections.items()},
        )

width property

width: float

Main strip width in um (section_max - section_min).

is_symmetric

is_symmetric() -> bool

Whether this cross section is symmetric.

Source code in kfactory/cross_section.py
708
709
710
def is_symmetric(self) -> bool:
    """Whether this cross section is symmetric."""
    return False

DCrossSection

Bases: TCrossSection[float]

Source code in kfactory/cross_section.py
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
class DCrossSection(TCrossSection[float]):
    def add_bbox(
        self,
        c: KCell | DKCell | VKCell,
        ref: kdb.LayerInfo
        | int
        | kdb.Box
        | kdb.DBox
        | ProtoInstance[Any]
        | None = None,
        *,
        top: float | None = None,
        bottom: float | None = None,
        right: float | None = None,
        left: float | None = None,
    ) -> None:
        """Draw bbox_sections using padding in micrometers.

        Args:
            c: Target KCell, DKCell, or VKCell, including subclasses. Must share
                this cross section's KCLayout, as must any instance reference.
            ref: None for the whole target, a layer/index in c, an explicit
                Box (dbu) or DBox (micrometers), or an instance's transformed
                bounds in c's coordinate system. Cell references are not accepted.
            top: Top padding override for every bbox layer.
            bottom: Bottom padding override for every bbox layer.
            right: Right padding override for every bbox layer.
            left: Left padding override for every bbox layer.

        None padding uses each layer's stored offset; zero suppresses padding.
        Real targets use integer geometry; VKCell targets use micrometers.
        All layers use the same original bounds. Empty references draw nothing;
        neither the cross section nor the reference box is modified.

        Warning:
            Logs a warning when a non-VKCell target has pending virtual instances,
            even with an explicit reference. Call insert_vinsts() first to avoid
            inaccurate geometry. This method does not materialize instances.

        Raises:
            LockedError: The target cell is locked.
            TypeError: The target or reference type is unsupported.
            ValueError: The target or instance reference uses another KCLayout.
        """
        from .kcell import DKCell, KCell, VKCell

        if not isinstance(c, KCell | DKCell | VKCell):
            raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
        if c.kcl is not self.kcl:
            raise ValueError(
                "The cross section and target must share the same KCLayout"
            )
        if c.locked:
            raise LockedError(c)
        if isinstance(c, KCell | DKCell):
            self.to_itype().add_bbox(
                c,
                ref,
                top=self.kcl.to_dbu(top),
                bottom=self.kcl.to_dbu(bottom),
                right=self.kcl.to_dbu(right),
                left=self.kcl.to_dbu(left),
            )
            return
        bbox = _bbox_reference(c, ref)
        _add_bbox_virtual(
            c,
            bbox if isinstance(bbox, kdb.DBox) else self.kcl.to_um(bbox),
            {
                self.kcl.layer(layer): offset
                for layer, offset in self.bbox_sections.items()
            },
            top=top,
            bottom=bottom,
            right=right,
            left=left,
        )

    @overload
    def __init__(self, kcl: KCLayout, *, base: SymmetricalCrossSection) -> None: ...

    @overload
    def __init__(
        self,
        kcl: KCLayout,
        width: float,
        layer: kdb.LayerInfo,
        sections: list[
            tuple[kdb.LayerInfo, float, float] | tuple[kdb.LayerInfo, float]
        ],
        radius: float | None = None,
        radius_min: float | None = None,
        name: str | None = None,
        bbox_layers: Sequence[kdb.LayerInfo] | None = None,
        bbox_offsets: Sequence[float] | None = None,
    ) -> None: ...

    def __init__(
        self,
        kcl: KCLayout,
        width: float | None = None,
        layer: kdb.LayerInfo | None = None,
        sections: list[tuple[kdb.LayerInfo, float, float] | tuple[kdb.LayerInfo, float]]
        | None = None,
        radius: float | None = None,
        radius_min: float | None = None,
        name: str | None = None,
        bbox_layers: Sequence[kdb.LayerInfo] | None = None,
        bbox_offsets: Sequence[float] | None = None,
        base: SymmetricalCrossSection | None = None,
    ) -> None:
        if not base:
            if bbox_layers:
                if not bbox_offsets:
                    bbox_offsets = [0 for _ in range(len(bbox_layers))]
                elif len(bbox_offsets) != len(bbox_layers):
                    raise ValueError(
                        "Length of the bbox_layers list and the bbox_offsets list"
                        " must be the same "
                        f"{len(bbox_layers)=}, {len(bbox_offsets)=}"
                    )
            else:
                bbox_layers = []
                bbox_offsets = []
            if width is None or layer is None or sections is None:
                raise ValueError(
                    "If no base is given, width, layer, and sections must be defined"
                )
            base = kcl.get_symmetrical_cross_section(
                SymmetricalCrossSection(
                    width=kcl.to_dbu(width),
                    enclosure=LayerEnclosure(
                        sections=[
                            (s[0], *[kcl.to_dbu(s[i]) for i in range(1, len(s))])  # ty:ignore[no-matching-overload]
                            for s in sections
                        ],
                        main_layer=layer,
                        bbox_sections=[
                            (s[0], kcl.to_dbu(s[1]))
                            for s in zip(bbox_layers, bbox_offsets)  # noqa: B905
                        ],
                    ),
                    name=name,
                    radius=kcl.to_dbu(radius),
                    radius_min=kcl.to_dbu(radius_min),
                )
            )
        self.kcl = kcl
        self._base = base

    @property
    def sections(self) -> dict[kdb.LayerInfo, list[tuple[float | None, float]]]:
        items = self._base.enclosure.layer_sections.items()
        return {
            layer: [
                (
                    self.kcl.to_um(section.d_min),
                    self.kcl.to_um(section.d_max),
                )
                for section in sections.sections
            ]
            for layer, sections in items
        }

    def get_sections(self) -> tuple[DCrossSectionLayer, ...]:
        """Absolute signed um strips of the realised profile, main strip first.

        Unlike `sections`, which returns the enclosure's edge-relative bands,
        this resolves them against the core width and includes the main strip.
        """
        return _to_dsections(self.kcl, self._base.get_sections())

    @property
    def bbox_sections(self) -> dict[kdb.LayerInfo, float]:
        return {k: self.kcl.to_um(v) for k, v in self._base.bbox_sections.items()}

    @property
    def width(self) -> float:
        return self.kcl.to_um(self._base.width)

    @property
    def radius(self) -> float | None:
        return self.kcl.to_um(self._base.radius)

    @property
    def radius_min(self) -> float | None:
        return self.kcl.to_um(self._base.radius_min)

    def get_xmin_xmax(self) -> tuple[float, float]:
        return (
            self.kcl.to_um(self._base.get_xmin()),
            self.kcl.to_um(self._base.get_xmax()),
        )

    def model_copy(
        self, *, update: Mapping[str, Any] = {"name": None}, deep: bool
    ) -> DCrossSection:
        return DCrossSection(
            kcl=self.kcl, base=self.base.model_copy(update=update, deep=deep)
        )

add_bbox

add_bbox(c: KCell | DKCell | VKCell, ref: LayerInfo | int | Box | DBox | ProtoInstance[Any] | None = None, *, top: float | None = None, bottom: float | None = None, right: float | None = None, left: float | None = None) -> None

Draw bbox_sections using padding in micrometers.

Parameters:

Name Type Description Default
c KCell | DKCell | VKCell

Target KCell, DKCell, or VKCell, including subclasses. Must share this cross section's KCLayout, as must any instance reference.

required
ref LayerInfo | int | Box | DBox | ProtoInstance[Any] | None

None for the whole target, a layer/index in c, an explicit Box (dbu) or DBox (micrometers), or an instance's transformed bounds in c's coordinate system. Cell references are not accepted.

None
top float | None

Top padding override for every bbox layer.

None
bottom float | None

Bottom padding override for every bbox layer.

None
right float | None

Right padding override for every bbox layer.

None
left float | None

Left padding override for every bbox layer.

None

None padding uses each layer's stored offset; zero suppresses padding. Real targets use integer geometry; VKCell targets use micrometers. All layers use the same original bounds. Empty references draw nothing; neither the cross section nor the reference box is modified.

Warning

Logs a warning when a non-VKCell target has pending virtual instances, even with an explicit reference. Call insert_vinsts() first to avoid inaccurate geometry. This method does not materialize instances.

Raises:

Type Description
LockedError

The target cell is locked.

TypeError

The target or reference type is unsupported.

ValueError

The target or instance reference uses another KCLayout.

Source code in kfactory/cross_section.py
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
def add_bbox(
    self,
    c: KCell | DKCell | VKCell,
    ref: kdb.LayerInfo
    | int
    | kdb.Box
    | kdb.DBox
    | ProtoInstance[Any]
    | None = None,
    *,
    top: float | None = None,
    bottom: float | None = None,
    right: float | None = None,
    left: float | None = None,
) -> None:
    """Draw bbox_sections using padding in micrometers.

    Args:
        c: Target KCell, DKCell, or VKCell, including subclasses. Must share
            this cross section's KCLayout, as must any instance reference.
        ref: None for the whole target, a layer/index in c, an explicit
            Box (dbu) or DBox (micrometers), or an instance's transformed
            bounds in c's coordinate system. Cell references are not accepted.
        top: Top padding override for every bbox layer.
        bottom: Bottom padding override for every bbox layer.
        right: Right padding override for every bbox layer.
        left: Left padding override for every bbox layer.

    None padding uses each layer's stored offset; zero suppresses padding.
    Real targets use integer geometry; VKCell targets use micrometers.
    All layers use the same original bounds. Empty references draw nothing;
    neither the cross section nor the reference box is modified.

    Warning:
        Logs a warning when a non-VKCell target has pending virtual instances,
        even with an explicit reference. Call insert_vinsts() first to avoid
        inaccurate geometry. This method does not materialize instances.

    Raises:
        LockedError: The target cell is locked.
        TypeError: The target or reference type is unsupported.
        ValueError: The target or instance reference uses another KCLayout.
    """
    from .kcell import DKCell, KCell, VKCell

    if not isinstance(c, KCell | DKCell | VKCell):
        raise TypeError("The bbox target must be a KCell, DKCell, or VKCell")
    if c.kcl is not self.kcl:
        raise ValueError(
            "The cross section and target must share the same KCLayout"
        )
    if c.locked:
        raise LockedError(c)
    if isinstance(c, KCell | DKCell):
        self.to_itype().add_bbox(
            c,
            ref,
            top=self.kcl.to_dbu(top),
            bottom=self.kcl.to_dbu(bottom),
            right=self.kcl.to_dbu(right),
            left=self.kcl.to_dbu(left),
        )
        return
    bbox = _bbox_reference(c, ref)
    _add_bbox_virtual(
        c,
        bbox if isinstance(bbox, kdb.DBox) else self.kcl.to_um(bbox),
        {
            self.kcl.layer(layer): offset
            for layer, offset in self.bbox_sections.items()
        },
        top=top,
        bottom=bottom,
        right=right,
        left=left,
    )

get_sections

get_sections() -> tuple[DCrossSectionLayer, ...]

Absolute signed um strips of the realised profile, main strip first.

Unlike sections, which returns the enclosure's edge-relative bands, this resolves them against the core width and includes the main strip.

Source code in kfactory/cross_section.py
1790
1791
1792
1793
1794
1795
1796
def get_sections(self) -> tuple[DCrossSectionLayer, ...]:
    """Absolute signed um strips of the realised profile, main strip first.

    Unlike `sections`, which returns the enclosure's edge-relative bands,
    this resolves them against the core width and includes the main strip.
    """
    return _to_dsections(self.kcl, self._base.get_sections())

DCrossSectionLayer pydantic-model

Bases: BaseModel

um based CrossSectionLayer.

Fields:

  • layer (LayerInfo)
  • section_min (float)
  • section_max (float)

Validators:

  • _validate_bounds
Source code in kfactory/cross_section.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
class DCrossSectionLayer(BaseModel, arbitrary_types_allowed=True):
    """um based CrossSectionLayer."""

    layer: kdb.LayerInfo
    section_min: float
    section_max: float

    @model_validator(mode="after")
    def _validate_bounds(self) -> Self:
        if self.section_min >= self.section_max:
            raise ValueError(
                "section_min must be strictly less than section_max (got"
                f" section_min={self.section_min},"
                f" section_max={self.section_max})."
            )
        return self

    @property
    def width(self) -> float:
        """Width of the strip in um (`section_max - section_min`)."""
        return self.section_max - self.section_min

    def to_itype(self, kcl: KCLayout) -> CrossSectionLayer:
        return CrossSectionLayer(
            layer=self.layer,
            section_min=kcl.to_dbu(self.section_min),
            section_max=kcl.to_dbu(self.section_max),
        )

width property

width: float

Width of the strip in um (section_max - section_min).

DSymmetricalCrossSection pydantic-model

Bases: BaseModel

um based CrossSection.

Fields:

  • width (float)
  • enclosure (DLayerEnclosure)
  • name (str | None)
  • radius (float | None)
  • radius_min (float | None)

Validators:

  • _validate_width
Source code in kfactory/cross_section.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
class DSymmetricalCrossSection(BaseModel):
    """um based CrossSection."""

    width: float
    enclosure: DLayerEnclosure
    name: str | None = None
    radius: float | None = None
    radius_min: float | None = None

    @model_validator(mode="after")
    def _validate_width(self) -> Self:
        if self.width <= 0:
            raise ValueError("Width must be greater than 0.")
        return self

    def is_symmetric(self) -> bool:
        """Whether this cross section is symmetric."""
        return True

    def to_itype(self, kcl: KCLayout) -> SymmetricalCrossSection:
        """Convert to a dbu based CrossSection."""
        return SymmetricalCrossSection(
            width=kcl.to_dbu(self.width),
            enclosure=kcl.get_enclosure(self.enclosure.to_itype(kcl)),
            name=self.name,
            radius=kcl.to_dbu(self.radius),
            radius_min=kcl.to_dbu(self.radius_min),
        )

is_symmetric

is_symmetric() -> bool

Whether this cross section is symmetric.

Source code in kfactory/cross_section.py
237
238
239
def is_symmetric(self) -> bool:
    """Whether this cross section is symmetric."""
    return True

to_itype

to_itype(kcl: KCLayout) -> SymmetricalCrossSection

Convert to a dbu based CrossSection.

Source code in kfactory/cross_section.py
241
242
243
244
245
246
247
248
249
def to_itype(self, kcl: KCLayout) -> SymmetricalCrossSection:
    """Convert to a dbu based CrossSection."""
    return SymmetricalCrossSection(
        width=kcl.to_dbu(self.width),
        enclosure=kcl.get_enclosure(self.enclosure.to_itype(kcl)),
        name=self.name,
        radius=kcl.to_dbu(self.radius),
        radius_min=kcl.to_dbu(self.radius_min),
    )

SymmetricalCrossSection pydantic-model

Bases: BaseModel

CrossSection which is symmetrical to its main_layer/width.

Fields:

Validators:

  • _set_name
  • _validate_enclosure_main_layer
  • _validate_width
Source code in kfactory/cross_section.py
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
class SymmetricalCrossSection(BaseModel, frozen=True, arbitrary_types_allowed=True):
    """CrossSection which is symmetrical to its main_layer/width."""

    width: dbu
    enclosure: LayerEnclosure
    name: str = ""
    radius: dbu | None = None
    radius_min: dbu | None = None

    def __init__(
        self,
        width: dbu,
        enclosure: LayerEnclosure,
        name: str | None = None,
        radius: dbu | None = None,
        radius_min: dbu | None = None,
    ) -> None:
        """Initialized the CrossSection.

        `bbox_sections` live on the `enclosure` — build the enclosure with them.
        """
        super().__init__(
            width=width,
            enclosure=enclosure,
            name=name or f"{enclosure.name}_{width}",
            radius=radius,
            radius_min=radius_min,
        )

    @property
    def bbox_sections(self) -> dict[kdb.LayerInfo, dbu]:
        """Bounding-box sections (owned by the enclosure)."""
        return self.enclosure.bbox_sections

    def auto_name(self) -> str:
        return f"{self.enclosure.name}_{self.width}"

    @property
    def is_named(self) -> bool:
        """Whether an explicit name was given (vs. the enclosure-derived name)."""
        return self.name != self.auto_name()

    @property
    def extent(self) -> dbu:
        return 0

    @model_validator(mode="before")
    @classmethod
    def _set_name(cls, data: Any) -> Any:
        if not isinstance(data, dict):
            return data
        data["name"] = data.get("name") or f"{data['enclosure'].name}_{data['width']}"
        return data

    @model_validator(mode="after")
    def _validate_enclosure_main_layer(self) -> Self:
        if self.enclosure.main_layer is None:
            raise ValueError("Enclosures of cross sections must have a main layer.")
        if self.width % 2:
            raise ValueError(
                "Width of symmetrical cross sections must have be a multiple of 2 dbu. "
                "This could cause cross sections and extrusions to become unsymmetrical"
                " otherwise."
            )
        if not self.width:
            raise ValueError("Cross section with width 0 is not allowed.")
        return self

    @model_validator(mode="after")
    def _validate_width(self) -> Self:
        if self.width <= 0:
            raise ValueError("Width must be greater than 0.")
        return self

    @property
    def main_layer(self) -> kdb.LayerInfo:
        """Main Layer of the enclosure and cross section."""
        assert self.enclosure.main_layer is not None
        return self.enclosure.main_layer

    def is_symmetric(self) -> bool:
        """Whether this cross section is symmetric."""
        return True

    def get_sections(self) -> tuple[CrossSectionLayer, ...]:
        """Absolute signed dbu strips of the realised profile, main strip first.

        The main strip is `width` centered on the center line; the enclosure's
        edge-relative bands are resolved against that width, so a 3 µm band sits
        at ±3.25 µm for a 500 nm core and at ±3.55 µm for an 1100 nm one.

        The main strip is always first and is never merged into the others, even
        when the enclosure carries a band on the main layer. The remaining
        strips are normalized per layer (touching or overlapping ones are
        merged) and sorted, matching `AsymmetricalCrossSection.sections`.
        """
        half = self.width // 2
        return (
            CrossSectionLayer(
                layer=self.main_layer, section_min=-half, section_max=half
            ),
            *_enclosure_strips(self.width, self.enclosure),
        )

    def to_dtype(self, kcl: KCLayout) -> DSymmetricalCrossSection:
        """Convert to a um based CrossSection."""
        return DSymmetricalCrossSection(
            width=kcl.to_um(self.width),
            enclosure=self.enclosure.to_dtype(kcl),
            name=self.name,
            radius=kcl.to_um(self.radius),
            radius_min=kcl.to_um(self.radius_min),
        )

    def get_xmax(self) -> int:
        """Outer edge of the profile in dbu.

        The core always reaches `width // 2`, so the enclosure can only push the
        extent outwards: a cross section with no bands at all is just its core,
        and a band that shrinks inwards (negative `d_max`) does not pull the
        extent inside the core it sits on.
        """
        outermost = max(
            (
                s.d_max
                for sections in self.enclosure.layer_sections.values()
                for s in sections.sections
            ),
            default=0,
        )
        return self.width // 2 + max(outermost, 0)

    def get_xmin(self) -> int:
        # Symmetric by construction: the full extent is mirrored about the center line.
        return -self.get_xmax()

    def model_copy(
        self, *, update: Mapping[str, Any] | None = {"name": None}, deep: bool = False
    ) -> SymmetricalCrossSection:
        return super().model_copy(update=update, deep=deep)

    def __eq__(self, o: object) -> bool:
        if isinstance(o, (AsymmetricalCrossSection, TAsymmetricCrossSection)):
            return False
        if isinstance(o, TCrossSection):
            return self == o.base
        if isinstance(o, SymmetricalCrossSection):
            # radius/radius_min are non-identifying metadata.
            return (
                self.width == o.width
                and self.enclosure == o.enclosure
                and self.name == o.name
            )
        return NotImplemented

    def __hash__(self) -> int:
        return hash((self.width, self.enclosure, self.name))

bbox_sections property

bbox_sections: dict[LayerInfo, dbu]

Bounding-box sections (owned by the enclosure).

is_named property

is_named: bool

Whether an explicit name was given (vs. the enclosure-derived name).

main_layer property

main_layer: LayerInfo

Main Layer of the enclosure and cross section.

__init__

__init__(width: dbu, enclosure: LayerEnclosure, name: str | None = None, radius: dbu | None = None, radius_min: dbu | None = None) -> None

Initialized the CrossSection.

bbox_sections live on the enclosure — build the enclosure with them.

Source code in kfactory/cross_section.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def __init__(
    self,
    width: dbu,
    enclosure: LayerEnclosure,
    name: str | None = None,
    radius: dbu | None = None,
    radius_min: dbu | None = None,
) -> None:
    """Initialized the CrossSection.

    `bbox_sections` live on the `enclosure` — build the enclosure with them.
    """
    super().__init__(
        width=width,
        enclosure=enclosure,
        name=name or f"{enclosure.name}_{width}",
        radius=radius,
        radius_min=radius_min,
    )

get_sections

get_sections() -> tuple[CrossSectionLayer, ...]

Absolute signed dbu strips of the realised profile, main strip first.

The main strip is width centered on the center line; the enclosure's edge-relative bands are resolved against that width, so a 3 µm band sits at ±3.25 µm for a 500 nm core and at ±3.55 µm for an 1100 nm one.

The main strip is always first and is never merged into the others, even when the enclosure carries a band on the main layer. The remaining strips are normalized per layer (touching or overlapping ones are merged) and sorted, matching AsymmetricalCrossSection.sections.

Source code in kfactory/cross_section.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def get_sections(self) -> tuple[CrossSectionLayer, ...]:
    """Absolute signed dbu strips of the realised profile, main strip first.

    The main strip is `width` centered on the center line; the enclosure's
    edge-relative bands are resolved against that width, so a 3 µm band sits
    at ±3.25 µm for a 500 nm core and at ±3.55 µm for an 1100 nm one.

    The main strip is always first and is never merged into the others, even
    when the enclosure carries a band on the main layer. The remaining
    strips are normalized per layer (touching or overlapping ones are
    merged) and sorted, matching `AsymmetricalCrossSection.sections`.
    """
    half = self.width // 2
    return (
        CrossSectionLayer(
            layer=self.main_layer, section_min=-half, section_max=half
        ),
        *_enclosure_strips(self.width, self.enclosure),
    )

get_xmax

get_xmax() -> int

Outer edge of the profile in dbu.

The core always reaches width // 2, so the enclosure can only push the extent outwards: a cross section with no bands at all is just its core, and a band that shrinks inwards (negative d_max) does not pull the extent inside the core it sits on.

Source code in kfactory/cross_section.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def get_xmax(self) -> int:
    """Outer edge of the profile in dbu.

    The core always reaches `width // 2`, so the enclosure can only push the
    extent outwards: a cross section with no bands at all is just its core,
    and a band that shrinks inwards (negative `d_max`) does not pull the
    extent inside the core it sits on.
    """
    outermost = max(
        (
            s.d_max
            for sections in self.enclosure.layer_sections.values()
            for s in sections.sections
        ),
        default=0,
    )
    return self.width // 2 + max(outermost, 0)

is_symmetric

is_symmetric() -> bool

Whether this cross section is symmetric.

Source code in kfactory/cross_section.py
143
144
145
def is_symmetric(self) -> bool:
    """Whether this cross section is symmetric."""
    return True

to_dtype

to_dtype(kcl: KCLayout) -> DSymmetricalCrossSection

Convert to a um based CrossSection.

Source code in kfactory/cross_section.py
167
168
169
170
171
172
173
174
175
def to_dtype(self, kcl: KCLayout) -> DSymmetricalCrossSection:
    """Convert to a um based CrossSection."""
    return DSymmetricalCrossSection(
        width=kcl.to_um(self.width),
        enclosure=self.enclosure.to_dtype(kcl),
        name=self.name,
        radius=kcl.to_um(self.radius),
        radius_min=kcl.to_um(self.radius_min),
    )

TAsymmetricCrossSection

Bases: ABC

Unit-flavored wrapper around an AsymmetricalCrossSection base.

Mirrors TCrossSection for the symmetric case: both the dbu wrapper (AsymmetricCrossSection) and the um wrapper (DAsymmetricCrossSection) hold the same AsymmetricalCrossSection as _base, so they compare equal across units via .base.

Source code in kfactory/cross_section.py
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
class TAsymmetricCrossSection[T: (int, float)](ABC):
    """Unit-flavored wrapper around an `AsymmetricalCrossSection` base.

    Mirrors `TCrossSection` for the symmetric case: both the dbu wrapper
    (`AsymmetricCrossSection`) and the um wrapper (`DAsymmetricCrossSection`)
    hold the same `AsymmetricalCrossSection` as `_base`, so they compare equal
    across units via `.base`.
    """

    _base: AsymmetricalCrossSection = PrivateAttr()
    kcl: KCLayout

    @property
    def base(self) -> AsymmetricalCrossSection:
        return self._base

    @property
    def name(self) -> str:
        return self._base.name

    @property
    def layer(self) -> kdb.LayerInfo:
        return self._base.layer

    @property
    def main_layer(self) -> kdb.LayerInfo:
        return self._base.layer

    def is_symmetric(self) -> bool:
        """Whether this cross section is symmetric."""
        return False

    @property
    @abstractmethod
    def width(self) -> T: ...

    @property
    @abstractmethod
    def section_min(self) -> T: ...

    @property
    @abstractmethod
    def section_max(self) -> T: ...

    @property
    @abstractmethod
    def sections(
        self,
    ) -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]: ...

    @abstractmethod
    def get_sections(
        self,
    ) -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]:
        """Absolute strips of the realised profile, main strip first."""
        ...

    @property
    @abstractmethod
    def radius(self) -> T | None: ...

    @property
    @abstractmethod
    def radius_min(self) -> T | None: ...

    @property
    @abstractmethod
    def bbox_sections(self) -> dict[kdb.LayerInfo, T]: ...

    @abstractmethod
    def add_bbox(
        self,
        c: KCell | DKCell | VKCell,
        ref: kdb.LayerInfo
        | int
        | kdb.Box
        | kdb.DBox
        | ProtoInstance[Any]
        | None = None,
        *,
        top: T | None = None,
        bottom: T | None = None,
        right: T | None = None,
        left: T | None = None,
    ) -> None:
        """Draw bbox_sections around a cell, layer, box, or instance.

        Args:
            c: Target KCell, DKCell, or VKCell (including subclasses), sharing this
                cross section's KCLayout. Instance references must share it too.
            ref: Reference layer/index in c, explicit Box/DBox, or instance.
                None uses the whole cell. A Box is in c's dbu; a DBox is in
                micrometers. Instances use their transformed bounds in their
                parent coordinates, which must match c's coordinate system.
            top: Override top padding for every bbox layer.
            bottom: Override bottom padding for every bbox layer.
            right: Override right padding for every bbox layer.
            left: Override left padding for every bbox layer.

        Padding uses this cross section's units (dbu or micrometers).
        None uses each layer's stored padding; zero suppresses padding on that
        edge. All layers share the original reference bounds. Empty references
        draw nothing. The cross section and reference box are not modified.
        Real-cell geometry is computed in integer DBU after converting inputs;
        virtual-cell geometry remains in micrometers without grid snapping.
        Warns if a real target has pending virtual instances; call insert_vinsts()
        before adding bbox layers to avoid inaccurate geometry.
        """
        ...

    @abstractmethod
    def get_xmin_xmax(self) -> tuple[T, T]: ...

    def to_itype(self) -> AsymmetricCrossSection:
        return AsymmetricCrossSection(kcl=self.kcl, base=self._base)

    def to_dtype(self) -> DAsymmetricCrossSection:
        return DAsymmetricCrossSection(kcl=self.kcl, base=self._base)

    def __eq__(self, o: object) -> bool:
        if isinstance(o, TAsymmetricCrossSection):
            return self.base == o.base
        if isinstance(o, AsymmetricalCrossSection):
            return self.base == o
        return False

    def __hash__(self) -> int:
        return hash(self._base)

add_bbox abstractmethod

add_bbox(c: KCell | DKCell | VKCell, ref: LayerInfo | int | Box | DBox | ProtoInstance[Any] | None = None, *, top: T | None = None, bottom: T | None = None, right: T | None = None, left: T | None = None) -> None

Draw bbox_sections around a cell, layer, box, or instance.

Parameters:

Name Type Description Default
c KCell | DKCell | VKCell

Target KCell, DKCell, or VKCell (including subclasses), sharing this cross section's KCLayout. Instance references must share it too.

required
ref LayerInfo | int | Box | DBox | ProtoInstance[Any] | None

Reference layer/index in c, explicit Box/DBox, or instance. None uses the whole cell. A Box is in c's dbu; a DBox is in micrometers. Instances use their transformed bounds in their parent coordinates, which must match c's coordinate system.

None
top T | None

Override top padding for every bbox layer.

None
bottom T | None

Override bottom padding for every bbox layer.

None
right T | None

Override right padding for every bbox layer.

None
left T | None

Override left padding for every bbox layer.

None

Padding uses this cross section's units (dbu or micrometers). None uses each layer's stored padding; zero suppresses padding on that edge. All layers share the original reference bounds. Empty references draw nothing. The cross section and reference box are not modified. Real-cell geometry is computed in integer DBU after converting inputs; virtual-cell geometry remains in micrometers without grid snapping. Warns if a real target has pending virtual instances; call insert_vinsts() before adding bbox layers to avoid inaccurate geometry.

Source code in kfactory/cross_section.py
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
@abstractmethod
def add_bbox(
    self,
    c: KCell | DKCell | VKCell,
    ref: kdb.LayerInfo
    | int
    | kdb.Box
    | kdb.DBox
    | ProtoInstance[Any]
    | None = None,
    *,
    top: T | None = None,
    bottom: T | None = None,
    right: T | None = None,
    left: T | None = None,
) -> None:
    """Draw bbox_sections around a cell, layer, box, or instance.

    Args:
        c: Target KCell, DKCell, or VKCell (including subclasses), sharing this
            cross section's KCLayout. Instance references must share it too.
        ref: Reference layer/index in c, explicit Box/DBox, or instance.
            None uses the whole cell. A Box is in c's dbu; a DBox is in
            micrometers. Instances use their transformed bounds in their
            parent coordinates, which must match c's coordinate system.
        top: Override top padding for every bbox layer.
        bottom: Override bottom padding for every bbox layer.
        right: Override right padding for every bbox layer.
        left: Override left padding for every bbox layer.

    Padding uses this cross section's units (dbu or micrometers).
    None uses each layer's stored padding; zero suppresses padding on that
    edge. All layers share the original reference bounds. Empty references
    draw nothing. The cross section and reference box are not modified.
    Real-cell geometry is computed in integer DBU after converting inputs;
    virtual-cell geometry remains in micrometers without grid snapping.
    Warns if a real target has pending virtual instances; call insert_vinsts()
    before adding bbox layers to avoid inaccurate geometry.
    """
    ...

get_sections abstractmethod

get_sections() -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]

Absolute strips of the realised profile, main strip first.

Source code in kfactory/cross_section.py
869
870
871
872
873
874
@abstractmethod
def get_sections(
    self,
) -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]:
    """Absolute strips of the realised profile, main strip first."""
    ...

is_symmetric

is_symmetric() -> bool

Whether this cross section is symmetric.

Source code in kfactory/cross_section.py
847
848
849
def is_symmetric(self) -> bool:
    """Whether this cross section is symmetric."""
    return False

TCrossSection

Bases: ABC

Source code in kfactory/cross_section.py
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
class TCrossSection[T: (int, float)](ABC):
    _base: SymmetricalCrossSection = PrivateAttr()
    kcl: KCLayout

    @overload
    @abstractmethod
    def __init__(self, kcl: KCLayout, *, base: SymmetricalCrossSection) -> None: ...

    @overload
    @abstractmethod
    def __init__(
        self,
        kcl: KCLayout,
        width: T,
        layer: kdb.LayerInfo,
        sections: Sequence[tuple[T, T] | tuple[T]],
        radius: T | None = None,
        radius_min: T | None = None,
        bbox_layers: Sequence[kdb.LayerInfo] | None = None,
        bbox_offsets: Sequence[T] | None = None,
    ) -> None: ...

    @abstractmethod
    def __init__(
        self,
        kcl: KCLayout,
        width: T | None = None,
        layer: kdb.LayerInfo | None = None,
        sections: Sequence[tuple[T, T] | tuple[T]] | None = None,
        radius: T | None = None,
        radius_min: T | None = None,
        bbox_layers: Sequence[kdb.LayerInfo] | None = None,
        bbox_offsets: Sequence[T] | None = None,
        base: SymmetricalCrossSection | None = None,
    ) -> None: ...

    @property
    def base(self) -> SymmetricalCrossSection:
        return self._base

    @property
    @abstractmethod
    def width(self) -> T: ...

    @property
    def layer(self) -> kdb.LayerInfo:
        return self._base.main_layer

    @property
    def enclosure(self) -> LayerEnclosure:
        return self._base.enclosure

    @property
    def name(self) -> str:
        return self._base.name

    def to_itype(self) -> CrossSection:
        return CrossSection(kcl=self.kcl, base=self._base)

    def to_dtype(self) -> DCrossSection:
        return DCrossSection(kcl=self.kcl, base=self._base)

    @property
    @abstractmethod
    def sections(self) -> dict[kdb.LayerInfo, list[tuple[T | None, T]]]: ...

    @abstractmethod
    def get_sections(
        self,
    ) -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]:
        """Absolute strips of the realised profile, main strip first."""
        ...

    @property
    @abstractmethod
    def radius(self) -> T | None: ...

    @property
    @abstractmethod
    def radius_min(self) -> T | None: ...

    @property
    @abstractmethod
    def bbox_sections(
        self,
    ) -> dict[kdb.LayerInfo, T]: ...

    @abstractmethod
    def add_bbox(
        self,
        c: KCell | DKCell | VKCell,
        ref: kdb.LayerInfo
        | int
        | kdb.Box
        | kdb.DBox
        | ProtoInstance[Any]
        | None = None,
        *,
        top: T | None = None,
        bottom: T | None = None,
        right: T | None = None,
        left: T | None = None,
    ) -> None:
        """Draw bbox_sections around a cell, layer, box, or instance.

        Args:
            c: Target KCell, DKCell, or VKCell (including subclasses), sharing this
                cross section's KCLayout. Instance references must share it too.
            ref: Reference layer/index in c, explicit Box/DBox, or instance.
                None uses the whole cell. A Box is in c's dbu; a DBox is in
                micrometers. Instances use their transformed bounds in their
                parent coordinates, which must match c's coordinate system.
            top: Override top padding for every bbox layer.
            bottom: Override bottom padding for every bbox layer.
            right: Override right padding for every bbox layer.
            left: Override left padding for every bbox layer.

        Padding uses this cross section's units (dbu or micrometers).
        None uses each layer's stored padding; zero suppresses padding on that
        edge. All layers share the original reference bounds. Empty references
        draw nothing. The cross section and reference box are not modified.
        Real-cell geometry is computed in integer DBU after converting inputs;
        virtual-cell geometry remains in micrometers without grid snapping.
        Warns if a real target has pending virtual instances; call insert_vinsts()
        before adding bbox layers to avoid inaccurate geometry.
        """
        ...

    @abstractmethod
    def get_xmin_xmax(self) -> tuple[T, T]: ...

    @abstractmethod
    def model_copy(
        self, *, update: Mapping[str, Any] = {"name": None}, deep: bool
    ) -> Self: ...

    def __eq__(self, o: object) -> bool:
        if isinstance(o, TCrossSection):
            return self.base == o.base
        if isinstance(o, SymmetricalCrossSection):
            return self.base == o
        return False

    @property
    def main_layer(self) -> kdb.LayerInfo:
        """Main Layer of the enclosure and cross section."""
        return self.base.main_layer

    def is_symmetric(self) -> bool:
        """Whether this cross section is symmetric."""
        return True

main_layer property

main_layer: LayerInfo

Main Layer of the enclosure and cross section.

add_bbox abstractmethod

add_bbox(c: KCell | DKCell | VKCell, ref: LayerInfo | int | Box | DBox | ProtoInstance[Any] | None = None, *, top: T | None = None, bottom: T | None = None, right: T | None = None, left: T | None = None) -> None

Draw bbox_sections around a cell, layer, box, or instance.

Parameters:

Name Type Description Default
c KCell | DKCell | VKCell

Target KCell, DKCell, or VKCell (including subclasses), sharing this cross section's KCLayout. Instance references must share it too.

required
ref LayerInfo | int | Box | DBox | ProtoInstance[Any] | None

Reference layer/index in c, explicit Box/DBox, or instance. None uses the whole cell. A Box is in c's dbu; a DBox is in micrometers. Instances use their transformed bounds in their parent coordinates, which must match c's coordinate system.

None
top T | None

Override top padding for every bbox layer.

None
bottom T | None

Override bottom padding for every bbox layer.

None
right T | None

Override right padding for every bbox layer.

None
left T | None

Override left padding for every bbox layer.

None

Padding uses this cross section's units (dbu or micrometers). None uses each layer's stored padding; zero suppresses padding on that edge. All layers share the original reference bounds. Empty references draw nothing. The cross section and reference box are not modified. Real-cell geometry is computed in integer DBU after converting inputs; virtual-cell geometry remains in micrometers without grid snapping. Warns if a real target has pending virtual instances; call insert_vinsts() before adding bbox layers to avoid inaccurate geometry.

Source code in kfactory/cross_section.py
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
@abstractmethod
def add_bbox(
    self,
    c: KCell | DKCell | VKCell,
    ref: kdb.LayerInfo
    | int
    | kdb.Box
    | kdb.DBox
    | ProtoInstance[Any]
    | None = None,
    *,
    top: T | None = None,
    bottom: T | None = None,
    right: T | None = None,
    left: T | None = None,
) -> None:
    """Draw bbox_sections around a cell, layer, box, or instance.

    Args:
        c: Target KCell, DKCell, or VKCell (including subclasses), sharing this
            cross section's KCLayout. Instance references must share it too.
        ref: Reference layer/index in c, explicit Box/DBox, or instance.
            None uses the whole cell. A Box is in c's dbu; a DBox is in
            micrometers. Instances use their transformed bounds in their
            parent coordinates, which must match c's coordinate system.
        top: Override top padding for every bbox layer.
        bottom: Override bottom padding for every bbox layer.
        right: Override right padding for every bbox layer.
        left: Override left padding for every bbox layer.

    Padding uses this cross section's units (dbu or micrometers).
    None uses each layer's stored padding; zero suppresses padding on that
    edge. All layers share the original reference bounds. Empty references
    draw nothing. The cross section and reference box are not modified.
    Real-cell geometry is computed in integer DBU after converting inputs;
    virtual-cell geometry remains in micrometers without grid snapping.
    Warns if a real target has pending virtual instances; call insert_vinsts()
    before adding bbox layers to avoid inaccurate geometry.
    """
    ...

get_sections abstractmethod

get_sections() -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]

Absolute strips of the realised profile, main strip first.

Source code in kfactory/cross_section.py
1352
1353
1354
1355
1356
1357
@abstractmethod
def get_sections(
    self,
) -> tuple[CrossSectionLayer, ...] | tuple[DCrossSectionLayer, ...]:
    """Absolute strips of the realised profile, main strip first."""
    ...

is_symmetric

is_symmetric() -> bool

Whether this cross section is symmetric.

Source code in kfactory/cross_section.py
1434
1435
1436
def is_symmetric(self) -> bool:
    """Whether this cross section is symmetric."""
    return True