コード例 #1
0
def test_robustpath_warnings():
    with pytest.warns(UserWarning):
        gdspy.RobustPath((0, 0), 1, ends="smooth", gdsii_path=True)
    with pytest.warns(UserWarning):
        gdspy.RobustPath((0, 0), [1, 1],
                         ends=["flush", "smooth"],
                         gdsii_path=True)
コード例 #2
0
def test_robustpath1(target):
    cell = gdspy.Cell("test")
    rp = gdspy.RobustPath((0, 0), 0.1, layer=[1], gdsii_path=True)
    rp.segment((1, 1))
    cell.add(rp)
    rp = gdspy.RobustPath(
        (1, 0),
        0.1,
        [-0.1, 0.1],
        tolerance=1e-5,
        ends=["round", "extended"],
        layer=[2, 3],
        max_points=6,
    )
    rp.segment((2, 1))
    cell.add(rp)
    rp = gdspy.RobustPath((2, 0), [0.1, 0.2],
                          0.2,
                          ends=(0.2, 0.1),
                          layer=4,
                          datatype=[1, 1])
    rp.segment((3, 1))
    cell.add(rp)
    rp = gdspy.RobustPath(
        (3, 0),
        [0.1, 0.2, 0.1],
        [-0.2, 0, 0.2],
        ends=[(0.2, 0.1), "smooth", "flush"],
        datatype=5,
    )
    rp.segment((4, 1))
    cell.add(rp)
    assertsame(target["RobustPath1"], cell)
コード例 #3
0
def test_robustpath1(target):
    cell = gdspy.Cell('test', True)
    rp = gdspy.RobustPath((0, 0), 0.1, layer=[1], gdsii_path=True)
    rp.segment((1, 1))
    cell.add(rp)
    rp = gdspy.RobustPath((1, 0),
                          0.1, [-0.1, 0.1],
                          tolerance=1e-5,
                          ends=['round', 'extended'],
                          layer=[2, 3],
                          max_points=6)
    rp.segment((2, 1))
    cell.add(rp)
    rp = gdspy.RobustPath((2, 0), [0.1, 0.2],
                          0.2,
                          ends=(0.2, 0.1),
                          layer=4,
                          datatype=[1, 1])
    rp.segment((3, 1))
    cell.add(rp)
    rp = gdspy.RobustPath((3, 0), [0.1, 0.2, 0.1], [-0.2, 0, 0.2],
                          ends=[(0.2, 0.1), 'smooth', 'flush'],
                          datatype=5)
    rp.segment((4, 1))
    cell.add(rp)
    assertsame(target['RobustPath1'], cell)
コード例 #4
0
def test_robustpath_togds(tmpdir):
    cell = gdspy.Cell('robustpath')
    rp = gdspy.RobustPath((0, 0), 0.1, layer=[1])
    rp.segment((1, 1))
    rp.segment((2, 3), 0)
    cell.add(rp)
    rp = gdspy.RobustPath((2, 0), [0.1, 0.2],
                          0.2,
                          ends=['round', (0.2, 0.1)],
                          layer=4,
                          datatype=[1, 1],
                          gdsii_path=True)
    rp.segment((3, 1))
    cell.add(rp)
    rp = gdspy.RobustPath((0, 0),
                          0.1,
                          layer=5,
                          tolerance=1e-5,
                          max_points=0,
                          max_evals=1e6,
                          gdsii_path=True)
    rp.segment((10, 0))
    rp.turn(20, 'll')
    rp.turn(20, 'rr')
    rp.turn(20, 'll')
    cell.add(rp)
    fname = str(tmpdir.join('test.gds'))
    with pytest.warns(UserWarning):
        gdspy.write_gds(fname, unit=1, precision=1e-7)
    lib = gdspy.GdsLibrary(infile=fname, rename={'robustpath': 'file'})
    assertsame(lib.cell_dict['file'], cell, tolerance=1e-3)
    gdspy.current_library = gdspy.GdsLibrary()
コード例 #5
0
def test_robustpath_warnings():
    with pytest.warns(UserWarning):
        gdspy.RobustPath((0, 0), 1, ends='smooth', gdsii_path=True)
    with pytest.warns(UserWarning):
        gdspy.RobustPath((0, 0), [1, 1],
                         ends=['flush', 'smooth'],
                         gdsii_path=True)
