original_docstring:  Routes a straight polygon between two ports. 
docstring: Routes a straight polygon between two ports.
docstring_tokens: Routes a straight polygon between two ports .
code: def RouteStraight(p1, p2, layer, path_type='straight', width_type='straight'):
      """ Routes a straight polygon between two ports. """
  
      point_a = p1.midpoint
      point_b = p2.midpoint
      width_input = p1.width
      width_output = p2.width
  
      if ug.angle_diff(p2.orientation, p1.orientation) != 180:
          raise ValueError('Ports do not face eachother.')
  
      separation = np.array([point_b[0], point_b[1]]) - np.array([point_a[0], point_a[1]])
      distance = norm(separation)
      rotation = np.arctan2(separation[1], separation[0]) * constants.RAD2DEG
      angle = rotation - p1.orientation
      xf = distance * np.cos(angle*constants.DEG2RAD)
      yf = distance * np.sin(angle*constants.DEG2RAD)
  
      if path_type == 'straight':
          curve_fun = lambda t: [xf*t, yf*t]
          curve_deriv_fun = lambda t: [xf + t*0, 0 + t*0]
      if path_type == 'sine':
          curve_fun = lambda t: [xf*t, yf*(1-np.cos(t*np.pi))/2]
          curve_deriv_fun = lambda t: [xf + t*0, yf*(np.sin(t*np.pi)*np.pi)/2]
  
      if width_type == 'straight':
          width_fun = lambda t: (width_output - width_input)*t + width_input
      if width_type == 'sine':
          width_fun = lambda t: (width_output - width_input)*(1-np.cos(t*np.pi))/2 + width_input
  
      path = gdspy.Path(width=width_input, initial_point=(0,0))
      path.parametric(curve_fun, curve_deriv_fun, final_width=width_fun)
  
      port1 = Port(name='I1', midpoint=(0,0), width=width_input, orientation=180, process=layer.process)
      port2 = Port(name='I2', midpoint=(xf,yf), width=width_output, orientation=0, process=layer.process)
  
      R = Route(shape=path, p1=port1, p2=port2, layer=layer)
      T = vector_match_transform(v1=R.ports[0], v2=p1)
      R.transform(T)
      return R
code_tokens: def RouteStraight ( p1 , p2 , layer , path_type = 'straight' , width_type = 'straight' ) : point_a = p1 . midpoint point_b = p2 . midpoint width_input = p1 . width width_output = p2 . width if ug . angle_diff ( p2 . orientation , p1 . orientation ) != 180 : raise ValueError ( 'Ports do not face eachother.' ) separation = np . array ( [ point_b [ 0 ] , point_b [ 1 ] ] ) - np . array ( [ point_a [ 0 ] , point_a [ 1 ] ] ) distance = norm ( separation ) rotation = np . arctan2 ( separation [ 1 ] , separation [ 0 ] ) * constants . RAD2DEG angle = rotation - p1 . orientation xf = distance * np . cos ( angle * constants . DEG2RAD ) yf = distance * np . sin ( angle * constants . DEG2RAD ) if path_type == 'straight' : curve_fun = lambda t : [ xf * t , yf * t ] curve_deriv_fun = lambda t : [ xf + t * 0 , 0 + t * 0 ] if path_type == 'sine' : curve_fun = lambda t : [ xf * t , yf * ( 1 - np . cos ( t * np . pi ) ) / 2 ] curve_deriv_fun = lambda t : [ xf + t * 0 , yf * ( np . sin ( t * np . pi ) * np . pi ) / 2 ] if width_type == 'straight' : width_fun = lambda t : ( width_output - width_input ) * t + width_input if width_type == 'sine' : width_fun = lambda t : ( width_output - width_input ) * ( 1 - np . cos ( t * np . pi ) ) / 2 + width_input path = gdspy . Path ( width = width_input , initial_point = ( 0 , 0 ) ) path . parametric ( curve_fun , curve_deriv_fun , final_width = width_fun ) port1 = Port ( name = 'I1' , midpoint = ( 0 , 0 ) , width = width_input , orientation = 180 , process = layer . process ) port2 = Port ( name = 'I2' , midpoint = ( xf , yf ) , width = width_output , orientation = 0 , process = layer . process ) R = Route ( shape = path , p1 = port1 , p2 = port2 , layer = layer ) T = vector_match_transform ( v1 = R . ports [ 0 ] , v2 = p1 ) R . transform ( T ) return R
short_docstring: Routes a straight polygon between two ports.
short_docstring_tokens: Routes a straight polygon between two ports .
comment: """ Routes a straight polygon between two ports. """