Skip to content

Commit 264416d

Browse files
authored
Add new methods to get faces and edges largest and smallest elements (#1254)
* Changed return of Faces * Implemented methods to find biggest faces and edges and smallest one. Co-authored-by: maxcapodi78 <Shark78>
1 parent a8042e2 commit 264416d

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

_unittest/test_07_Object3D.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,13 @@ def test_03_FacePrimitive(self):
150150
for face in o_box2.faces:
151151
assert isinstance(face.is_on_bounding(), bool)
152152
assert len(o_box2.faces_on_bounding_box) == 3
153-
assert o_box2.face_closest_to_bounding_box in o_box2.faces_on_bounding_box
153+
assert o_box2.face_closest_to_bounding_box.id in [i.id for i in o_box2.faces_on_bounding_box]
154154
assert not o_sphere.faces[0].is_planar
155155
assert o_box.faces[0].is_planar
156+
assert isinstance(o_box.largest_face()[0], FacePrimitive)
157+
assert isinstance(o_box.smallest_face(2), list)
158+
assert isinstance(o_box.longest_edge()[0], EdgePrimitive)
159+
assert isinstance(o_box.shortest_edge()[0], EdgePrimitive)
156160

157161
def test_04_object_material_property_invalid(self):
158162
o_box = self.create_copper_box("Invalid1")

pyaedt/modeler/Object3d.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,12 +1270,12 @@ def faces_on_bounding_box(self):
12701270
12711271
Returns
12721272
-------
1273-
list
1273+
List of :class:`pyaedt.modeler.Object3d.FacePrimitive`
12741274
"""
12751275
f_list = []
12761276
for face in self.faces:
12771277
if face.is_on_bounding():
1278-
f_list.append(face.id)
1278+
f_list.append(face)
12791279
return f_list
12801280

12811281
@property
@@ -1284,7 +1284,7 @@ def face_closest_to_bounding_box(self):
12841284
12851285
Returns
12861286
-------
1287-
int
1287+
:class:`pyaedt.modeler.Object3d.FacePrimitive`
12881288
"""
12891289
b = [float(i) for i in list(self.m_Editor.GetModelBoundingBox())]
12901290
f_id = None
@@ -1303,10 +1303,72 @@ def face_closest_to_bounding_box(self):
13031303
)
13041304

13051305
if f_val and p_dist < f_val or not f_val:
1306-
f_id = face.id
1306+
f_id = face
13071307
f_val = p_dist
13081308
return f_id
13091309

1310+
@pyaedt_function_handler()
1311+
def largest_face(self, n=1):
1312+
"""Return only the face with the greatest area.
1313+
1314+
Returns
1315+
-------
1316+
List of :class:`pyaedt.modeler.Object3d.FacePrimitive`
1317+
"""
1318+
f = []
1319+
for face in self.faces:
1320+
f.append((face.area, face))
1321+
f.sort(key=lambda tup: tup[0], reverse=True)
1322+
f_sorted = [x for y, x in f]
1323+
return f_sorted[:n]
1324+
1325+
@pyaedt_function_handler()
1326+
def longest_edge(self, n=1):
1327+
"""Return only the edge with the greatest length.
1328+
1329+
Returns
1330+
-------
1331+
List of :class:`pyaedt.modeler.Object3d.EdgePrimitive`
1332+
"""
1333+
e = []
1334+
for edge in self.edges:
1335+
e.append((edge.length, edge))
1336+
e.sort(key=lambda tup: tup[0], reverse=True)
1337+
e_sorted = [x for y, x in e]
1338+
return e_sorted[:n]
1339+
1340+
@pyaedt_function_handler()
1341+
def smallest_face(self, n=1):
1342+
"""Return only the face with the smallest area.
1343+
1344+
Returns
1345+
-------
1346+
List of :class:`pyaedt.modeler.Object3d.FacePrimitive`
1347+
"""
1348+
f = []
1349+
for face in self.faces:
1350+
f.append((face.area, face))
1351+
f.sort(key=lambda tup: tup[0])
1352+
f_sorted = [x for y, x in f]
1353+
return f_sorted[:n]
1354+
1355+
@pyaedt_function_handler()
1356+
def shortest_edge(self, n=1):
1357+
"""Return only the edge with the smallest length.
1358+
1359+
Returns
1360+
-------
1361+
List of :class:`pyaedt.modeler.Object3d.EdgePrimitive`
1362+
"""
1363+
e = []
1364+
for edge in self.edges:
1365+
e.append((edge.length, edge))
1366+
e.sort(
1367+
key=lambda tup: tup[0],
1368+
)
1369+
e_sorted = [x for y, x in e]
1370+
return e_sorted[:n]
1371+
13101372
@property
13111373
def top_face_z(self):
13121374
"""Top face in the Z direction of the object.

0 commit comments

Comments
 (0)