コード例 #6
0
def test_robustpath_transform(target):
    rp = gdspy.FlexPath([(0, 0)], [2, 1, 1], 5)
    rp.segment((15, 20))
    rp.scale(0.7)
    rp.turn(10, "r")
    rp.transform((10, 0), -1.5, 1.5, x_reflection=True)
    rp.segment((10, -10), relative=True)
    rp.rotate(-0.7)
    rp.translate(50, 30)
    rp.segment((-10, 0))
    assertsame(target["RobustPath4"], gdspy.Cell("FP5").add(rp))

    rp = gdspy.RobustPath((0, 0), [2, 1, 1], 5)
    rp.segment((15, 20))
    rp.turn(10, "r")
    rp.segment((10, -10), relative=True)
    poly = rp.to_polygonset()
    rp.rotate(-0.7)
    rp.scale(0.7)
    rp.translate(50, 30)
    rp.transform((10, 0), numpy.pi / 4, 1.5, True)
    poly.rotate(-0.7)
    poly.scale(0.7)
    poly.translate(50, 30)
    c0 = gdspy.Cell("POLY")
    c0.add(poly)
    ref = gdspy.CellReference(c0, (10, 0), 45, 1.5, True)
    assertsame(gdspy.Cell("RP").add(rp),
               gdspy.Cell("REF").add(ref),
               tolerance=1e-2)
コード例 #7
0
ファイル: robustpath.py プロジェクト: wshanks/gdstk
def bench_gdspy(output=None):
    rp = gdspy.RobustPath(
        (50, 0),
        [2, 0.5, 1, 1],
        [0, 0, -1, 1],
        ends=["extended", "round", "flush", "flush"],
        layer=[0, 2, 1, 1],
        datatype=[0, 1, 2, 3],
        max_points=8190,
    )
    rp.segment((45, 0))
    rp.segment(
        (5, 0),
        width=[lambda u: 2 + 16 * u * (1 - u), 0.5, 1, 1],
        offset=[
            0,
            lambda u: 8 * u * (1 - u) * numpy.cos(12 * numpy.pi * u),
            lambda u: -1 - 8 * u * (1 - u),
            lambda u: 1 + 8 * u * (1 - u),
        ],
    )
    rp.segment((0, 0))
    rp.smooth(
        [(5, 10)],
        angles=[0.5 * numpy.pi, 0],
        width=0.5,
        offset=[-0.25, 0.25, -0.75, 0.75],
    )
    rp.bezier([(0, 10), (10, 10), (10, -10), (20, -10), (20, 0), (30, 0)])
    if output:
        cell = gdspy.Cell("MAIN", exclude_from_current=True)
        cell.add(rp)
        cell.write_svg(output, 10)
コード例 #8
0
def test_robustpath_width():
    rp = gdspy.RobustPath((0, 0), [0.1, 0.3])
    rp.segment((1, 0), 0.3)
    rp.segment((1, 1), [0.1, 0.2])
    assert numpy.sum((numpy.array((0.1, 0.3)) - rp.width(0))**2) < 1e-12
    assert numpy.sum((numpy.array((0.2, 0.3)) - rp.width(0.5))**2) < 1e-12
    assert numpy.sum((numpy.array((0.3, 0.3)) - rp.width(1))**2) < 1e-12
    assert numpy.sum((numpy.array((0.2, 0.25)) - rp.width(1.5))**2) < 1e-12
    assert numpy.sum((numpy.array((0.1, 0.2)) - rp.width(2))**2) < 1e-12
コード例 #9
0
def test_robustpath_getpolygons():
    rp = gdspy.RobustPath((0, 0),
                          0.05, [-0.1, 0.1],
                          ends=['extended', (0.1, 0.2)],
                          layer=[0, 1],
                          datatype=[1, 0])
    rp.segment((1, 1))
    rp.parametric(lambda u: numpy.array((u, u - u**2)))
    d = rp.get_polygons(True)
    l = rp.get_polygons()
    assert len(d) == 2
    assert (1, 0) in d
    assert (0, 1) in d
    assert sum(len(p) for p in d.values()) == len(l)
    assert sum(sum(len(x) for x in p)
               for p in d.values()) == sum(len(x) for x in l)
    ps = rp.to_polygonset()
    assert len(ps.layers) == len(ps.datatypes) == len(ps.polygons)
    assert gdspy.RobustPath((0, 0), 1).to_polygonset() == None
