"""Polygon helpers and simple geometric utility cells.""" from typing import Optional import nazca as nd import nazca.clipper as clp import numpy as np def _my_polygon (layer_wg,vtx,vtx_not=None) : ''' establishing a polygon with input vertices Args vtx (2*x list) : Return frame (nazca.cell): ''' sz_l = vtx.shape sz_l = sz_l[0] idx_seq = np.linspace(1,sz_l-1,sz_l-1) _points_ = [(vtx[0,0],vtx[0,1])] for idx in idx_seq: _point_cur_ = [(vtx[int(idx),0],vtx[int(idx),1])] _points_.extend(_point_cur_) if (isinstance(vtx_not,np.ndarray) ): _points_cut_ = [(vtx_not[0,0],vtx_not[0,1])] sz_l = vtx_not.shape sz_l = sz_l[0] for idx in range(0,sz_l): _point_cur_ = [(vtx_not[int(idx),0],vtx_not[int(idx),1])] _points_cut_.extend(_point_cur_) _points_ = clp.diff_polygons(paths_A=[_points_],paths_B=[_points_cut_]) _points_ = _points_[0] # nd.Polygon(layer=layer_wg, points = _points_cut_).put() frame = nd.Polygon(layer=layer_wg, points = _points_) return frame class strt_round_courner: def __init__(self, width: float=5, length: float = 10, layer: Optional[str]=None, radius: float=1, n_points: int=64) -> None: if (radius>width/2): radius = width/2 with nd.Cell(instantiate=False) as C: theta = np.linspace(0,np.pi/2,n_points) ## establish a arc vtx_ru_x = radius*np.cos(theta) + length-radius vtx_ru_y = radius*np.sin(theta) + width/2 - radius theta = np.linspace(np.pi/2,np.pi,n_points) ## establish a arc vtx_lu_x = radius*np.cos(theta) + radius vtx_lu_y = radius*np.sin(theta) + width/2 - radius theta = np.linspace(np.pi,np.pi/2*3,n_points) ## establish a arc vtx_ld_x = radius*np.cos(theta) + radius vtx_ld_y = radius*np.sin(theta) - width/2 + radius theta = np.linspace(-np.pi/2,0,n_points) ## establish a arc vtx_rd_x = radius*np.cos(theta) + length-radius vtx_rd_y = radius*np.sin(theta) - width/2 + radius vtx_x = np.r_[vtx_ru_x,vtx_lu_x,vtx_ld_x,vtx_rd_x] vtx_y = np.r_[vtx_ru_y,vtx_lu_y,vtx_ld_y,vtx_rd_y] # vtx_x = vtx_ru_x # vtx_y = vtx_ru_y vtx = np.c_[vtx_x,vtx_y] # vtx = np.transpose(vtx) # print(np.shape(vtx)) _my_polygon(layer_wg=layer,vtx=vtx).put() nd.Pin(name='a0',width=width).put(0,0,180) nd.Pin(name='b0',width=width).put(length,0,0) nd.put_stub() self.cell = C