Example #1
0
def bench_gdstk(output=None):
    sp1 = gdstk.FlexPath([(0, 0), (3, 0), (3, 2), (5, 3), (3, 4), (0, 4)],
                         1,
                         gdsii_path=True,
                         datatype=1)
    sp1.interpolation([(0, 2), (2, 2), (4, 3), (5, 1)], relative=True)

    sp2 = gdstk.FlexPath(
        [(12, 0), (8, 0), (8, 3), (10, 2)],
        [0.3, 0.2, 0.4],
        0.5,
        ends=["extended", "flush", "round"],
        joins=["bevel", "miter", "round"],
        datatype=2,
    )
    sp2.arc(2, -0.5 * numpy.pi, 0.5 * numpy.pi)
    sp2.arc(1, 0.5 * numpy.pi, 1.5 * numpy.pi)

    points = [(0, 0), (0, 10), (20, 0), (18, 15), (8, 15)]
    sp3 = gdstk.FlexPath(points,
                         0.5,
                         bend_radius=5,
                         gdsii_path=True,
                         datatype=4)
    sp4 = gdstk.FlexPath(points, 0.5, gdsii_path=True, layer=1, datatype=5)
    if output:
        cell = gdstk.Cell("MAIN")
        cell.add(sp1, sp2, sp3, sp4)
        cell.write_svg(output, 30)
Example #2
0
def test_init():
    path = gdstk.FlexPath(0j, 2)
    assert path.layers == (0, )
    assert path.datatypes == (0, )
    assert path.num_paths == 1
    assert path.size == 1
    path.set_layers(1)
    path.set_datatypes(2)
    assert path.layers == (1, )
    assert path.datatypes == (2, )

    path = gdstk.FlexPath(0j, [2, 2], layer=3, datatype=[4, 5])
    assert path.layers == (3, 3)
    assert path.datatypes == (4, 5)
    assert path.num_paths == 2
    assert path.size == 1
    path.set_layers(5, 4)
    path.set_datatypes(3, 2)
    assert path.layers == (5, 4)
    assert path.datatypes == (3, 2)

    path = gdstk.FlexPath((0j, (1, 1)), 2, [-1, 1])
    assert path.layers == (0, 0)
    assert path.datatypes == (0, 0)
    assert path.num_paths == 2

    path = gdstk.FlexPath((1j, -1j), [2, 2], [-1, 1], layer=3, datatype=[4, 5])
    assert path.layers == (3, 3)
    assert path.datatypes == (4, 5)
    assert path.num_paths == 2
Example #3
0
def segment_image():
    points = [(1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1)]
    path_1 = gdstk.FlexPath((0, 0), 0.2)
    path_1.segment(points, 0.6)
    path_2 = gdstk.FlexPath((3, 0), [0.1, 0.1], 0.2)
    path_2.segment(points, offset=0.6, relative=True)
    return gdstk.Cell("segment").add(path_1, path_2)
Example #4
0
def mach_zehnder_interferometer(lib):
    cell = lib.new_cell("MZI")
    cell.add(gdstk.Reference("Directinal Coupler", (0, 0)))
    cell.add(gdstk.Reference("Directinal Coupler", (75, 0)))

    points = numpy.array([(5, 1), (25, 1), (25, 40), (55, 40), (55, 1),
                          (75, 1)])
    arm1 = gdstk.FlexPath(points,
                          0.5,
                          bend_radius=15,
                          gdsii_path=True,
                          layer=1)
    points[:, 1] *= -1
    arm2 = gdstk.FlexPath(points,
                          0.5,
                          bend_radius=15,
                          gdsii_path=True,
                          layer=1)
    points = numpy.array([(25, 20), (25, 40), (55, 40), (55, 20)])
    heater1 = gdstk.FlexPath(points,
                             2,
                             bend_radius=15,
                             gdsii_path=True,
                             layer=10)
    points[:, 1] *= -1
    heater2 = gdstk.FlexPath(points,
                             2,
                             bend_radius=15,
                             gdsii_path=True,
                             layer=10)
    cell.add(arm1, arm2, heater1, heater2)