コード例 #10
0
def test_robustpath_grad():
    rp = gdspy.RobustPath((0, 0), 0.1)
    rp.segment((1, 0), 0.3)
    rp.segment((1, 1), 0.1)
    assert numpy.sum((numpy.array((1, 0)) - rp.grad(0))**2) < 1e-12
    assert numpy.sum((numpy.array((1, 0)) - rp.grad(1))**2) < 1e-12
    assert numpy.sum((numpy.array((0, 1)) - rp.grad(1, side="+"))**2) < 1e-12
    assert numpy.sum((numpy.array((0, 1)) - rp.grad(2))**2) < 1e-12
    assert numpy.sum((numpy.array((0.1, 1)) - rp.grad(2, arm=-1))**2) < 1e-12
    assert numpy.sum((numpy.array((-0.1, 1)) - rp.grad(2, arm=1))**2) < 1e-12
コード例 #11
0
def test_robustpath3(target):
    cell = gdspy.Cell('test', True)
    rp = gdspy.RobustPath((0, 0), 0.1)
    rp.parametric(lambda u: numpy.array(
        (3 * numpy.sin(numpy.pi * u), -3 * numpy.cos(numpy.pi * u))),
                  relative=False)
    rp.parametric(lambda u: numpy.array((3.5 - 3 * numpy.cos(numpy.pi * u),
                                         -0.5 + 3 * numpy.sin(numpy.pi * u))),
                  lambda u: numpy.array(
                      (numpy.sin(numpy.pi * u), numpy.cos(numpy.pi * u))),
                  relative=True)
    cell.add(rp)
    assertsame(target['RobustPath3'], cell)
コード例 #12
0
def test_robustpath_gdsiipath():
    cells = []
    for gdsii_path in [True, False]:
        cells.append(gdspy.Cell(str(gdsii_path), True))
        rp = gdspy.RobustPath((0, 0),
                              0.05, [-0.1, 0.1],
                              ends=['extended', (0.1, 0.2)],
                              layer=[0, 1],
                              gdsii_path=gdsii_path)
        rp.segment((1, 1))
        rp.parametric(lambda u: numpy.array((u, u - u**2)))
        cells[-1].add(rp)
    assertsame(*cells)
コード例 #13
0
def test_robustpath_len():
    rp = gdspy.RobustPath((0, 0), [0.1, 0.2, 0.1], 0.15, layer=[1, 2, 3])
    assert len(rp) == 0
    rp.segment((1, 0))
    rp.segment((1, 1), 0.1, 0.05)
    rp.segment((1, 1), [0.2, 0.1, 0.1], -0.05, True)
    rp.segment((-1, 1), 0.2, [-0.2, 0, 0.3], True)
    rp.arc(2, 0, 0.5 * numpy.pi)
    rp.arc(3, 0.7 * numpy.pi, numpy.pi, 0.1, 0)
    rp.arc(2, 0.4 * numpy.pi, -0.4 * numpy.pi, [0.1, 0.2, 0.1], [0.2, 0, -0.2])
    rp.turn(1, -0.3 * numpy.pi)
    rp.turn(1, "rr", 0.15)
    rp.turn(0.5, "l", [0.05, 0.1, 0.05], [0.15, 0, -0.15])
    assert len(rp) == 10
コード例 #14
0
def test_robustpath_togds(tmpdir):
    cell = gdspy.Cell("robustpath")
    rp = gdspy.RobustPath((0, 0), 0.1, layer=[1])
    rp.segment((1, 1))
    rp.segment((2, 3), 0)
    cell.add(rp)

    rp = gdspy.RobustPath(
        (2, 0),
        [0.1, 0.2],
        0.2,
        ends=["round", (0.2, 0.1)],
        layer=4,
        datatype=[1, 1],
        gdsii_path=True,
    )
    rp.segment((3, -1))
    cell.add(rp)

    rp = gdspy.RobustPath(
        (0, 0),
        0.1,
        layer=5,
        tolerance=1e-5,
        max_points=0,
        max_evals=1e6,
        gdsii_path=True,
    )
    rp.segment((1, 0))
    rp.turn(2, "ll")
    rp.turn(1, "rr")
    rp.turn(2, "l")
    cell.add(rp)
    fname = str(tmpdir.join("test.gds"))
    gdspy.GdsLibrary(unit=1, precision=1e-7).add(cell).write_gds(fname)
    lib = gdspy.GdsLibrary(infile=fname, rename={"robustpath": "file"})
    assertsame(lib.cells["file"], cell, tolerance=1e-3)
