"""Create a 10 um x 0.5 um waveguide. Install with: python -m pip install gdstk."""
from pathlib import Path
import gdstk

# Coordinates are in micrometres. The GDS database precision is 1 nm.
library = gdstk.Library(unit=1e-6, precision=1e-9)
cell = library.new_cell("straight_10um")
cell.add(gdstk.rectangle((0, -0.25), (10, 0.25), layer=1, datatype=0))

# Each port has its own datatype. The paths point out of the device.
for x, direction, name, datatype in [(0, -1, "opt1", 10), (10, 1, "opt2", 11)]:
    cell.add(gdstk.FlexPath(
        [(x - 0.1 * direction, 0), (x + 0.1 * direction, 0)],
        0.5, layer=1, datatype=datatype, simple_path=True,
    ))
    cell.add(gdstk.Label(name, (x, 0), layer=1, texttype=datatype))

output = Path(__file__).with_name("straight_10um.gds")
library.write_gds(output)
print(output)