Example #5
0
def interpolation_image():
    half_pi = numpy.pi / 2
    points = [(4, 1), (4, 3), (0, 5), (-4, 3), (-4, -2), (0, -4)]
    angles = [half_pi, None, None, None, -half_pi, -half_pi, None]
    path_1 = gdstk.FlexPath((0, 0), 0.2, tolerance=1e-3)
    path_1.interpolation(points, cycle=True)
    path_2 = gdstk.FlexPath((6, -8), 0.2, tolerance=1e-3)
    path_2.interpolation(points, angles, cycle=True, relative=True)
    return gdstk.Cell("interpolation").add(path_1, path_2)
Example #6
0
def bench_gdstk(output=None):
    def broken(p0, v0, p1, v1, p2, w):
        p0 = numpy.array(p0)
        v0 = numpy.array(v0)
        p1 = numpy.array(p1)
        v1 = numpy.array(v1)
        p2 = numpy.array(p2)
        den = v1[1] * v0[0] - v1[0] * v0[1]
        lim = 1e-12 * (v0[0] ** 2 + v0[1] ** 2) * (v1[0] ** 2 + v1[1] ** 2)
        if den ** 2 < lim:
            u0 = u1 = 0
            p = 0.5 * (p0 + p1)
        else:
            dx = p1[0] - p0[0]
            dy = p1[1] - p0[1]
            u0 = (v1[1] * dx - v1[0] * dy) / den
            u1 = (v0[1] * dx - v0[0] * dy) / den
            p = 0.5 * (p0 + v0 * u0 + p1 + v1 * u1)
        if u0 <= 0 and u1 >= 0:
            return [p]
        return [p0, p2, p1]

    def pointy(p0, v0, p1, v1):
        p0 = numpy.array(p0)
        v0 = numpy.array(v0)
        p1 = numpy.array(p1)
        v1 = numpy.array(v1)
        r = 0.5 * numpy.sqrt(numpy.sum((p0 - p1) ** 2))
        return [p0, 0.5 * (p0 + p1) + 0.5 * (v0 - v1) * r, p1]

    sp0 = gdstk.FlexPath(
        [(0, 0), (0, 1)],
        [0.1, 0.3, 0.5],
        offset=[-0.2, 0, 0.4],
        layer=[0, 1, 2],
        joins=broken,
        ends=pointy,
        datatype=3,
    )
    sp0.segment((3, 3), offset=[-0.5, -0.1, 0.5])
    sp0.segment((4, 1), width=[0.2, 0.2, 0.2], offset=[-0.2, 0, 0.2])
    sp0.segment((0, -1), relative=True)

    def spiral(u):
        r = 2 - u
        theta = 5 * u * numpy.pi
        return (r * numpy.cos(theta) - 2, r * numpy.sin(theta))

    sp1 = gdstk.FlexPath((2, 6), 0.2, layer=2)
    sp1.parametric(spiral)

    if output:
        cell = gdstk.Cell("MAIN")
        cell.add(sp0, sp1)
        cell.write_svg(output, 50)
Example #7
0
def test_init():
    path = gdstk.FlexPath(0j, 2)
    assert path.layers == (0,)
    assert path.datatypes == (0,)
    assert path.num_paths == 1
    assert path.size == 1
    assert path.tolerance == 1e-2
    assert path.simple_path == False
    assert path.scale_width == True
    assert path.joins == ("natural",)
    assert path.ends == ("flush",)
    assert path.bend_radius == (0,)
    assert path.bend_function == (None,)
    path.set_layers(1)
    path.set_datatypes(2)
    path.tolerance = 1e-3
    path.simple_path = True
    path.set_joins("round")
    path.set_ends((1, 2))
    path.set_bend_radius(0.1)
    path.set_bend_function(None)
    assert path.layers == (1,)
    assert path.datatypes == (2,)
    assert path.tolerance == 1e-3
    assert path.simple_path == True
    assert path.joins == ("round",)
    assert path.ends == ((1, 2),)
    assert path.bend_radius == (0.1,)
    assert path.bend_function == (None,)

    path = gdstk.FlexPath(0j, [2, 2], layer=3, datatype=[4, 5])
    assert path.layers == (3, 3)
    assert path.datatypes == (4, 5)
    assert path.num_paths == 2
    assert path.size == 1
    path.set_layers(5, 4)
    path.set_datatypes(3, 2)
    assert path.layers == (5, 4)
    assert path.datatypes == (3, 2)

    path = gdstk.FlexPath((0j, (1, 1)), 2, [-1, 1])
    assert path.layers == (0, 0)
    assert path.datatypes == (0, 0)
    assert path.num_paths == 2

    path = gdstk.FlexPath((1j, -1j), [2, 2], [-1, 1], layer=3, datatype=[4, 5])
    assert path.layers == (3, 3)
    assert path.datatypes == (4, 5)
    assert path.num_paths == 2
    assert path.bend_function == (None, None)
    dummy = lambda *args: (0j,)
    path.set_bend_function(dummy, None)
    assert path.bend_function == (dummy, None)