コード例 #15
0
def bench_gdspy(output=None):
    p = gdspy.Polygon([(0, 0), (1, 0), (0, 1)])
    fp = gdspy.FlexPath([(-1, 0.5), (1, 0), (0.5, -0.5)], [0.1, 0.1], 0.3, ends="round")
    rp = gdspy.RobustPath((0, 0), [0.1, 0.1], 0.3).smooth(
        [(2, 0.5), (2, 1), (-1, 4)]
    )
    c1 = gdspy.Cell("REF", exclude_from_current=True)
    c1.add([p, fp, rp])
    r1 = gdspy.CellArray(c1, columns=3, rows=2, spacing=(2, 2), rotation=30)
    r2 = gdspy.CellArray(c1, origin=(8, 0), columns=5, rows=4, spacing=(2, 2))
    r3 = gdspy.CellArray(c1, origin=(9, 1), columns=4, rows=3, spacing=(2, 2))
    c2 = gdspy.Cell("MAIN", exclude_from_current=True)
    c2.add([r1, r2, r3])
    bb = c2.get_bounding_box()
    if output:
        c2.add(gdspy.Rectangle(*bb, layer=1))
        c2.write_svg(output, 100)
コード例 #16
0
def test_robustpath_call():
    rp = gdspy.RobustPath((0, 0), [0.1, 0.2, 0.1], 0.15, layer=[1, 2, 3])
    rp.segment((1, 0))
    rp.turn(5, "ll")
    rp.segment((-1, 0), relative=True)
    assert (numpy.sum((rp(0) - numpy.array([(0, 0.15), (0, 0),
                                            (0, -0.15)]))**2) < 1e-12)
    assert (numpy.sum((rp(0.5) - numpy.array([(0.5, 0.15), (0.5, 0),
                                              (0.5, -0.15)]))**2) < 1e-12)
    assert (numpy.sum((rp(1) - numpy.array([(1, 0.15), (1, 0),
                                            (1, -0.15)]))**2) < 1e-12)
    assert (numpy.sum((rp(1.5, arm=1) - numpy.array([(5.9, 5), (6.1, 5),
                                                     (6.2, 5)]))**2) < 1e-12)
    assert (numpy.sum((rp(1.5, arm=-1) - numpy.array([(5.8, 5), (5.9, 5),
                                                      (6.1, 5)]))**2) < 1e-12)
    assert (numpy.sum((rp(2) - numpy.array([(1, 9.85), (1, 10),
                                            (1, 10.15)]))**2) < 1e-12)
    assert (numpy.sum((rp(3) - numpy.array([(0, 9.85), (0, 10),
                                            (0, 10.15)]))**2) < 1e-12)
コード例 #17
0
ファイル: gdslibrary.py プロジェクト: tvt173/gdspy
def test_properties(tmpdir):
    lib = gdspy.GdsLibrary()
    c1 = lib.new_cell("POLY")
    rect = gdspy.Rectangle((0, 0), (2, 1))
    rect.properties[1] = "test1"
    rect.properties[126] = "test_126"
    lbl = gdspy.Label("LABEL", (20, 20))
    lbl.properties[2] = "test2"
    lbl.properties[22] = "test22"
    c1.add((rect, lbl))
    c2 = lib.new_cell("REF")
    ref = gdspy.CellReference(c1, (0, 0))
    ref.properties[6] = "test6"
    ref.properties[121] = "test_121"
    c2.add(ref)
    c3 = lib.new_cell("AREF")
    aref = gdspy.CellArray(c1, 1, 2, (30, 40), (0, 0))
    aref.properties[4] = "test4"
    aref.properties[123] = "test_123"
    c3.add(aref)
    c4 = lib.new_cell("FP")
    fp = gdspy.FlexPath([(0, 0), (0, 1), (1, 1)], 0.01, gdsii_path=True)
    fp.properties[2] = "test2"
    fp.properties[125] = "test_125"
    c4.add(fp)
    c5 = lib.new_cell("RP")
    rp = gdspy.RobustPath((0, 0), [0.01, 0.01], 0.5, gdsii_path=True).segment(
        (1, 1))
    rp.properties[3] = "test3"
    rp.properties[124] = "test_124"
    c5.add(rp)
    fname = str(tmpdir.join("test_properties.gds"))
    lib.write_gds(fname)
    lib1 = gdspy.GdsLibrary(infile=fname)
    assert rect.properties == lib1.cells["POLY"].polygons[0].properties
    assert lbl.properties == lib1.cells["POLY"].labels[0].properties
    assert ref.properties == lib1.cells["REF"].references[0].properties
    assert aref.properties == lib1.cells["AREF"].references[0].properties
    assert fp.properties == lib1.cells["FP"].paths[0].properties
    assert rp.properties == lib1.cells["RP"].paths[0].properties
    assert rp.properties == lib1.cells["RP"].paths[1].properties
