Port
A named port with position, direction, and optional width.
Ports are the primary mechanism for connecting components and routing
waveguides. Each port has a position in layout space, a unit vector
direction pointing outward from the component, and an optional
width used for waveguide width matching.
# Port facing +X at the origin, 0.5 um wide
p = Port("opt", Point(0, 0), Vector2(1, 0), width=0.5)
# Check the angle (degrees)
p.angle() # 0.0
# Two ports can connect if they are co-located with opposite directions
other = Port("in", Point(0, 0), Vector2(-1, 0), width=0.5)
p.can_connect_to(other) # TrueAttributes
attributenamestrName of the port (e.g. "opt", "in", "out_1").
attributepositionPointPosition of the port in layout coordinates.
attributedirectionVector2Unit vector pointing outward from the component. For example, a port
on the right edge of a component has direction (1, 0).
attributewidthfloat | NoneWaveguide width at this port, or None if unspecified.
Methods
func__init__(name, position, direction, width=None) -> NoneCreate a new Port.
Example
Port("opt", Point(0, 0), Vector2(1, 0), width=0.5)
Port("elec", Point(10, 5), Vector2(0, 1)) # No widthparamnamestrName of the port.
parampositionPointPosition in layout coordinates.
paramdirectionVector2Outward-facing unit vector.
paramwidthfloat | None= NoneWaveguide width at the port, or None.
Returns
Nonefuncangle() -> floatReturn the port direction as an angle in degrees.
The angle is measured counter-clockwise from the +X axis. For example,
a direction of (1, 0) returns 0.0, and (0, 1) returns 90.0.
Returns
floatDirection angle in degrees.
funccan_connect_to(other, tolerance=0.001) -> boolCheck if this port can connect to another port.
Two ports can connect when they are at the same position (within
tolerance) and have opposite directions. This is the geometric
condition for a flush waveguide junction.
Example
a = Port("out", Point(100, 0), Vector2(1, 0), width=0.5)
b = Port("in", Point(100, 0), Vector2(-1, 0), width=0.5)
a.can_connect_to(b) # True — same position, opposite directions
c = Port("in", Point(100, 1), Vector2(-1, 0), width=0.5)
a.can_connect_to(c) # False — positions differparamotherPortThe other port to check against.
paramtolerancefloat= 0.001Maximum position distance for ports to be considered co-located.
Returns
boolTrue if the ports can connect, False otherwise.