Example #8
0
def convex_hull_image():
    polygons = gdstk.text("F", 10, (0, 0))
    f_cell = gdstk.Cell("F_CELL")
    f_cell.add(*polygons)
    array_ref = gdstk.Reference(
        f_cell, rotation=numpy.pi / 4, columns=3, rows=2, spacing=(8, 10)
    )
    path = gdstk.FlexPath([(-5, 0), (0, -5), (5, 0)], 1, simple_path=True)
    main_cell = gdstk.Cell("MAIN")
    main_cell.add(array_ref, path)
    hull = main_cell.convex_hull()
    error = hull - numpy.array(
        [
            [1.14904852, 27.66555281],
            [-12.81631041, 13.70019389],
            [-5.35355339, -0.35355339],
            [0.0, -5.70710678],
            [5.35355339, -0.35355339],
            [11.3137085, 13.96535893],
            [9.98788328, 17.94283457],
            [8.66205807, 20.15254326],
        ]
    )
    assert numpy.abs(error).max() < 1e-8
    polygon_hull = gdstk.Polygon(hull, datatype=1)
    main_cell.name = "convex_hull"
    return main_cell.add(polygon_hull)
Example #9
0
def test_points():
    path = gdstk.FlexPath((0j, 10j), 2).horizontal(10, 2,
                                                   1).vertical(0, 1, [1])
    numpy.testing.assert_array_equal(path.spine(),
                                     [[0, 0], [0, 10], [10, 10], [10, 0]])
    numpy.testing.assert_array_equal(path.widths(), [[2], [2], [2], [1]])
    numpy.testing.assert_array_equal(path.offsets(), [[0], [0], [0], [1]])

    path = (gdstk.FlexPath((0j, 10j), [2, 2],
                           2).horizontal(10, 2, 1).vertical(0, 1, [-2, 1]))
    numpy.testing.assert_array_equal(path.spine(),
                                     [[0, 0], [0, 10], [10, 10], [10, 0]])
    numpy.testing.assert_array_equal(path.widths(),
                                     [[2, 2], [2, 2], [2, 2], [1, 1]])
    numpy.testing.assert_array_equal(path.offsets(),
                                     [[-1, 1], [-1, 1], [-0.5, 0.5], [-2, 1]])
Example #10
0
def test_copy_transform(proof_cells):
    ref_cell1 = gdstk.Cell("Reference 1")
    ref_cell1.add(*gdstk.text("F.", 10, (0, 0)))
    ref_cell1.add(gdstk.Label("LaBeL", (2.4, 8.7), "s"))
    ref_cell1.add(
        gdstk.FlexPath(8 + 4j, 1, simple_path=True,
                       layer=3).arc(2, 0, numpy.pi / 2))
    ref_cell1.add(
        gdstk.RobustPath(7.5 + 7j, 1, simple_path=True,
                         layer=4).bezier([-2 + 1j, -2 + 3j, 4j, 6j, -3 + 6j],
                                         relative=True))

    ref_cell2 = gdstk.Cell("Reference 2")
    ref_cell2.add(*gdstk.text("^", 10, (0, 5), layer=1))
    ref_cell2.add(gdstk.Reference(ref_cell1))

    cell = gdstk.Cell("Original cell")
    cell.add(gdstk.rectangle((-1, -0.5), (1, 0.5), layer=2))
    cell.add(gdstk.Reference(ref_cell2))
    cell.add(gdstk.Reference(ref_cell1, (10, 7), numpy.pi / 4, 0.5, True))
    cell.add(
        gdstk.Reference(ref_cell1, (-7, 15), -numpy.pi / 3, 0.5, True, 3, 2,
                        (5, 4)))
    cell.add(
        gdstk.Reference(ref_cell2, (-7, 23), numpy.pi / 3, 0.5, True, 3, 2,
                        (5, 8)))
    cell_copy = cell.copy("Cell.copy", (-10, -10), numpy.pi / 2, 2,
                          True).flatten()
    for path in cell_copy.paths:
        cell_copy.add(*path.to_polygons())
    assert_same_shape(proof_cells["Cell.copy"].polygons, cell_copy.polygons)
