[docs]def__init__(self,cross_sections:List[List[Path]],close_ends:Optional[bool]=True,stl_resolution:Optional[Union[int,Dict[str,int]]]=1,verbosity:Optional[int]=1,name:Optional[str]=None,)->None:"""Create a swept component. Parameters ---------- cross_sections : list A list containing cross-sections. Each cross-section is a list of paths that define one cross-section. They should connect end-to-end. close_ends : bool, optional If true the first and last cross-section will be used to close the sweap component. Only supported is cross-section is defined by 4 paths. The default is True. stl_resolution : int | dict[str, int], optional Defines different stl resolution for different edges. Keys are are: 'e0', 'e1', ... 'eN', 'sweep' for edges in first cross-section and for swept edges. The default is 1. """super().__init__(stl_resolution=stl_resolution,verbosity=verbosity,name=name)self.cross_sections=cross_sectionsself.close_ends=close_endsself.n_slices=len(self.cross_sections)self.n_edges=len(self.cross_sections[0])self._check_options()
def_check_options(self,small_number:Optional[int]=1e-12):forns,csinenumerate(self.cross_sections):iflen(cs)!=self.n_edges:# check that each c/s has correct number of edgesraiseException(f"Swept Component {self.name}."+f"Slice {ns} has incorrect number of edges.\n"+f"N_e={len(cs)} - {self.n_edges} expected.")foriinrange(len(cs)):# check that edges in each c/s form a closed loopifi<len(cs)-1:ip=i+1else:ip=0p1=cs[i](1)p0=cs[ip](0)if(abs(p0.x-p1.x)>small_numberorabs(p0.y-p1.y)>small_numberorabs(p0.z-p1.z)>small_number):raiseException(f"Swept Component {self.name}, Slice {ns}, edges not closed.\n"+f"edges[{i}](1) != edges[{ip}](0)\n"+f"{p1} != {p0}")ifself.close_endsisTrueandself.n_edges!=4:raiseException(f"Swept Component {self.name}. Combination of "+f"close_ends={self.close_ends} and N_edge={self.n_edges} is "+f"not supported.")ifself.close_endsandisinstance(self.stl_resolution,Dict):flag=0ifself.stl_resolution["e0"]!=self.stl_resolution["e2"]:print("edge 'e0' and 'e2' don't have same stl_resolution.")flag=1ifself.stl_resolution["e1"]!=self.stl_resolution["e3"]:print("edge 'e1' and 'e3' don't have same stl_resolution.")flag=1ifflag>0:raiseException(f"stl_resolution not compatible for close_end.")