コード例 #18
0
ファイル: run.py プロジェクト: nescirem/gdstk
def memory_benchmark():
    proc = psutil.Process()
    total = 100000
    print(f"\nMemory usage per object for {total} objects:\n")

    def print_row(*vals, hsep=False):
        columns = [20, 16, 16, 9]
        print(
            "|",
            vals[0].ljust(columns[0]),
            "|",
            " | ".join(v.center(c) for v, c in zip(vals[1:], columns[1:])),
            "|",
        )
        if hsep:
            print(
                "|",
                ":" + "-" * (columns[0] - 1),
                "|",
                " | ".join(":" + "-" * (c - 2) + ":" for c in columns[1:]),
                "|",
            )

    print_row(
        "Object",
        "Gdspy " + gdspy.__version__,
        "Gdstk " + gdstk.__version__,
        "Reduction",
        hsep=True,
    )

    def mem_test(func):
        start_mem = proc.memory_info()
        r = [func(i) for i in range(total)]
        end_mem = proc.memory_info()
        return (end_mem.vms - start_mem.vms) / total, r

    data = []
    gdspy_cell = gdspy.Cell("TEMP", exclude_from_current=True)
    gdstk_cell = gdstk.Cell("TEMP")
    for obj, gdspy_func, gdstk_func in [
        (
            "Rectangle",
            lambda i: gdspy.Rectangle((i, i), (i + 1, i + 1)),
            lambda i: gdstk.rectangle((i, i), (i + 1, i + 1)),
        ),
        (
            "Circle (r = 10)",
            lambda i: gdspy.Round((0, 10 * i), 10),
            lambda i: gdstk.ellipse((0, 10 * i), 10),
        ),
        (
            "FlexPath segment",
            lambda i: gdspy.FlexPath([(i, i + 1), (i + 1, i)], 0.1),
            lambda i: gdstk.FlexPath([(i, i + 1), (i + 1, i)], 0.1),
        ),
        (
            "FlexPath arc",
            lambda i: gdspy.FlexPath([(10 * i, 0)], 0.1).arc(10, 0, numpy.pi),
            lambda i: gdstk.FlexPath([(10 * i, 0)], 0.1).arc(10, 0, numpy.pi),
        ),
        (
            "RobustPath segment",
            lambda i: gdspy.RobustPath((i, i + 1), 0.1).segment((i + 1, i)),
            lambda i: gdstk.RobustPath((i, i + 1), 0.1).segment((i + 1, i)),
        ),
        (
            "RobustPath arc",
            lambda i: gdspy.RobustPath((10 * i, 0), 0.1).arc(10, 0, numpy.pi),
            lambda i: gdstk.RobustPath((10 * i, 0), 0.1).arc(10, 0, numpy.pi),
        ),
        (
            "Label",
            lambda i: gdspy.Label(str(i), (i, i)),
            lambda i: gdstk.Label(str(i), (i, i)),
        ),
        (
            "Reference",
            lambda i: gdspy.CellReference(gdspy_cell, (0, 0)),
            lambda i: gdstk.Reference(gdstk_cell, (0, 0)),
        ),
        (
            "Reference (array)",
            lambda i: gdspy.CellArray(gdspy_cell, (0, 0), 1, 1, (0, 0)),
            lambda i: gdstk.Reference(gdstk_cell, (0, 0), rows=1, columns=1),
        ),
        (
            "Cell",
            lambda i: gdspy.Cell(str(i), exclude_from_current=True),
            lambda i: gdstk.Cell(str(i)),
        ),
    ]:
        gdspy_mem, gdspy_data = mem_test(gdspy_func)
        data.append(gdspy_data)
        gdstk_mem, gdstk_data = mem_test(gdstk_func)
        data.append(gdstk_data)
        print_row(
            obj,
            prefix_format(gdspy_mem, unit="B", base="bin"),
            prefix_format(gdstk_mem, unit="B", base="bin"),
            f"{100 - 100 * gdstk_mem / gdspy_mem:.0f}%",
        )
