def slice_image(): triangle = gdstk.regular_polygon((-10, 0), 8, 3) ring = gdstk.ellipse((10, 0), 8, 5, layer=1) result = gdstk.slice([triangle, ring], (-10, -5, 0, 6, 14), "x") # print(len(result)) # print([len(polys) for polys in result]) return gdstk.Cell("slice").add(*[p for polys in result for p in polys])
def slice_image(): triangle = gdstk.regular_polygon((-10, 0), 8, 3) ring = gdstk.ellipse((10, 0), 8, 5, layer=1) result = gdstk.slice([triangle, ring], (-10, -5, 0, 6, 14), "x") assert len(result) == 6 assert all(len(polys) == s for polys, s in zip(result, [1, 1, 0, 1, 2, 1])) return gdstk.Cell("slice").add(*[p for polys in result for p in polys])
def bench_gdstk(output=None): poly = gdstk.regular_polygon((0, 0), 1.5, 6, layer=1) orig = gdstk.Cell("OFF") orig.add(poly) ref = gdstk.Reference(orig, (-3, 5), columns=4, spacing=(2, 0)) off = gdstk.offset([poly, ref], 0.2, "bevel", layer=0) boo = gdstk.boolean(off, [poly, ref], "not", layer=2) if output: cell = gdstk.Cell("MAIN") cell.add(ref, poly, *off, *boo) cell.write_svg(output, 50)
def bench_gdstk(): n = 8000 r = 1 length = 2 * r * numpy.sin(numpy.pi / n) cell = gdstk.Cell("MAIN") for i in range(1000): cell.add(gdstk.regular_polygon((i, 0), length, n)) name = pathlib.Path(tempfile.gettempdir()) / "gsdtk.gds" lib = gdstk.Library() lib.add(cell) lib.write_gds(name, 0)
def regular_polygon_image(): poly3 = gdstk.regular_polygon((0, 0), 9, 3) poly4 = gdstk.regular_polygon((10, 0), 7, 4, layer=1) poly5 = gdstk.regular_polygon((0, 10), 5, 5, layer=2) poly6 = gdstk.regular_polygon((10, 10), 4, 6, layer=3) return gdstk.Cell("regular_polygon").add(poly3, poly4, poly5, poly6)
"datatype": 3 }, "partial etch": { "layer": 2, "datatype": 3 }, "lift-off": { "layer": 0, "datatype": 7 }, } p1 = gdstk.rectangle((-3, -3), (3, 3), **ld["full etch"]) p2 = gdstk.rectangle((-5, -3), (-3, 3), **ld["partial etch"]) p3 = gdstk.rectangle((5, -3), (3, 3), **ld["partial etch"]) p4 = gdstk.regular_polygon((0, 0), 2, 6, **ld["lift-off"]) draw(gdstk.Cell("layer_and_datatype").add(p1, p2, p3, p4), path) # References # Create a cell with a component that is used repeatedly contact = gdstk.Cell("CONTACT") contact.add(p1, p2, p3, p4) # Create a cell with the complete device device = gdstk.Cell("DEVICE") device.add(cutout) # Add 2 references to the component changing size and orientation ref1 = gdstk.Reference(contact, (3.5, 1), magnification=0.25) ref2 = gdstk.Reference(contact, (1, 3.5), magnification=0.25, rotation=numpy.pi / 2)
# Copyright 2020 Lucas Heitzmann Gabrielli. # This file is part of gdstk, distributed under the terms of the # Boost Software License - Version 1.0. See the accompanying # LICENSE file or <http://www.boost.org/LICENSE_1_0.txt> import pathlib from tutorial_images import draw import numpy import gdstk if __name__ == "__main__": # Rectangular repetition square = gdstk.regular_polygon((0, 0), 0.2, 4) square.repetition = gdstk.Repetition(3, 2, spacing=(1, 1)) # Regular repetition triangle = gdstk.regular_polygon((0, 2.5), 0.2, 3) triangle.repetition = gdstk.Repetition(3, 5, v1=(0.4, -0.3), v2=(0.4, 0.2)) # Explicit repetition circle = gdstk.ellipse((3.5, 0), 0.1) circle.repetition = gdstk.Repetition(offsets=[(0.5, 1), (2, 0), (1.5, 0.5)]) # X-explicit repetition vline = gdstk.FlexPath([(3, 2), (3, 3.5)], 0.1, gdsii_path=True) vline.repetition = gdstk.Repetition(x_offsets=[0.2, 0.6, 1.4, 3.0]) # Y-explicit repetition hline = gdstk.RobustPath((3, 2), 0.05, gdsii_path=True) hline.segment((6, 2))
if __name__ == "__main__": main = gdstk.Cell("Main") # Create a path path = gdstk.RobustPath((0, 0), 0.5) path.segment((8, 0)) path.interpolation( [(2, -4), (-2, -6), (-5, -8), (-4, -12)], angles=[0, None, None, None, -numpy.pi / 4], relative=True, ) path.segment((3, -3), relative=True) main.add(path) # Major and minor markers major = gdstk.regular_polygon((0, 0), 0.5, 6, layer=1) minor = gdstk.rectangle((-0.1, -0.5), (0.1, 0.5), layer=1) for s in range(path.size): # A major marker is added at the start of each path section m = major.copy() m.translate(path.position(s)) main.add(m) for u in numpy.linspace(0, 1, 5)[1:-1]: # Each section receives 3 equally-spaced minor markers # rotated to be aligned to the path direction m = minor.copy() grad = path.gradient(s + u) m.rotate(numpy.arctan2(grad[1], grad[0])) m.translate(path.position(s + u)) main.add(m) # Add a major marker at the end of the path