Skip to content

Commit b753d5e

Browse files
jacobrkerstetterpre-commit-ci[bot]pyansys-ci-botRobPasMue
authored
feat: offset faces set radius implementation + testing (#1769)
Co-authored-by: jkerstet <jacob.kerstetter@ansys.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com>
1 parent a838b77 commit b753d5e

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

doc/changelog.d/1769.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
offset faces set radius implementation + testing

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
FullFilletRequest,
3838
ModifyCircularPatternRequest,
3939
ModifyLinearPatternRequest,
40+
OffsetFacesSetRadiusRequest,
4041
PatternRequest,
4142
RenameObjectRequest,
4243
ReplaceFaceRequest,
@@ -1212,3 +1213,55 @@ def get_round_info(self, face: "Face") -> tuple[bool, Real]:
12121213
result = self._commands_stub.GetRoundInfo(RoundInfoRequest(face=face._grpc_id))
12131214

12141215
return (result.along_u, result.radius)
1216+
1217+
@protect_grpc
1218+
@min_backend_version(25, 2, 0)
1219+
def offset_faces_set_radius(
1220+
self,
1221+
faces: Union["Face", list["Face"]],
1222+
radius: Real,
1223+
copy: bool = False,
1224+
offset_mode: OffsetMode = OffsetMode.IGNORE_RELATIONSHIPS,
1225+
extrude_type: ExtrudeType = ExtrudeType.FORCE_INDEPENDENT,
1226+
) -> bool:
1227+
"""Offset faces with a radius.
1228+
1229+
Parameters
1230+
----------
1231+
faces : Face | list[Face]
1232+
Faces to offset.
1233+
radius : Real
1234+
Radius of the offset.
1235+
copy : bool, default: False
1236+
Copy the face and move it instead of offsetting the original face if ``True``.
1237+
offset_mode : OffsetMode, default: OffsetMode.MOVE_FACES_TOGETHER
1238+
Mode of how to handle offset relationships.
1239+
extrude_type : ExtrudeType, default: ExtrudeType.FORCE_INDEPENDENT
1240+
Type of extrusion to be performed.
1241+
1242+
Returns
1243+
-------
1244+
bool
1245+
``True`` when successful, ``False`` when failed.
1246+
"""
1247+
from ansys.geometry.core.designer.face import Face
1248+
1249+
faces: list[Face] = faces if isinstance(faces, list) else [faces]
1250+
1251+
check_type_all_elements_in_iterable(faces, Face)
1252+
check_is_float_int(radius, "radius")
1253+
1254+
for face in faces:
1255+
face.body._reset_tessellation_cache()
1256+
1257+
result = self._commands_stub.OffsetFacesSetRadius(
1258+
OffsetFacesSetRadiusRequest(
1259+
faces=[face._grpc_id for face in faces],
1260+
radius=radius,
1261+
copy=copy,
1262+
offset_mode=offset_mode.value,
1263+
extrude_type=extrude_type.value,
1264+
)
1265+
)
1266+
1267+
return result.success

tests/integration/test_geometry_commands.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,3 +990,22 @@ def test_update_fill_pattern_on_imported_geometry_faces(modeler: Modeler):
990990
assert design.bodies[0].volume.m == pytest.approx(
991991
Quantity(4.70663693e-6, UNITS.m**3).m, rel=1e-6, abs=1e-8
992992
)
993+
994+
995+
def test_offset_face_set_radius(modeler: Modeler):
996+
"""Test offsetting a face with a set radius"""
997+
design = modeler.create_design("offset_face_set_radius")
998+
box = design.extrude_sketch("box", Sketch().box(Point2D([0, 0]), 2, 2), 2)
999+
assert len(box.faces) == 6
1000+
assert box.volume.m == pytest.approx(Quantity(8, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1001+
1002+
# Add a hole to a box
1003+
hole = design.extrude_sketch("hole", Sketch().circle(Point2D([0, 0]), 0.5), 2)
1004+
box.subtract(hole)
1005+
assert box.volume.m == pytest.approx(Quantity(6.4292, UNITS.m**3).m, rel=1e-6, abs=1e-8)
1006+
1007+
# Change radius of hole
1008+
success = modeler.geometry_commands.offset_faces_set_radius(box.faces[6], 0.25)
1009+
assert success
1010+
1011+
assert box.volume.m == pytest.approx(Quantity(7.6073, UNITS.m**3).m, rel=1e-6, abs=1e-8)

0 commit comments

Comments
 (0)