Example #11
0
def horizontal_image():
    path = gdstk.FlexPath((0, 0), 0.2)
    path.horizontal(2, width=0.4, relative=True)
    path.horizontal(2, offset=[0.4], relative=True)
    path.horizontal(2, relative=True)
    # print(path.spine())
    return gdstk.Cell("horizontal").add(path)
Example #12
0
def test_transforms(proof_cells):
    for scale_width in [True, False]:
        path0 = gdstk.FlexPath(
            (
                0j,
                1j,
                0.5 + 1j,
            ),
            [0.1, 0.2],
            0.3,
            tolerance=1e-4,
            scale_width=scale_width,
        )
        path0.turn(0.4, -numpy.pi, [0.2, 0.1]).segment((-0.2, 0),
                                                       relative=True)
        paths = [
            path0,
            path0.copy().mirror((1.5, 0)),
            path0.copy().mirror((1.5, 0), (1.5, 1)),
            path0.copy().scale(2, (3, 0)),
            path0.copy().scale(-2, (-1, 0)),
            path0.copy().rotate(numpy.pi / 2, (2, 1)).translate(0.2, -0.3),
        ]
        assert_same_shape(
            proof_cells[f"FlexPath: scale_width {scale_width}"].polygons,
            paths)
Example #13
0
def test_properties():
    for obj in [
            gdstk.Polygon([-1 + 0j, -2j, 3 + 0j, 4j]),
            gdstk.FlexPath((0j, 1j), 0.1),
            gdstk.RobustPath(0j, 0.1),
            gdstk.Label("Label", 0j),
            gdstk.Reference("EMPTY"),
            gdstk.Cell("CELL"),
            gdstk.Library("Name"),
    ]:
        assert len(obj.properties) == 0
        assert obj.get_property("None") is None
        obj.set_property("FIRST", 1)
        obj.set_property("SECOND", 2.0)
        obj.set_property("THIRD", -3)
        obj.set_property("FOURTH", [1, 2.0, -3, "FO", b"UR\x00TH\x00"])
        obj.set_property("FIRST", -1)
        assert obj.get_property("FIRST") == [-1]
        obj.delete_property("THIRD")
        assert obj.properties == [
            ["FIRST", -1],
            ["FOURTH", 1, 2.0, -3, b"FO", b"UR\x00TH\x00"],
            ["SECOND", 2.0],
            ["FIRST", 1],
        ]
        obj.properties = (
            ("ONE", -1),
            ("TWO", -2.3e-4, "two"),
            ("Three", b"\xFF\xEE", 0),
        )
        assert obj.properties == [
            ["ONE", -1],
            ["TWO", -2.3e-4, b"two"],
            ["Three", b"\xFF\xEE", 0],
        ]
Example #14
0
def test_filter():
    polys = [
        gdstk.rectangle((0, 0), (1, 1), layer=l, datatype=t)
        for t in range(3)
        for l in range(3)
    ]
    labels = [
        gdstk.Label("FILTER", (1, 1), layer=l, texttype=t)
        for t in range(3)
        for l in range(3)
    ]
    paths = [
        gdstk.FlexPath([0j, 1j], [0.1, 0.1, 0.1], 0.5, layer=[0, 1, 2], datatype=t)
        for t in range(3)
    ] + [
        gdstk.RobustPath(0j, [0.1, 0.1], 0.5, layer=[1, 2], datatype=t)
        for t in range(3)
    ]
    layers = [1, 2]
    types = [0]
    for op, test in [
        ("and", lambda a, b: a and b),
        ("or", lambda a, b: a or b),
        ("xor", lambda a, b: (a and not b) or (b and not a)),
        ("nand", lambda a, b: not (a and b)),
        ("nor", lambda a, b: not (a or b)),
        ("nxor", lambda a, b: not ((a and not b) or (b and not a))),
    ]:
        path_results = [
            [test(a in layers, b in types) for a, b in zip(path.layers, path.datatypes)]
            for path in paths
        ]
        cell = gdstk.Cell(op)
        cell.add(*polys, *labels, *paths)
        cell.filter(layers, types, op)

        cell_polys = cell.polygons
        for poly in polys:
            if test(poly.layer in layers, poly.datatype in types):
                assert poly not in cell_polys
            else:
                assert poly in cell_polys
        cell_labels = cell.labels
        for label in labels:
            if test(label.layer in layers, label.texttype in types):
                assert label not in cell_labels
            else:
                assert label in cell_labels
        cell_paths = cell.paths
        for path, results in zip(paths, path_results):
            if all(results):
                assert path not in cell_paths
            else:
                assert path in cell_paths
                assert len(path.layers) == len(results) - sum(results)
                assert all(
                    not test(a in layers, b in types)
                    for a, b in zip(path.layers, path.datatypes)
                )
