def test_move(): # Test polygon move D = Device() p = D.add_polygon([(8, 6, 7, 9), (6, 8, 9, 5)]) p.move([1.7, 0.8]) h = D.hash_geometry(precision=1e-4) assert (h == '57a86bce5f60f7bc78c7c30473a544b736d2afb3') p.movex(13.9) h = D.hash_geometry(precision=1e-4) assert (h == '8fe6706e05ebe1512ee2efe2582546b949fbc48f') p.movey(19.2) h = D.hash_geometry(precision=1e-4) assert (h == '7df43241eca2dd11f267c25876e650eadaca7d9f') # Test Device move D = Device() D.add_polygon([(8, 6, 7, 9), (6, 8, 9, 5)]) D.add_polygon([(8, 6, 7, 9, 7, 0), (6, 8, 9, 5, 7, 0)]) D.move([1.7, 0.8]) h = D.hash_geometry(precision=1e-4) assert (h == 'c863156dd00a590dc02823e1791554d4142b1ea9') # Test label move D = Device() D.add_polygon([(8, 8, 8, 8), (6, 6, 6, 6)]) l = D.add_label('testing', position=D.center) print(all(l.center == D.center)) D.rotate(45) print(np.allclose(l.center, D.center)) D.move([70000.5, 30000.5]) print(np.allclose(l.center, D.center)) D.rotate(75) print(np.allclose(l.center, D.center)) D.mirror([7, 5]) print(np.allclose(l.center, D.center))
def fang(wg_width, length, orientation): F = Device() w1 = wg_width X1 = CrossSection() X1.add(width=w1, offset=0, layer=30, ports=('in', 'out')) P = Path() P.append(pp.euler(radius=50, angle=45)) # Euler bend (aka "racetrack" curve) fang = P.extrude(X1) fang = F.add_ref(fang) D = pg.taper(length=length, width1=w1, width2=0.000001, port=None, layer=30) taper = F.add_ref(D) taper.connect(port=1, destination=fang.ports['out']) #Defualt is RU, right up if orientation == 'RD': F.mirror(p1=[0, 0], p2=[1, 0]) elif orientation == 'LU': F.mirror(p1=[0, 0], p2=[0, 1]) elif orientation == 'LD': F.rotate(180, center=[0, 0]) return F
def complicated_waveguide(width=10, height=1, x=10, y=25, rotation=15): C = Device('complicated_waveguide') C.add_polygon([(0, 0), (width, 0), (width, height), (0, height)]) C.add_port(name=1, midpoint=[0, height / 2], width=height, orientation=180) C.add_port(name=2, midpoint=[width, height / 2], width=height, orientation=0) C.rotate(angle=rotation, center=(0, 0)) C.move((x, y)) return C
def test_rotate(): # Test polygon rotation D = Device() p = D.add_polygon([(8, 6, 7, 9), (6, 8, 9, 5)]) p.rotate(37.5) h = D.hash_geometry(precision=1e-4) assert (h == '2e4815072eabe053c3029d9e29a5b3ed59fe9bb7') # Test Device rotation D = Device() p = D.add_polygon([(8, 6, 7, 9), (6, 8, 9, 5)]) D.rotate(37.5) h = D.hash_geometry(precision=1e-4) assert (h == '2e4815072eabe053c3029d9e29a5b3ed59fe9bb7')
# with the original Device. These functions are especially useful if # you want to flatten a geometry without damaging the structure of the # original Device. D = Device() E1 = pg.ellipse(layer=1) E2 = pg.rectangle(layer=2) D.add_ref(E1) D.add_ref(E2).movex(15) D_copied = pg.copy(D) qp(D_copied) # Observe that if we add geometry to D now, D_copied is unaffected D.add_ref(pg.circle()) D.rotate(45) qp(D_copied) # However, note that if we now modify the underlying Devices (which # were referenced in D, and whose references were copied to D_copied), both # the original D and D_copied are affected: E1.add_polygon([[10, 20, 35], [1, 60, 40]], layer=3) qp(D_copied) # If instead we use pg.deepcopy(), all of the underlying references are copied # and used in the new D_deepcopied device. So if we change one of the old # references, the new D_deepcopied doesn't get affected D = Device() E1 = pg.ellipse(layer=1) E2 = pg.rectangle(layer=2) D.add_ref(E1)