@@ -18,9 +18,11 @@ class DFVertex:
1818 """
1919 This class represents a vertex, a simple container with 3 coordinates
2020 """
21- x : float
22- y : float
23- z : float
21+
22+ x : float
23+ y : float
24+ z : float
25+
2426 def __post_init__ (self ):
2527 self .x = self .x or 0.0
2628 self .y = self .y or 0.0
@@ -61,46 +63,41 @@ class DFFace:
6163 """
6264 This class represents a face, in diffCheck, a face is a collection of vertices.
6365 """
66+
6467 # just as breps a first outer loop and then inner loops of DFVertices
65- all_loops : typing .List [typing .List [DFVertex ]]
66- joint_id : int
68+ all_loops : typing .List [typing .List [DFVertex ]]
69+ joint_id : int = None
70+
6771 def __post_init__ (self ):
6872 if len (self .all_loops [0 ]) < 3 :
6973 raise ValueError ("A face must have at least 3 vertices" )
70- self .all_loops = self .all_loops or []
74+ self .all_loops = self .all_loops
7175
72- self .joint_id = self .joint_id or None
76+ self .joint_id = self .joint_id
7377 self .__is_joint = False
7478 self .__id = uuid .uuid4 ().int
7579
7680 def __repr__ (self ):
7781 return f"Face id: { len (self .id )} , IsJoint: { self .is_joint } Loops: { len (self .all_loops )} "
7882
7983 def __hash__ (self ):
80- outer_loop = tuple (tuple (vertex .__dict__ .values ()) for vertex in self .all_loops [0 ])
81- inner_loops = tuple (tuple (vertex .__dict__ .values ()) for loop in self .all_loops [1 :] for vertex in loop )
84+ outer_loop = tuple (
85+ tuple (vertex .__dict__ .values ()) for vertex in self .all_loops [0 ]
86+ )
87+ inner_loops = tuple (
88+ tuple (vertex .__dict__ .values ())
89+ for loop in self .all_loops [1 :]
90+ for vertex in loop
91+ )
8292 return hash ((outer_loop , inner_loops ))
8393
8494 def __eq__ (self , other ):
8595 if isinstance (other , DFFace ):
8696 return self .all_loops == other .all_loops
8797 return False
8898
89- @staticmethod
90- def compute_mass_center (face : rg .BrepFace ) -> rg .Point3d :
91- """
92- Compute the mass center of a face
93-
94- :param face: The face to compute the mass center from
95- :return mass_center: The mass center of the face
96- """
97- amp = rg .AreaMassProperties .Compute (face )
98- if amp :
99- return amp .Centroid
100- return None
101-
10299 @classmethod
103- def from_brep (cls , brep_face : rg .BrepFace , joint_id : int = None ):
100+ def from_brep (cls , brep_face : rg .BrepFace , joint_id : int = None ):
104101 """
105102 Create a DFFace from a Rhino Brep face
106103
@@ -135,12 +132,16 @@ def to_brep(self):
135132 brep_curves = []
136133
137134 for loop in self .all_loops :
138- inner_vertices = [rg .Point3d (vertex .x , vertex .y , vertex .z ) for vertex in loop ]
135+ inner_vertices = [
136+ rg .Point3d (vertex .x , vertex .y , vertex .z ) for vertex in loop
137+ ]
139138 inner_polyline = rg .Polyline (inner_vertices )
140139 inner_curve = inner_polyline .ToNurbsCurve ()
141140 brep_curves .append (inner_curve )
142141
143- brep = rg .Brep .CreatePlanarBreps (brep_curves , Rhino .RhinoDoc .ActiveDoc .ModelAbsoluteTolerance )[0 ]
142+ brep = rg .Brep .CreatePlanarBreps (
143+ brep_curves , Rhino .RhinoDoc .ActiveDoc .ModelAbsoluteTolerance
144+ )[0 ]
144145
145146 return brep
146147
@@ -171,8 +172,10 @@ class DFBeam:
171172 """
172173 This class represents a beam, in diffCheck, a beam is a collection of faces
173174 """
174- name : str
175- faces : typing .List [DFFace ]
175+
176+ name : str
177+ faces : typing .List [DFFace ]
178+
176179 def __post_init__ (self ):
177180 self .name = self .name or "Unnamed Beam"
178181 self .faces = self .faces or []
@@ -187,8 +190,11 @@ def from_brep(cls, brep):
187190 Create a DFBeam from a RhinoBrep object.
188191 It also removes duplicates and creates a list of unique faces.
189192 """
190- faces = diffCheck .df_joint_detector .JointDetector (brep ).run ()
191- faces = list (set (faces ))
193+ faces : typing .List [DFFace ] = []
194+ data_faces = diffCheck .df_joint_detector .JointDetector (brep ).run ()
195+ for data in data_faces :
196+ face = DFFace .from_brep (data [0 ], data [1 ])
197+ faces .append (face )
192198 beam = cls ("Beam" , faces )
193199 return beam
194200
@@ -213,8 +219,10 @@ class DFAssembly:
213219 """
214220 This class represents an assembly of beams
215221 """
216- beams : typing .List [DFBeam ]
217- name : str
222+
223+ beams : typing .List [DFBeam ]
224+ name : str
225+
218226 def __post_init__ (self ):
219227 self .beams = self .beams
220228 self .name = self .name or "Unnamed Assembly"
@@ -256,7 +264,9 @@ def to_xml(self):
256264 mesh = face .to_mesh ()
257265 mesh_vertices = mesh .Vertices
258266 for idx , vertex in enumerate (mesh_vertices ):
259- facerhmesh_vertex_elem = ET .SubElement (facerhmesh_elem , "RhMeshVertex" )
267+ facerhmesh_vertex_elem = ET .SubElement (
268+ facerhmesh_elem , "RhMeshVertex"
269+ )
260270 facerhmesh_vertex_elem .set ("x" , str (vertex .X ))
261271 facerhmesh_vertex_elem .set ("y" , str (vertex .Y ))
262272 facerhmesh_vertex_elem .set ("z" , str (vertex .Z ))
@@ -269,13 +279,13 @@ def to_xml(self):
269279 facerhmesh_face_elem .set ("v4" , str (face .D ))
270280
271281 tree = ET .ElementTree (root )
272- xml_string = ET .tostring (root , encoding = ' unicode' )
282+ xml_string = ET .tostring (root , encoding = " unicode" )
273283 dom = parseString (xml_string )
274284 pretty_xml = dom .toprettyxml ()
275285
276286 return pretty_xml
277287
278- def dump_xml (self , pretty_xml : str , dir : str ):
288+ def dump_xml (self , pretty_xml : str , dir : str ):
279289 """
280290 Dump the pretty XML to a file
281291
@@ -298,4 +308,4 @@ def all_joint_faces(self):
298308 def all_side_faces (self ):
299309 for beam in self .beams :
300310 self ._all_sidefaces .extend (beam .side_faces )
301- return self ._all_sidefaces
311+ return self ._all_sidefaces
0 commit comments