コード例 #19
0
    sp4 = gdspy.FlexPath(points,
                         0.5,
                         corners="circular bend",
                         bend_radius=5,
                         gdsii_path=True)

    # Same path, generated with natural corners, for comparison
    sp5 = gdspy.FlexPath(points, 0.5, layer=1, gdsii_path=True)
    draw(gdspy.Cell("flexible_paths_2").add([sp4, sp5]))

    # Robust Paths
    # Create 4 parallel paths in different layers
    lp = gdspy.RobustPath(
        (50, 0),
        [2, 0.5, 1, 1],
        [0, 0, -1, 1],
        ends=["extended", "round", "flush", "flush"],
        layer=[0, 2, 1, 1],
    )
    lp.segment((45, 0))
    lp.segment(
        (5, 0),
        width=[lambda u: 2 + 16 * u * (1 - u), 0.5, 1, 1],
        offset=[
            0,
            lambda u: 8 * u * (1 - u) * numpy.cos(12 * numpy.pi * u),
            lambda u: -1 - 8 * u * (1 - u),
            lambda u: 1 + 8 * u * (1 - u),
        ],
    )
    lp.segment((0, 0))
コード例 #20
0
fp.segment((15, 20))
fp.scale(0.7)
fp.turn(10, "r")
fp.transform((10, 0), -1.5, 1.5, x_reflection=True)
fp.segment((10, -10), relative=True)
fp.rotate(-0.7)
fp.translate(50, 30)
fp.segment((-10, 0))

cell.add(fp)

### RobustPath

cell = lib.new_cell("RobustPath1")