Example #15
0
def boolean_image():
    circle = gdstk.ellipse((0, 0), 50)
    path = gdstk.FlexPath((-50, 30), [5, 5], 10)
    path.interpolation([(20, 15), (0, 0), (-20, -15), (50, -30)],
                       angles=[0.3, None, None, None, 0.3])
    text = gdstk.text("GDSTK", 40, (-2.5 * 40 * 9 / 16, -40 / 2))
    result = gdstk.boolean(circle, text + [path], "not")
    return gdstk.Cell("boolean").add(*result)
Example #16
0
def init_image():
    fpath = gdstk.FlexPath((0, 0), 0.5, tolerance=1e-3)
    fpath.arc(1, 0, numpy.pi / 2)
    fpath.arc(1, 0, -numpy.pi / 2)
    rpath = gdstk.RobustPath((3, 0), 0.5, tolerance=1e-3)
    rpath.arc(1, 0, numpy.pi / 2)
    rpath.arc(1, 0, -numpy.pi / 2)
    return gdstk.Cell("init").add(fpath, rpath)
Example #17
0
def parametric_image():
    def spiral(u):
        rad = 2 * u**0.5
        ang = 3 * numpy.pi * u
        return (rad * numpy.cos(ang), rad * numpy.sin(ang))

    path = gdstk.FlexPath((0, 0), 0.2, tolerance=1e-3)
    path.parametric(spiral)
    return gdstk.Cell("parametric").add(path)
Example #18
0
def offset_image():
    text = gdstk.text("#A", 10, (0, 0), datatype=1)
    circle = gdstk.ellipse(
        (5, 11), 5, initial_angle=0, final_angle=numpy.pi, datatype=1
    )
    path = gdstk.FlexPath([(0, -1), (5, -10), (10, -1)], 1, datatype=1)
    dilated = gdstk.offset(text + [circle, path], 0.4)
    eroded = gdstk.offset(text + [circle, path], -0.4, use_union=True, layer=1)
    return gdstk.Cell("offset").add(*text, circle, path, *dilated, *eroded)
Example #19
0
def init_image():
    path = gdstk.FlexPath(
        [(0, 5), (0, 0), (5, 0), (15, 10), (15, -5)],
        [0.8, 0.8, 0.8, 0.8],
        1.0,
        joins=["natural", "bevel", "miter", "round"],
        ends=["flush", "extended", (0.4, 0.8), "round"],
        layer=[0, 1, 2, 3],
    )
    return gdstk.Cell("init").add(path)
Example #20
0
def horizontal_image():
    path = gdstk.FlexPath((0, 0), 0.2)
    path.horizontal(2, width=0.4, relative=True)
    path.horizontal(2, offset=[0.4], relative=True)
    path.horizontal(2, relative=True)
    assert (numpy.max(
        numpy.abs(path.spine() -
                  numpy.array([[0.0, 0.0], [2.0, 0.0], [4.0, 0.0], [6.0, 0.0]])
                  )) == 0)
    return gdstk.Cell("horizontal").add(path)
Example #21
0
def bench_gdstk(output=None):
    c1 = gdstk.Cell("REF")
    c1.add(gdstk.rectangle((0, 0), (10, 10)))
    c1.add(
        gdstk.FlexPath([(0, 0), (10, 0), (10, 10), (0, 10)], [0.1, 0.1],
                       0.3,
                       layer=1))
    c1.add(gdstk.Label("Label", (5, 5), anchor='o'))
    c2 = gdstk.Cell("MAIN")
    c2.add(gdstk.Reference(c1, columns=3, rows=2, spacing=(20, 20)))
    c2.flatten()
    c1.remove(*c1.polygons, *c1.paths, *c1.labels)
    if output:
        c2.write_svg(output, 10)
