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)
def test_translate(): ps = gdspy.PolygonSet([[(0, 0), (1, 0), (1, 2), (0, 2)]]) ps.translate(-1, -2) tgt = gdspy.PolygonSet([[(-1, -2), (0, -2), (0, 0), (-1, 0)]]) assertsame( gdspy.Cell("test", True).add(ps), gdspy.Cell("TGT", True).add(tgt))
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)
def test_hobby2(target): cell = gdspy.Cell("test", True) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)]) cell.add(gdspy.Polygon(c.get_points(), layer=1)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], curl_start=0) cell.add(gdspy.Polygon(c.get_points(), layer=2)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], curl_end=0) cell.add(gdspy.Polygon(c.get_points(), layer=3)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], curl_start=0, curl_end=0) cell.add(gdspy.Polygon(c.get_points(), layer=4)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i( [(1, 2), (2, 1), (3, 2), (4, 0)], angles=[numpy.pi / 2, None, None, None, -numpy.pi / 2], curl_start=0, curl_end=0, ) cell.add(gdspy.Polygon(c.get_points(), layer=5)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i( [(1, 2), (2, 1), (3, 2), (4, 0)], angles=[None, 0, None, 0, None], curl_start=0, curl_end=1, ) cell.add(gdspy.Polygon(c.get_points(), layer=6)) assertsame(target["Hobby2"], cell)
def test_flexpath1(target): cell = gdspy.Cell("test") fp = gdspy.FlexPath([(0, 0), (1, 1)], 0.1, layer=[1], gdsii_path=True) cell.add(fp) fp = gdspy.FlexPath( [(1, 0), (2, 1)], 0.1, [-0.1, 0.1], tolerance=1e-5, ends=["round", "extended"], layer=[2, 3], max_points=6, ) cell.add(fp) fp = gdspy.FlexPath([(2, 0), (3, 1)], [0.1, 0.2], 0.2, ends=(0.2, 0.1), layer=4, datatype=[1, 1]) cell.add(fp) fp = gdspy.FlexPath( [(3, 0), (4, 1)], [0.1, 0.2, 0.1], [-0.2, 0, 0.2], ends=[(0.2, 0.1), "smooth", pointy], datatype=5, ) cell.add(fp) assertsame(target["FlexPath1"], cell)
def test_hobby3(target): cell = gdspy.Cell("test", True) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)]) cell.add(gdspy.Polygon(c.get_points(), layer=1)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_in=2) cell.add(gdspy.Polygon(c.get_points(), layer=2)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_out=2) cell.add(gdspy.Polygon(c.get_points(), layer=3)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_in=2, t_out=2) cell.add(gdspy.Polygon(c.get_points(), layer=4)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_in=[2, 1, 1, 1, 1], t_out=[1, 1, 1, 1, 2]) cell.add(gdspy.Polygon(c.get_points(), layer=5)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_in=[1, 1, 2, 1, 1], t_out=[1, 2, 1, 1, 1]) cell.add(gdspy.Polygon(c.get_points(), layer=6)) assertsame(target["Hobby3"], cell)
def test_flexpath3(target): cell = gdspy.Cell("test") pts = numpy.array([ (0, 0), (0.5, 0), (1, 0), (1, 2), (3, 0), (2, -1), (2, -2), (0, -1), (1, -2), (1, -3), ]) fp = gdspy.FlexPath( pts + numpy.array((0, 5)), [0.1, 0.1, 0.1], 0.15, layer=[1, 2, 3], corners=["natural", "miter", "bevel"], ends=(0.5, 0), ) cell.add(fp) fp = gdspy.FlexPath( pts + numpy.array((5, 0)), [0.1, 0.1, 0.1], 0.15, layer=[4, 5, 6], corners=["round", "smooth", broken], ends=[pointy, "smooth", (0, 0.5)], ) cell.add(fp) assertsame(target["FlexPath3"], cell)
def test_hobby4(target): cell = gdspy.Cell('test', True) c = gdspy.Curve(0, 3, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=10)) c = gdspy.Curve(0, 3, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_in=[2, 1, 1, 1, 1], t_out=[1, 1, 1, 1, 2], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=11)) c = gdspy.Curve(0, 3, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], t_in=[1, 1, 2, 1, 1], t_out=[1, 2, 1, 1, 1], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=12)) c = gdspy.Curve(0, 3, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], angles=[numpy.pi * 3 / 4.0, None, None, None, -numpy.pi * 3 / 4.0], t_in=[2, 1, 1, 1, 1], t_out=[1, 1, 1, 1, 2], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=13)) c = gdspy.Curve(0, 3, tolerance=1e-3) c.i([(1, 2), (2, 1), (3, 2), (4, 0)], angles=[numpy.pi * 3 / 4.0, None, None, None, -numpy.pi * 3 / 4.0], t_in=[1, 1, 1, 1, 1], t_out=[1, 1, 1, 1, 1], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=14)) assertsame(target['Hobby4'], cell)
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)
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()
def test_mirror(): ps = gdspy.PolygonSet([[(0, 0), (1, 0), (1, 2), (0, 2)]]) ps.mirror((-1, 1), (1, -1)) tgt = gdspy.PolygonSet([[(0, 0), (-2, 0), (-2, -1), (0, -1)]]) assertsame( gdspy.Cell("test", True).add(ps), gdspy.Cell("TGT", True).add(tgt))
def test_fillet(target): cell = gdspy.Cell("test") orig = gdspy.PolygonSet([ [ (0, 0), (-1, 0), (0, -1), (0.5, -0.5), (1, 0), (1, 1), (4, -1), (1, 3), (1, 2), (0, 1), ], [(2, -1), (3, -1), (2.5, -2)], ]) orig.datatypes = [0, 1] p = gdspy.copy(orig, 0, 5) p.layers = [1, 1] p.fillet(0.3, max_points=0) cell.add(p) p = gdspy.copy(orig, 5, 5) p.layers = [2, 2] p.fillet([0.3, 0.2, 0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.4, 0.1, 0.2, 0], max_points=0) cell.add(p) p = gdspy.copy(orig, 5, 0) p.layers = [3, 3] p.fillet( [[0.1, 0.1, 0.4, 0, 0.4, 0.1, 0.1, 0.4, 0.4, 0.1], [0.2, 0.2, 0.5]], max_points=0, ) cell.add(p) p = gdspy.PolygonSet( [ [ (0, 0), (0, 0), (-1, 0), (0, -1), (0.5, -0.5), (1, 0), (1, 0), (1, 1), (4, -1), (1, 3), (1, 2), (0, 1), ], [(2, -1), (3, -1), (2.5, -2), (2, -1)], ], layer=4, ) p.datatypes = [0, 1] p.fillet([0.8, [10.0, 10.0, 20.0, 20.0]], max_points=199, precision=1e-6) cell.add(p) assertsame(cell, target["PolygonSet_fillet"], tolerance=1e-3)
def test_togds(tmpdir): ps = gdspy.PolygonSet([[(10 + i * 1e-3, i ** 2 * 1e-6) for i in range(8191)]]) cell = gdspy.Cell("LARGE").add(ps) fname = str(tmpdir.join("large.gds")) lib = gdspy.GdsLibrary(unit=1, precision=1e-7).add(cell) with pytest.warns(UserWarning): lib.write_gds(fname) lib = gdspy.GdsLibrary(infile=fname) assertsame(lib.cells["LARGE"], cell)
def test_rotation(): ps = gdspy.PolygonSet([[(0, 0), (1, 0), (1, 2), (0, 2)]]) ps.rotate(-numpy.pi / 6, center=(1, 0)) x = 3**0.5 / 2 a = numpy.arctan(2) + numpy.pi / 6 l = 5**0.5 tgt = gdspy.PolygonSet([[(1 - x, 0.5), (1, 0), (2, 2 * x), (1 - l * numpy.cos(a), l * numpy.sin(a))]]) assertsame(gdspy.Cell("test").add(ps), gdspy.Cell("TGT").add(tgt))
def test_flexpath_duplicates(): fp = gdspy.FlexPath([(1.1, 2), (1.1, 2.0)], 0.1) poly = fp.get_polygons() assert isinstance(poly, list) and len(poly) == 0 poly = fp.get_polygons(True) assert isinstance(poly, dict) and len(poly) == 0 fp1 = gdspy.FlexPath([(1.1, 2), (1.1, 2.0), (1, 1), (1, 1), (1, 1.0), (0, 1), (0.0, 1.0)], 0.1) fp2 = gdspy.FlexPath([(1.1, 2), (1, 1.0), (0.0, 1.0)], 0.1) assertsame(gdspy.Cell("DUPS").add(fp1), gdspy.Cell("SNGL").add(fp2))
def test_scale(): ps = gdspy.PolygonSet([[(0, 0), (1, 0), (1, 2), (0, 2)]]) cell = gdspy.Cell("test").add(ps) ps.scale(0.5) tgt = gdspy.PolygonSet([[(0, 0), (0.5, 0), (0.5, 1), (0, 1)]]) assertsame(cell, gdspy.Cell("TGT").add(tgt)) ps = gdspy.PolygonSet([[(0, 0), (1, 0), (1, 2), (0, 2)]]) cell = gdspy.Cell("test").add(ps) ps.scale(0.2, 2, center=(1, 2)) tgt = gdspy.PolygonSet([[(0.8, -2), (1, -2), (1, 2), (0.8, 2)]]) assertsame(cell, gdspy.Cell("TGT").add(tgt))
def test_flexpath_transform(target): fp = gdspy.FlexPath([(0, 0)], [2, 1, 1], 5) 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)) assertsame(target["FlexPath5"], gdspy.Cell("FP5").add(fp))
def test_flexpath_togds(tmpdir): cell = gdspy.Cell("flexpath") fp = gdspy.FlexPath([(0, 0), (0.5, 0.5), (1, 1)], 0.1, layer=[1], gdsii_path=True) cell.add(fp) fp = gdspy.FlexPath([(3, 0), (3.5, 0.5), (4, 1)], 0.1, layer=[21]) cell.add(fp) fp = gdspy.FlexPath( [(1, 0), (2, 1)], 0.1, [-0.1, 0.1], max_points=6, ends=["round", "extended"], layer=[2, 3], gdsii_path=True, ) cell.add(fp) fp = gdspy.FlexPath( [(2, 0), (3, 1)], [0.1, 0.2], 0.2, ends=(0.2, 0.1), layer=4, datatype=[10, 10], gdsii_path=True, ) cell.add(fp) fp = gdspy.FlexPath( [(0, 0), (0.5, 0), (1, 0), (1, 1), (0, 1), (-1, -2), (-2, 0)], 0.05, [0, -0.1, 0, 0.1], corners=["natural", "circular bend", "circular bend", "circular bend"], tolerance=1e-5, ends=["flush", "extended", (0.1, 0.2), "flush"], layer=[10, 11, 11, 12], bend_radius=[0, 0.3, 0.3, 0.2], gdsii_path=True, ).translate(-5, 0) cell.add(fp) fp = gdspy.FlexPath([(i, 2 + i**2) for i in numpy.linspace(0, 1, 8192)], 0.01, gdsii_path=True) cell.add(fp) 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={"flexpath": "file"}) assertsame(lib.cell_dict["file"], cell, tolerance=1e-3) gdspy.current_library = gdspy.GdsLibrary()
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)
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)
def test_flexpath2(target): cell = gdspy.Cell('test', True) fp = gdspy.FlexPath( [(0, 0), (0.5, 0), (1, 0), (1, 1), (0, 1), (-1, -2), (-2, 0)], 0.05, [0, -0.1, 0, 0.1], corners=['natural', 'circular bend', 'circular bend', 'circular bend'], ends=['flush', 'extended', (0.1, 0.2), 'round'], tolerance=1e-4, layer=[0, 1, 1, 2], bend_radius=[0, 0.3, 0.3, 0.2], max_points=10) cell.add(fp) assertsame(target['FlexPath2'], cell) cell = gdspy.Cell('test2', True)
def test_flexpath2(target): cell = gdspy.Cell("test") fp = gdspy.FlexPath( [(0, 0), (0.5, 0), (1, 0), (1, 1), (0, 1), (-1, -2), (-2, 0)], 0.05, [0, -0.1, 0, 0.1], corners=["natural", "circular bend", "circular bend", "circular bend"], ends=["flush", "extended", (0.1, 0.2), "round"], tolerance=1e-4, layer=[0, 1, 1, 2], bend_radius=[0, 0.3, 0.3, 0.2], max_points=10, ) cell.add(fp) assertsame(target["FlexPath2"], cell)
def test_flexpath_gdsiipath(): cells = [] for gdsii_path in [True, False]: cells.append(gdspy.Cell(str(gdsii_path))) fp = gdspy.FlexPath( [(0, 0), (0.5, 0), (1, 0), (1, 1), (0, 1), (-1, -2), (-2, 0)], 0.05, [-0.1, 0.1], corners=["natural", "circular bend"], ends=["extended", (0.1, 0.2)], layer=[0, 1], bend_radius=[0, 0.3], gdsii_path=gdsii_path, ) cells[-1].add(fp) assertsame(*cells)
def test_flexpath3(target): cell = gdspy.Cell('test', True) pts = numpy.array([(0, 0), (0.5, 0), (1, 0), (1, 2), (3, 0), (2, -1), (2, -2), (0, -1), (1, -2), (1, -3)]) fp = gdspy.FlexPath(pts + numpy.array((0, 5)), [0.1, 0.1, 0.1], 0.15, layer=[1, 2, 3], corners=['natural', 'miter', 'bevel'], ends=(0.5, 0)) cell.add(fp) fp = gdspy.FlexPath(pts + numpy.array((5, 0)), [0.1, 0.1, 0.1], 0.15, layer=[4, 5, 6], corners=['round', 'smooth', broken], ends=[pointy, 'smooth', (0, 0.5)]) cell.add(fp) assertsame(target['FlexPath3'], cell)
def test_polygonset(target): ps = gdspy.PolygonSet( [ [(10, 0), (11, 0), (10, 1)], numpy.array([(11.0, 0), (10, 1), (11, 1)]), [numpy.array((11, 1)), numpy.array((12.0, 1.0)), (11, 2)], ], 1, 2, ) assert str(ps) == "PolygonSet (3 polygons, 9 vertices, layers [1], datatypes [2])" assert ps.area() == 1.5 assert ps.area(True) == {(1, 2): 1.5} bb = ps.get_bounding_box() assert bb.shape == (2, 2) assert numpy.max(numpy.abs(bb - numpy.array(((10, 0), (12, 2))))) == 0 assert gdspy.PolygonSet([]).get_bounding_box() == None cell = gdspy.Cell("test").add(ps) assertsame(cell, target["PolygonSet"])
def test_flexpath1(target): cell = gdspy.Cell('test', True) fp = gdspy.FlexPath([(0, 0), (1, 1)], 0.1, layer=[1], gdsii_path=True) cell.add(fp) fp = gdspy.FlexPath([(1, 0), (2, 1)], 0.1, [-0.1, 0.1], tolerance=1e-5, ends=['round', 'extended'], layer=[2, 3], max_points=6) cell.add(fp) fp = gdspy.FlexPath([(2, 0), (3, 1)], [0.1, 0.2], 0.2, ends=(0.2, 0.1), layer=4, datatype=[1, 1]) cell.add(fp) fp = gdspy.FlexPath([(3, 0), (4, 1)], [0.1, 0.2, 0.1], [-0.2, 0, 0.2], ends=[(0.2, 0.1), 'smooth', pointy], datatype=5) cell.add(fp) assertsame(target['FlexPath1'], cell)
def test_fracture(): ps1 = gdspy.PolygonSet([[(-2, -1), (-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2)]]) ps2 = gdspy.PolygonSet([[(-2, -1), (-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2)]]) ps2.fracture(5) assert all(len(p) <= 5 for p in ps2.polygons) assertsame(gdspy.Cell("1").add(ps1), gdspy.Cell("2").add(ps2)) def spiral(u): r = 4 - 3 * u theta = 5 * u * numpy.pi x = r * numpy.cos(theta) - 4 y = r * numpy.sin(theta) return (x, y) def dspiral_dt(u): theta = 5 * u * numpy.pi dx_dt = -numpy.sin(theta) dy_dt = numpy.cos(theta) return (dx_dt, dy_dt) pt1 = gdspy.Path(0.5, (0, 0)) pt1.parametric(spiral, dspiral_dt, number_of_evaluations=512, tolerance=10, max_points=0) assert len(pt1.polygons) == 1 assert len(pt1.polygons[0]) == 1024 pt2 = gdspy.Path(0.5, (0, 0)) pt2.parametric(spiral, dspiral_dt, number_of_evaluations=512, tolerance=10, max_points=0) pt2.fracture(199, precision=1e-6) assert all(len(p) <= 199 for p in pt2.polygons) assertsame(gdspy.Cell("3").add(pt1), gdspy.Cell("4").add(pt2))
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)
def test_flexpath4(target): cell = gdspy.Cell("test") fp = gdspy.FlexPath( [(0, 0)], [0.1, 0.2, 0.1], 0.15, layer=[1, 2, 3], corners=["natural", "miter", "bevel"], ) fp.segment((1, 0)) fp.segment((1, 1), 0.1, 0.05) fp.segment((1, 1), [0.2, 0.1, 0.1], -0.05, True) fp.segment((-1, 1), 0.2, [-0.2, 0, 0.3], True) fp.arc(2, 0, 0.5 * numpy.pi) fp.arc(3, 0.5 * numpy.pi, numpy.pi, 0.1, 0) fp.arc(1, 0.4 * numpy.pi, -0.4 * numpy.pi, [0.1, 0.2, 0.1], [0.2, 0, -0.2]) fp.turn(1, 0.4 * numpy.pi) fp.turn(1, "ll", 0.15, 0) fp.turn(0.5, "r", [0.1, 0.05, 0.1], [0.15, 0, -0.15]) cell.add(fp) fp = gdspy.FlexPath([(-5, 6)], 0.8, layer=20, ends="round", tolerance=1e-4) fp.segment((1, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-5, 6)], 0.8, layer=21, ends="extended", tolerance=1e-4) fp.segment((1, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-5, 6)], 0.8, layer=22, ends=(0.1, 0.2), tolerance=1e-4) fp.segment((1, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-5, 6)], 0.8, layer=23, ends="smooth", tolerance=1e-4) fp.segment((1, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-3, 6)], 0.8, layer=10, corners="round", ends="round", tolerance=1e-5) fp.segment((1, 0), 0.1, relative=True) fp.segment((0, 1), 0.8, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-3, 6)], 0.8, layer=11, corners="smooth", ends="extended", tolerance=1e-5) fp.segment((1, 0), 0.1, relative=True) fp.segment((0, 1), 0.8, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-3, 6)], 0.8, layer=12, corners="smooth", ends="smooth", tolerance=1e-5) fp.segment((1, 0), 0.1, relative=True) fp.segment((0, 1), 0.8, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-3, 8)], 0.1, layer=13, corners="round", ends="round", tolerance=1e-5) fp.segment((1, 0), 0.8, relative=True) fp.segment((0, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-3, 8)], 0.1, layer=14, corners="smooth", ends=(0.2, 0.2), tolerance=1e-5) fp.segment((1, 0), 0.8, relative=True) fp.segment((0, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(-3, 8)], 0.1, layer=15, corners="round", ends="smooth", tolerance=1e-5) fp.segment((1, 0), 0.8, relative=True) fp.segment((0, 1), 0.1, relative=True) cell.add(fp) fp = gdspy.FlexPath([(5, 2)], [0.05, 0.1, 0.2], [-0.2, 0, 0.4], layer=[4, 5, 6]) fp.parametric(lambda u: numpy.array((5.5 + 3 * u, 2 + 3 * u**2)), relative=False) fp.segment((0, 1), relative=True) fp.parametric( lambda u: numpy.array((2 * numpy.cos(0.5 * numpy.pi * u) - 2, 3 * numpy .sin(0.5 * numpy.pi * u))), [0.2, 0.1, 0.05], [-0.3, 0, 0.3], ) fp.parametric(lambda u: numpy.array((-2 * u, 0)), 0.1, 0.2) fp.bezier([(-3, 0), (-2, -3), (0, -4), (0, -5)], offset=[-0.2, 0, 0.2]) fp.bezier( [(5, 0), (1, -1), (1, 5), (3, 2), (5, 2)], [0.05, 0.1, 0.2], [-0.2, 0, 0.4], relative=False, ) cell.add(fp) fp = gdspy.FlexPath([(2, -1)], 0.1, layer=7, tolerance=1e-5, max_points=0) fp.smooth( [(1, 0), (1, -1), (0, -1)], angles=[numpy.pi / 3, None, -2 / 3.0 * numpy.pi, None], cycle=True, ) cell.add(fp) fp = gdspy.FlexPath([(2.5, -1.5)], 0.1, layer=8) fp.smooth( [(3, -1.5), (4, -2), (5, -1), (6, -2), (7, -1.5), (7.5, -1.5)], relative=False, width=0.2, ) cell.add(fp) assertsame(target["FlexPath4"], cell)
def test_hobby1(target): cell = gdspy.Cell("test", True) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)]) cell.add(gdspy.Polygon(c.get_points(), layer=1)) c = gdspy.Curve(2, 0, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[numpy.pi / 3, None, None, None]) cell.add(gdspy.Polygon(c.get_points(), layer=3)) c = gdspy.Curve(4, 0, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, None, None, 2 / 3.0 * numpy.pi]) cell.add(gdspy.Polygon(c.get_points(), layer=5)) c = gdspy.Curve(0, 2, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[numpy.pi / 3, None, None, 3 / 4.0 * numpy.pi]) cell.add(gdspy.Polygon(c.get_points(), layer=7)) c = gdspy.Curve(2, 2, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, None, numpy.pi / 2, None]) cell.add(gdspy.Polygon(c.get_points(), layer=9)) c = gdspy.Curve(4, 2, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, 0, None, None]) cell.add(gdspy.Polygon(c.get_points(), layer=11)) c = gdspy.Curve(0, 4, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, 0, None, -numpy.pi / 2]) cell.add(gdspy.Polygon(c.get_points(), layer=13)) c = gdspy.Curve(2, 4, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, 0, -numpy.pi, -numpy.pi / 2]) cell.add(gdspy.Polygon(c.get_points(), layer=15)) c = gdspy.Curve(4, 4, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[-numpy.pi / 4, 0, numpy.pi / 2, -numpy.pi]) cell.add(gdspy.Polygon(c.get_points(), layer=17)) c = gdspy.Curve(0, 0, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=2)) c = gdspy.Curve(2, 0, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[numpy.pi / 3, None, None, None], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=4)) c = gdspy.Curve(4, 0, tolerance=1e-3) c.i( [(1, 0), (1, 1), (0, 1)], angles=[None, None, None, 2 / 3.0 * numpy.pi], cycle=True, ) cell.add(gdspy.Polygon(c.get_points(), layer=6)) c = gdspy.Curve(0, 2, tolerance=1e-3) c.i( [(1, 0), (1, 1), (0, 1)], angles=[numpy.pi / 3, None, None, 3 / 4.0 * numpy.pi], cycle=True, ) cell.add(gdspy.Polygon(c.get_points(), layer=8)) c = gdspy.Curve(2, 2, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, None, numpy.pi / 2, None], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=10)) c = gdspy.Curve(4, 2, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, 0, None, None], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=12)) c = gdspy.Curve(0, 4, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, 0, None, -numpy.pi / 2], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=14)) c = gdspy.Curve(2, 4, tolerance=1e-3) c.i([(1, 0), (1, 1), (0, 1)], angles=[None, 0, -numpy.pi, -numpy.pi / 2], cycle=True) cell.add(gdspy.Polygon(c.get_points(), layer=16)) c = gdspy.Curve(4, 4, tolerance=1e-3) c.i( [(1, 0), (1, 1), (0, 1)], angles=[-numpy.pi / 4, 0, numpy.pi / 2, -numpy.pi], cycle=True, ) cell.add(gdspy.Polygon(c.get_points(), layer=18)) assertsame(target["Hobby1"], cell)