rp = gdspy.RobustPath((0, 0), 0.1, layer=[1], gdsii_path=True)
rp.segment((1, 1))
cell.add(rp)
rp = gdspy.RobustPath(
    (1, 0),
    0.1,
    [-0.1, 0.1],
    tolerance=1e-5,
    ends=["round", "extended"],
    layer=[2, 3],
    max_points=6,
)
rp.segment((2, 1))
cell.add(rp)
rp = gdspy.RobustPath((2, 0), [0.1, 0.2],
                      0.2,
コード例 #21
0
ファイル: makeimages.py プロジェクト: zlatko-minev/gdspy
    # Path created with automatic bends of radius 5
    points = [(0, 0), (0, 10), (20, 0), (18, 15), (8, 15)]
    sp4 = gdspy.FlexPath(points,
                         0.5,
                         corners='circular bend',
                         bend_radius=5,
                         gdsii_path=True)

    # Same path, generated with natural corners, for comparison
    sp5 = gdspy.FlexPath(points, 0.5, layer=1, gdsii_path=True)
    draw(gdspy.Cell('flexible_paths_2').add([sp4, sp5]))

    # Robust Paths
    # Create 4 parallel paths in different layers
    lp = gdspy.RobustPath((50, 0), [2, 0.5, 1, 1], [0, 0, -1, 1],
                          ends=['extended', 'round', 'flush', 'flush'],
                          layer=[0, 2, 1, 1])
    lp.segment((45, 0))
    lp.segment(
        (5, 0),
        width=[lambda u: 2 + 16 * u * (1 - u), 0.5, 1, 1],
        offset=[
            0, lambda u: 8 * u * (1 - u) * numpy.cos(12 * numpy.pi * u),
            lambda u: -1 - 8 * u * (1 - u), lambda u: 1 + 8 * u * (1 - u)
        ])
    lp.segment((0, 0))
    lp.smooth([(5, 10)],
              angles=[0.5 * numpy.pi, 0],
              width=0.5,
              offset=[-0.25, 0.25, -0.75, 0.75])
    lp.parametric(lambda u: numpy.array(
コード例 #22
0
def test_robustpath2(target):
    cell = gdspy.Cell("test")
    rp = gdspy.RobustPath((0, 0), [0.1, 0.2, 0.1], 0.15, layer=[1, 2, 3])
    assert len(rp) == 0
    rp.segment((1, 0))
    rp.segment((1, 1), 0.1, 0.05)
    rp.segment((1, 1), [0.2, 0.1, 0.1], -0.05, True)
    rp.segment((-1, 1), 0.2, [-0.2, 0, 0.3], True)
    rp.arc(2, 0, 0.5 * numpy.pi)
    rp.arc(3, 0.7 * numpy.pi, numpy.pi, 0.1, 0)
    rp.arc(2, 0.4 * numpy.pi, -0.4 * numpy.pi, [0.1, 0.2, 0.1], [0.2, 0, -0.2])
    rp.turn(1, -0.3 * numpy.pi)
    rp.turn(1, "rr", 0.15)
    rp.turn(0.5, "l", [0.05, 0.1, 0.05], [0.15, 0, -0.15])
    assert len(rp) == 10
    cell.add(rp)
    rp = gdspy.RobustPath((-5, 6), 0.8, layer=20, ends="round", tolerance=1e-4)
    rp.segment((1, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-5, 6),
                          0.8,
                          layer=21,
                          ends="extended",
                          tolerance=1e-4)
    rp.segment((1, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-5, 6),
                          0.8,
                          layer=22,
                          ends=(0.1, 0.2),
                          tolerance=1e-4)
    rp.segment((1, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-5, 6),
                          0.8,
                          layer=23,
                          ends="smooth",
                          tolerance=1e-4)
    rp.segment((1, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-3, 6), 0.8, layer=10, ends="round", tolerance=1e-5)
    rp.segment((1, 0), 0.1, relative=True)
    rp.segment((0, 1), 0.8, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-3, 6),
                          0.8,
                          layer=11,
                          ends="extended",
                          tolerance=1e-5)
    rp.segment((1, 0), 0.1, relative=True)
    rp.segment((0, 1), 0.8, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-3, 6),
                          0.8,
                          layer=12,
                          ends="smooth",
                          tolerance=1e-5)
    rp.segment((1, 0), 0.1, relative=True)
    rp.segment((0, 1), 0.8, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-3, 8), 0.1, layer=13, ends="round", tolerance=1e-5)
    rp.segment((1, 0), 0.8, relative=True)
    rp.segment((0, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-3, 8),
                          0.1,
                          layer=14,
                          ends=(0.2, 0.2),
                          tolerance=1e-5)
    rp.segment((1, 0), 0.8, relative=True)
    rp.segment((0, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((-3, 8),
                          0.1,
                          layer=15,
                          ends="smooth",
                          tolerance=1e-5)
    rp.segment((1, 0), 0.8, relative=True)
    rp.segment((0, 1), 0.1, relative=True)
    cell.add(rp)
    rp = gdspy.RobustPath((5, 2), [0.05, 0.1, 0.2], [-0.2, 0, 0.4],
                          layer=[4, 5, 6])
    rp.parametric(lambda u: numpy.array((5.5 + 3 * u, 2 + 3 * u**2)),
                  relative=False)
    rp.segment((0, 1), relative=True)
    rp.parametric(
        lambda u: numpy.array((2 * numpy.cos(0.5 * numpy.pi * u) - 2, 3 * numpy
                               .sin(0.5 * numpy.pi * u))),
        width=[0.2, 0.1, 0.05],
        offset=[-0.3, 0, 0.3],
    )
    rp.parametric(lambda u: numpy.array((-2 * u, 0)), width=0.1, offset=0.2)
    rp.bezier([(-3, 0), (-2, -3), (0, -4), (0, -5)], offset=[-0.2, 0, 0.2])
    rp.bezier(
        [(4.5, 0), (1, -1), (1, 5), (3, 2), (5, 2)],
        width=[0.05, 0.1, 0.2],
        offset=[-0.2, 0, 0.4],
        relative=False,
    )
    cell.add(rp)
    rp = gdspy.RobustPath((2, -1), 0.1, layer=7, tolerance=1e-4, max_points=0)
    rp.smooth(
        [(1, 0), (1, -1), (0, -1)],
        angles=[numpy.pi / 3, None, -2 / 3.0 * numpy.pi, None],
        cycle=True,
    )
    cell.add(rp)
    rp = gdspy.RobustPath((2.5, -1.5), 0.1, layer=8)
    rp.smooth(
        [(3, -1.5), (4, -2), (5, -1), (6, -2), (7, -1.5), (7.5, -1.5)],
        relative=False,
        width=0.2,
    )
    cell.add(rp)
    assertsame(target["RobustPath2"], cell)