Skip to content

Add new methods to get faces and edges largest and smallest elements #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion _unittest/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ def test_03_FacePrimitive(self):
for face in o_box2.faces:
assert isinstance(face.is_on_bounding(), bool)
assert len(o_box2.faces_on_bounding_box) == 3
assert o_box2.face_closest_to_bounding_box in o_box2.faces_on_bounding_box
assert o_box2.face_closest_to_bounding_box.id in [i.id for i in o_box2.faces_on_bounding_box]
assert not o_sphere.faces[0].is_planar
assert o_box.faces[0].is_planar
assert isinstance(o_box.largest_face()[0], FacePrimitive)
assert isinstance(o_box.smallest_face(2), list)
assert isinstance(o_box.longest_edge()[0], EdgePrimitive)
assert isinstance(o_box.shortest_edge()[0], EdgePrimitive)

def test_04_object_material_property_invalid(self):
o_box = self.create_copper_box("Invalid1")
Expand Down
70 changes: 66 additions & 4 deletions pyaedt/modeler/Object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,12 @@ def faces_on_bounding_box(self):

Returns
-------
list
List of :class:`pyaedt.modeler.Object3d.FacePrimitive`
"""
f_list = []
for face in self.faces:
if face.is_on_bounding():
f_list.append(face.id)
f_list.append(face)
return f_list

@property
Expand All @@ -1284,7 +1284,7 @@ def face_closest_to_bounding_box(self):

Returns
-------
int
:class:`pyaedt.modeler.Object3d.FacePrimitive`
"""
b = [float(i) for i in list(self.m_Editor.GetModelBoundingBox())]
f_id = None
Expand All @@ -1303,10 +1303,72 @@ def face_closest_to_bounding_box(self):
)

if f_val and p_dist < f_val or not f_val:
f_id = face.id
f_id = face
f_val = p_dist
return f_id

@pyaedt_function_handler()
def largest_face(self, n=1):
"""Return only the face with the greatest area.

Returns
-------
List of :class:`pyaedt.modeler.Object3d.FacePrimitive`
"""
f = []
for face in self.faces:
f.append((face.area, face))
f.sort(key=lambda tup: tup[0], reverse=True)
f_sorted = [x for y, x in f]
return f_sorted[:n]

@pyaedt_function_handler()
def longest_edge(self, n=1):
"""Return only the edge with the greatest length.

Returns
-------
List of :class:`pyaedt.modeler.Object3d.EdgePrimitive`
"""
e = []
for edge in self.edges:
e.append((edge.length, edge))
e.sort(key=lambda tup: tup[0], reverse=True)
e_sorted = [x for y, x in e]
return e_sorted[:n]

@pyaedt_function_handler()
def smallest_face(self, n=1):
"""Return only the face with the smallest area.

Returns
-------
List of :class:`pyaedt.modeler.Object3d.FacePrimitive`
"""
f = []
for face in self.faces:
f.append((face.area, face))
f.sort(key=lambda tup: tup[0])
f_sorted = [x for y, x in f]
return f_sorted[:n]

@pyaedt_function_handler()
def shortest_edge(self, n=1):
"""Return only the edge with the smallest length.

Returns
-------
List of :class:`pyaedt.modeler.Object3d.EdgePrimitive`
"""
e = []
for edge in self.edges:
e.append((edge.length, edge))
e.sort(
key=lambda tup: tup[0],
)
e_sorted = [x for y, x in e]
return e_sorted[:n]

@property
def top_face_z(self):
"""Top face in the Z direction of the object.
Expand Down