1111from  descartes  import  PolygonPatch 
1212
1313from  .base  import  Tidy3dBaseModel 
14- from  .types  import  Literal , Bound , Size , Coordinate , Axis , Coordinate2D 
14+ from  .types  import  Literal , Bound , Size , Coordinate , Axis , Coordinate2D ,  Array 
1515from  .types  import  Vertices , Ax , Shapely 
1616from  .viz  import  add_ax_if_none 
17- from  ..log  import  Tidy3dKeyError 
17+ from  ..log  import  Tidy3dKeyError ,  SetupError 
1818
1919# add this around extents of plots 
2020PLOT_BUFFER  =  0.3 
@@ -780,8 +780,9 @@ class PolySlab(Planar):
780780
781781    Parameters 
782782    ---------- 
783-     vertices : List[Tuple[float, float]] 
783+     vertices : List[Tuple[float, float]] or np.ndarray  
784784        List of vertices defining the polygon face along dimensions parallel to slab normal axis. 
785+         If numpy.ndarray, must have shape (N, 2) for N vertices. 
785786    axis : int 
786787        Integer index into the polygon's slab axis. (0,1,2) -> (x,y,z) 
787788    slab_bounds: Tuple[float, float] 
@@ -793,7 +794,7 @@ class PolySlab(Planar):
793794    """ 
794795
795796    slab_bounds : Tuple [float , float ]
796-     vertices : Vertices 
797+     vertices : Union [ Vertices ,  Array [ float ]] 
797798    type : Literal ["PolySlab" ] =  "PolySlab" 
798799
799800    @pydantic .validator ("slab_bounds" , always = True ) 
@@ -803,6 +804,18 @@ def set_length(cls, val, values):
803804        values ["length" ] =  zmax  -  zmin 
804805        return  val 
805806
807+     @pydantic .validator ("vertices" , always = True ) 
808+     def  correct_shape (cls , val ):
809+         """makes sure vertices is correct shape if numpy array""" 
810+         if  isinstance (val , np .ndarray ):
811+             shape  =  val .shape 
812+             if  len (shape ) !=  2  or  shape [1 ] !=  2 :
813+                 raise  SetupError (
814+                     "PolySlab.vertices must be a 2 dimensional array shaped (N, 2).  " 
815+                     f"Given array with shape of { shape }  
816+                 )
817+         return  val 
818+ 
806819    @pydantic .validator ("vertices" , always = True ) 
807820    def  set_center (cls , val , values ):
808821        """sets the .center field using zmin, zmax, and polygon vertices""" 
0 commit comments