Skip to content

Commit 00e83e1

Browse files
committed
Merge branch 'feat/inspect_repair_results' of https://github.com/ansys/pyansys-geometry into feat/inspect_repair_results
2 parents 97b9876 + 08dc2c6 commit 00e83e1

File tree

7 files changed

+85
-33
lines changed

7 files changed

+85
-33
lines changed

doc/changelog.d/1725.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
revert boolean ops logic and hold-off on commands-based implementation (temporarily)

doc/changelog.d/1742.dependencies.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bump jupytext from 1.16.6 to 1.16.7 in the docs-deps group

doc/changelog.d/1743.dependencies.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bump ansys-api-geometry from 0.4.36 to 0.4.37

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
]
2525

2626
dependencies = [
27-
"ansys-api-geometry==0.4.36",
27+
"ansys-api-geometry==0.4.37",
2828
"ansys-tools-path>=0.3,<1",
2929
"ansys-tools-visualization-interface>=0.2.6,<1",
3030
"attrs!=24.3.0",
@@ -89,7 +89,7 @@ doc = [
8989
"grpcio-health-checking==1.67.1",
9090
"ipyvtklink==0.2.3",
9191
"jupyter_sphinx==0.5.3",
92-
"jupytext==1.16.6",
92+
"jupytext==1.16.7",
9393
"myst-parser==4.0.0",
9494
"nbconvert==7.16.6",
9595
"nbsphinx==0.9.6",

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@
9696

9797
from ansys.geometry.core.designer.component import Component
9898

99+
# TODO: Temporary fix for boolean operations
100+
# This is a temporary fix for the boolean operations issue. The issue is that the
101+
# boolean operations are not working as expected with command-based operations. The
102+
# goal is to fix this issue in the future.
103+
# https://github.com/ansys/pyansys-geometry/issues/1733
104+
__TEMPORARY_BOOL_OPS_FIX__ = (99, 0, 0)
105+
99106

100107
@unique
101108
class MidSurfaceOffsetType(Enum):
@@ -1764,23 +1771,23 @@ def plot( # noqa: D102
17641771
pl.show(screenshot=screenshot, **plotting_options)
17651772

17661773
def intersect(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False) -> None: # noqa: D102
1767-
if self._template._grpc_client.backend_version < (25, 2, 0):
1774+
if self._template._grpc_client.backend_version < __TEMPORARY_BOOL_OPS_FIX__:
17681775
self.__generic_boolean_op(other, keep_other, "intersect", "bodies do not intersect")
17691776
else:
17701777
self.__generic_boolean_command(
17711778
other, keep_other, "intersect", "bodies do not intersect"
17721779
)
17731780

17741781
def subtract(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False) -> None: # noqa: D102
1775-
if self._template._grpc_client.backend_version < (25, 2, 0):
1782+
if self._template._grpc_client.backend_version < __TEMPORARY_BOOL_OPS_FIX__:
17761783
self.__generic_boolean_op(other, keep_other, "subtract", "empty (complete) subtraction")
17771784
else:
17781785
self.__generic_boolean_command(
17791786
other, keep_other, "subtract", "empty (complete) subtraction"
17801787
)
17811788

17821789
def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False) -> None: # noqa: D102
1783-
if self._template._grpc_client.backend_version < (25, 2, 0):
1790+
if self._template._grpc_client.backend_version < __TEMPORARY_BOOL_OPS_FIX__:
17841791
self.__generic_boolean_op(other, keep_other, "unite", "union operation failed")
17851792
else:
17861793
self.__generic_boolean_command(other, False, "unite", "union operation failed")

tests/integration/test_design.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,20 +1675,20 @@ def test_boolean_body_operations(modeler: Modeler):
16751675
# 1.b.ii
16761676
copy1 = body1.copy(comp1, "Copy1")
16771677
copy1a = body1.copy(comp1, "Copy1a")
1678-
copy1.subtract(copy1a)
1678+
with pytest.raises(ValueError):
1679+
copy1.subtract(copy1a)
16791680

16801681
assert copy1.is_alive
1681-
assert not copy1a.is_alive
1682+
assert copy1a.is_alive
16821683

16831684
# 1.b.iii
16841685
copy1 = body1.copy(comp1, "Copy1")
16851686
copy3 = body3.copy(comp3, "Copy3")
1686-
with pytest.raises(ValueError):
1687-
copy1.subtract(copy3)
1687+
copy1.subtract(copy3)
16881688

16891689
assert Accuracy.length_is_equal(copy1.volume.m, 1)
16901690
assert copy1.volume
1691-
assert copy3.is_alive
1691+
assert not copy3.is_alive
16921692

16931693
# 1.c.i.x
16941694
copy1 = body1.copy(comp1, "Copy1")
@@ -1711,10 +1711,9 @@ def test_boolean_body_operations(modeler: Modeler):
17111711
# 1.c.ii
17121712
copy1 = body1.copy(comp1, "Copy1")
17131713
copy3 = body3.copy(comp3, "Copy3")
1714-
with pytest.raises(ValueError):
1715-
copy1.unite(copy3)
1714+
copy1.unite(copy3)
17161715

1717-
assert copy3.is_alive
1716+
assert not copy3.is_alive
17181717
assert body3.is_alive
17191718
assert Accuracy.length_is_equal(copy1.volume.m, 1)
17201719

@@ -1785,20 +1784,20 @@ def test_boolean_body_operations(modeler: Modeler):
17851784
# 2.b.ii
17861785
copy1 = body1.copy(comp1_i, "Copy1")
17871786
copy1a = body1.copy(comp1_i, "Copy1a")
1788-
copy1.subtract(copy1a)
1787+
with pytest.raises(ValueError):
1788+
copy1.subtract(copy1a)
17891789

17901790
assert copy1.is_alive
1791-
assert not copy1a.is_alive
1791+
assert copy1a.is_alive
17921792

17931793
# 2.b.iii
17941794
copy1 = body1.copy(comp1_i, "Copy1")
17951795
copy3 = body3.copy(comp3_i, "Copy3")
1796-
with pytest.raises(ValueError):
1797-
copy1.subtract(copy3)
1796+
copy1.subtract(copy3)
17981797

17991798
assert Accuracy.length_is_equal(copy1.volume.m, 1)
18001799
assert copy1.volume
1801-
assert copy3.is_alive
1800+
assert not copy3.is_alive
18021801

18031802
# 2.c.i.x
18041803
copy1 = body1.copy(comp1_i, "Copy1")
@@ -1821,10 +1820,9 @@ def test_boolean_body_operations(modeler: Modeler):
18211820
# 2.c.ii
18221821
copy1 = body1.copy(comp1_i, "Copy1")
18231822
copy3 = body3.copy(comp3_i, "Copy3")
1824-
with pytest.raises(ValueError):
1825-
copy1.unite(copy3)
1823+
copy1.unite(copy3)
18261824

1827-
assert copy3.is_alive
1825+
assert not copy3.is_alive
18281826
assert body3.is_alive
18291827
assert Accuracy.length_is_equal(copy1.volume.m, 1)
18301828

@@ -1921,26 +1919,21 @@ def test_bool_operations_with_keep_other(modeler: Modeler):
19211919
assert len(comp3.bodies) == 1
19221920

19231921
# ---- Verify unite operation ----
1924-
body1.unite([body2, body3])
1922+
body1.unite([body2, body3], keep_other=True)
19251923

1926-
assert body1.is_alive
1927-
assert not body2.is_alive
1924+
assert body2.is_alive
1925+
assert body3.is_alive
19281926
assert len(comp1.bodies) == 1
1929-
assert len(comp2.bodies) == 0
1930-
assert len(comp3.bodies) == 0
1927+
assert len(comp2.bodies) == 1
1928+
assert len(comp3.bodies) == 1
19311929

19321930
# ---- Verify intersect operation ----
1933-
comp2 = design.add_component("Comp2")
1934-
comp3 = design.add_component("Comp3")
1935-
body1 = comp1.extrude_sketch("Body1", Sketch().box(Point2D([0, 0]), 1, 1), 1)
1936-
body2 = comp2.extrude_sketch("Body2", Sketch().box(Point2D([0.5, 0]), 1, 1), 1)
1937-
body3 = comp3.extrude_sketch("Body3", Sketch().box(Point2D([5, 0]), 1, 1), 1)
1938-
body1.intersect([body2, body3], keep_other=True)
1931+
body1.intersect(body2, keep_other=True)
19391932

19401933
assert body1.is_alive
19411934
assert body2.is_alive
19421935
assert body3.is_alive
1943-
assert len(comp1.bodies) == 2
1936+
assert len(comp1.bodies) == 1
19441937
assert len(comp2.bodies) == 1
19451938
assert len(comp3.bodies) == 1
19461939

tests/integration/test_issues.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pathlib import Path
2525

2626
import numpy as np
27+
import pytest
2728

2829
from ansys.geometry.core.math import (
2930
UNITVECTOR3D_X,
@@ -139,6 +140,11 @@ def test_issue_1304_arc_sketch_creation():
139140
DEFAULT_UNITS.LENGTH = UNITS.meter
140141

141142

143+
# TODO: Temporary fix for boolean operations
144+
# Issue had to be skipped due to the fact that the intersect operation is not working as expected
145+
# when using command-based boolean operations.
146+
# https://github.com/ansys/pyansys-geometry/issues/1733
147+
@pytest.mark.skip(reason="This test is not working as expected")
142148
def test_issue_1192_temp_body_on_empty_intersect(modeler: Modeler):
143149
"""Test demonstrating the issue when intersecting two bodies that do not intersect
144150
and the empty temporal body that gets created."""
@@ -224,3 +230,46 @@ def test_issue_1309_revolve_operation_with_coincident_origins(modeler: Modeler):
224230
)
225231

226232
assert revolved_body.name == "toroid"
233+
234+
235+
def test_issue_1724_intersect_failures(modeler: Modeler):
236+
"""Test that intersecting two bodies that overlap does not crash the program.
237+
238+
For more info see
239+
https://github.com/ansys/pyansys-geometry/issues/1724
240+
"""
241+
wx = 10
242+
wy = 10
243+
wz = 2
244+
radius = 1
245+
unit = DEFAULT_UNITS.LENGTH
246+
247+
design = modeler.create_design("Test")
248+
249+
start_at = Point3D([wx / 2, wy / 2, 0.0], unit=unit)
250+
251+
plane = Plane(
252+
start_at,
253+
UNITVECTOR3D_X,
254+
UNITVECTOR3D_Y,
255+
)
256+
box_plane = Sketch(plane)
257+
box_plane.box(Point2D([0.0, 0.0], unit=unit), width=wx, height=wy)
258+
259+
box = design.extrude_sketch("box", box_plane, wz)
260+
261+
point = Point3D([wx / 2, wx / 2, 0.0], unit=unit)
262+
plane = Plane(point, UNITVECTOR3D_X, UNITVECTOR3D_Y)
263+
sketch_cylinder = Sketch(plane)
264+
sketch_cylinder.circle(Point2D([0.0, 0.0], unit=unit), radius=radius)
265+
cylinder = design.extrude_sketch("cylinder", sketch_cylinder, wz - 0.1)
266+
267+
# Request the intersection
268+
cylinder.intersect(box)
269+
270+
# Only the cylinder should be present
271+
assert len(design.bodies) == 1
272+
assert design.bodies[0].name == "cylinder"
273+
274+
# Verify that the volume of the cylinder is the same (the intersect is the same as the cylinder)
275+
assert np.isclose(design.bodies[0].volume.m, np.pi * radius**2 * (wz - 0.1))

0 commit comments

Comments
 (0)