Example #22
0
def bench_gdstk(output=None):
    p = gdstk.Polygon([(0, 0), (1, 0), (0, 1)])
    fp = gdstk.FlexPath([(0, 0), (1, 0), (0.5, -0.5)], 0.1, ends="round")
    c1 = gdstk.Cell("REF")
    c1.add(p, fp)
    r = gdstk.Reference(c1,
                        columns=3,
                        rows=2,
                        spacing=(2, 2),
                        rotation=30 * numpy.pi / 180)
    c2 = gdstk.Cell("MAIN")
    c2.add(r)
    bb = c2.bounding_box()
    if output:
        c2.add(gdstk.rectangle(*bb, layer=1))
        c2.write_svg(output, 100)
Example #23
0
def bounding_box_image():
    polygons = gdstk.text("F", 10, (0, 0))
    f_cell = gdstk.Cell("F_CELL")
    f_cell.add(*polygons)
    array_ref = gdstk.Reference(f_cell,
                                rotation=numpy.pi / 4,
                                columns=3,
                                rows=2,
                                spacing=(8, 10))
    path = gdstk.FlexPath([(-5, 0), (0, -5), (5, 0)], 1, gdsii_path=True)
    main_cell = gdstk.Cell("MAIN")
    main_cell.add(array_ref, path)
    bbox = main_cell.bounding_box()
    # print(bbox)
    polygon_bb = gdstk.rectangle(*bbox, datatype=1)
    main_cell.name = "bounding_box"
    return main_cell.add(polygon_bb)
Example #24
0
def commands_image():
    path = gdstk.FlexPath((0, 0), [0.2, 0.4, 0.2], 0.5, tolerance=1e-3)
    path.commands(
        "l",
        3,
        4,
        "A",
        2,
        numpy.arctan2(3, -4),
        numpy.pi / 2,
        "h",
        0.5,
        "a",
        3,
        -numpy.pi,
    )
    return gdstk.Cell("commands").add(path)
Example #25
0
def test_bb_flexpath_repetition():
    pth = gdstk.FlexPath([0.5 + 0j, 0.5 + 1j], 1)
    pth.repetition = gdstk.Repetition(x_offsets=(1, 3, -2))
    c_pth = gdstk.Cell("E")
    c_pth.add(pth)
    assert_close(c_pth.bounding_box(), ((-2, 0), (4, 1)))
    ref = gdstk.Reference(c_pth)
    ref.repetition = gdstk.Repetition(y_offsets=(-1, 2, -4))
    c_ref = gdstk.Cell("F")
    c_ref.add(ref)
    assert_close(c_ref.bounding_box(), ((-2, -4), (4, 3)))
    ref.rotation = numpy.pi / 4
    a = (-2 + 1j) * numpy.exp(0.25j * numpy.pi)
    b = (-2 + 0j) * numpy.exp(0.25j * numpy.pi)
    c = (4 + 0j) * numpy.exp(0.25j * numpy.pi)
    d = (4 + 1j) * numpy.exp(0.25j * numpy.pi)
    assert_close(c_ref.bounding_box(),
                 ((a.real, b.imag - 4), (c.real, d.imag + 2)))
Example #26
0
def test_properties():
    for obj in [
        gdstk.Polygon([-1 + 0j, -2j, 3 + 0j, 4j]),
        gdstk.FlexPath((0j, 1j), 0.1),
        gdstk.RobustPath(0j, 0.1),
        gdstk.Label("Label", 0j),
        gdstk.Reference("EMPTY"),
    ]:
        assert obj.get_property(12) is None
        assert obj.delete_property(12) is obj
        obj.set_property(13, "Property text")
        assert obj.get_property(12) is None
        assert obj.get_property(13) == "Property text"
        obj.delete_property(13)
        assert obj.get_property(13) is None
        obj.set_property(13, "Second text")
        obj.set_property(13, "Third text")
        assert obj.get_property(13) == "Third text"
Example #27
0
def bounding_box_image():
    polygons = gdstk.text("F", 10, (0, 0))
    f_cell = gdstk.Cell("F_CELL")
    f_cell.add(*polygons)
    array_ref = gdstk.Reference(
        f_cell, rotation=numpy.pi / 4, columns=3, rows=2, spacing=(8, 10)
    )
    path = gdstk.FlexPath([(-5, 0), (0, -5), (5, 0)], 1, simple_path=True)
    main_cell = gdstk.Cell("MAIN")
    main_cell.add(array_ref, path)
    bbox = main_cell.bounding_box()
    assert bbox == (
        (-12.816310409006173, -5.707106781186548),
        (11.313708498984761, 27.66555281392367),
    )
    polygon_bb = gdstk.rectangle(*bbox, datatype=1)
    main_cell.name = "bounding_box"
    return main_cell.add(polygon_bb)
