"""Cookbook: a single-bus ring resonator.

A bus waveguide running east-west, a ring sitting above it with the
gap controlled by `gap`. The ring is just a `lm.Ring` shape on the same
layer as the bus.
"""
import lumicron as lm
import lumicron.pdks.elyon_demo.all as pdk


@lm.pcell
def RingResonator(
    radius: float = 25,
    width: float = 0.5,
    gap: float = 0.2,
    bus_length: float = 200,
):
    c = lm.CELL("RingResonator")

    # Bus waveguide: a flat rectangle along the silicon strip layer.
    bus = lm.Rectangle(x_dim=bus_length, y_dim=width, layer=pdk.LAYER.SILC)
    c.add(bus)
    c.Place(bus).at((0, 0))

    # Ring centered above the bus, separated by gap.
    ring_y = width / 2 + gap + radius
    ring = lm.Ring(outer_radius=radius, width=width, layer=pdk.LAYER.SILC)
    c.add(ring)
    c.Place(ring).at((bus_length / 2, ring_y))

    c.add(lm.PORT("in", position=(0, 0), direction=180,
                  width=width, layer=pdk.LAYER.SILC))
    c.add(lm.PORT("out", position=(bus_length, 0), direction=0,
                  width=width, layer=pdk.LAYER.SILC))
    return c


if __name__ == "__main__":
    RingResonator().to_gds("ring_resonator.gds")