Example #28
0
def init1_image():
    def custom_broken_join(p0, v0, p1, v1, center, width):
        p0 = numpy.array(p0)
        v0 = numpy.array(v0)
        p1 = numpy.array(p1)
        v1 = numpy.array(v1)
        center = numpy.array(center)
        # Calculate intersection point p between lines defined by
        # p0 + u0 * v0 (for all u0) and p1 + u1 * v1 (for all u1)
        den = v1[1] * v0[0] - v1[0] * v0[1]
        lim = 1e-12 * (v0[0]**2 + v0[1]**2) * (v1[0]**2 + v1[1]**2)
        if den**2 < lim:
            # Lines are parallel: use mid-point
            u0 = u1 = 0
            p = 0.5 * (p0 + p1)
        else:
            dx = p1[0] - p0[0]
            dy = p1[1] - p0[1]
            u0 = (v1[1] * dx - v1[0] * dy) / den
            u1 = (v0[1] * dx - v0[0] * dy) / den
            p = 0.5 * (p0 + v0 * u0 + p1 + v1 * u1)
        if u0 <= 0 and u1 >= 0:
            # Inner corner
            return [p]
        # Outer corner
        return [p0, center, p1]

    def custom_pointy_end(p0, v0, p1, v1):
        p0 = numpy.array(p0)
        v0 = numpy.array(v0)
        p1 = numpy.array(p1)
        v1 = numpy.array(v1)
        r = 0.5 * numpy.sqrt(numpy.sum((p0 - p1)**2))
        v0 /= numpy.sqrt(numpy.sum(v0**2))
        v1 /= numpy.sqrt(numpy.sum(v1**2))
        return [p0, 0.5 * (p0 + p1) + 0.5 * (v0 - v1) * r, p1]

    path = gdstk.FlexPath(
        [(0, 5), (0, 0), (5, 0), (15, 10), (15, -5)],
        3,
        joins=custom_broken_join,
        ends=custom_pointy_end,
    )
    return gdstk.Cell("init1").add(path)
Example #29
0
def test_get_paths(tree):
    c3, c2, c1 = tree
    c1.add(
        gdstk.FlexPath([(0, 0), (1, 1)], [0.1, 0.1],
                       layer=[0, 1],
                       datatype=[2, 3]))
    c2.add(gdstk.RobustPath((0, 0), [0.1, 0.1], layer=[0, 1], datatype=[2, 3]))
    paths = c3.get_paths()
    assert len(paths) == 12
    assert paths[0].num_paths == 2
    assert all(p is not None for p in paths)
    paths = c3.get_paths(depth=1)
    assert len(paths) == 6
    assert paths[0].num_paths == 2
    assert all(p is not None for p in paths)
    paths = c3.get_paths(depth=1, layer=1, datatype=3)
    assert len(paths) == 6
    assert paths[0].num_paths == 1
    assert all(p is not None for p in paths)
Example #30
0
def bench_gdstk(output=None):
    p = gdstk.Polygon([(0, 0), (1, 0), (0, 1)])
    fp = gdstk.FlexPath([(-1, 0.5), (1, 0), (0.5, -0.5)], [0.1, 0.1], 0.3, ends="round")
    rp = gdstk.RobustPath((0, 0), [0.1, 0.1], 0.3).interpolation(
        [(2, 0.5), (2, 1), (-1, 4)]
    )
    c1 = gdstk.Cell("REF")
    c1.add(p, fp, rp)
    r1 = gdstk.Reference(
        c1, columns=3, rows=2, spacing=(2, 2), rotation=30 * numpy.pi / 180
    )
    r2 = gdstk.Reference(c1, origin=(8, 0), columns=5, rows=4, spacing=(2, 2))
    r3 = gdstk.Reference(c1, origin=(9, 1), columns=4, rows=3, spacing=(2, 2))
    c2 = gdstk.Cell("MAIN")
    c2.add(r1, r2, r3)
    bb = c2.bounding_box()
    if output:
        c2.add(gdstk.rectangle(*bb, layer=1))
        c2.write_svg(output, 100)