From b499d2c621e8c6ec0867dbd821bf822127da4538 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:00:25 +0200 Subject: [PATCH 1/4] fix: mathematical approximations leading to potential issues - allowing rounding --- src/ansys/geometry/core/math/misc.py | 4 +++- src/ansys/geometry/core/sketch/sketch.py | 5 +++++ tests/integration/test_issues.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/math/misc.py b/src/ansys/geometry/core/math/misc.py index b4ff02c2e9..a17fc515e1 100644 --- a/src/ansys/geometry/core/math/misc.py +++ b/src/ansys/geometry/core/math/misc.py @@ -80,7 +80,9 @@ def get_two_circle_intersections( return None else: a = (r0**2 - r1**2 + d**2) / (2 * d) - h = np.sqrt(r0**2 - a**2) + # abs is used to ensure non-negative value - close to zero + # conditions might occur if circles are nearly tangent + h = np.sqrt(abs(r0**2 - a**2)) x2 = x0 + a * (x1 - x0) / d y2 = y0 + a * (y1 - y0) / d diff --git a/src/ansys/geometry/core/sketch/sketch.py b/src/ansys/geometry/core/sketch/sketch.py index 9ff19e50cb..24c09441c1 100644 --- a/src/ansys/geometry/core/sketch/sketch.py +++ b/src/ansys/geometry/core/sketch/sketch.py @@ -516,6 +516,11 @@ def arc_from_start_end_and_radius( ------- Sketch Revised sketch state ready for further sketch actions. + + Warning + ------- + This method may not produce the exact same radius, depending on the input parameters. + This is due to the mathematical approximations involved in the arc creation. """ arc = Arc.from_start_end_and_radius( start, diff --git a/tests/integration/test_issues.py b/tests/integration/test_issues.py index 9c4a0898fc..4d3089b583 100644 --- a/tests/integration/test_issues.py +++ b/tests/integration/test_issues.py @@ -40,6 +40,7 @@ from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Angle, Distance from ansys.geometry.core.modeler import Modeler from ansys.geometry.core.sketch import Sketch +from ansys.geometry.core.sketch.arc import Arc from ansys.geometry.core.tools import ( MeasurementTools, PrepareTools, @@ -371,3 +372,25 @@ def test_issue_2184_prevent_raw_instantiation_of_tools_and_commands(): GeometryRuntimeError, match="GeometryCommands should not be instantiated directly" ): GeometryCommands(None) + + +def test_issue_2074_rounding_math_errors(): + """Test that rounding errors in math operations do not cause issues. + + For more info see + https://github.com/ansys/pyansys-geometry/issues/2074 + """ + sketch1 = Sketch() + width = 7 + start = Point2D([width / 2, 0], UNITS.mm) + end = Point2D([-width / 2, 0], UNITS.mm) + radius = width / 2 * UNITS.mm + sketch1.arc_from_start_end_and_radius(start, end, radius) + + arc: Arc = sketch1.edges[-1] + + assert arc.center is not None + assert np.allclose(arc.center, Point2D([0, 0], UNITS.mm)) + assert np.isclose(arc.radius.to_base_units().m, radius.to_base_units().m) + assert arc.start == start + assert arc.end == end From 57b35b61bcb16fbcdcaa6f64d2e19a7698d0750e Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:00:41 +0200 Subject: [PATCH 2/4] fix: issue --- src/ansys/geometry/core/sketch/sketch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ansys/geometry/core/sketch/sketch.py b/src/ansys/geometry/core/sketch/sketch.py index 24c09441c1..ca873c9057 100644 --- a/src/ansys/geometry/core/sketch/sketch.py +++ b/src/ansys/geometry/core/sketch/sketch.py @@ -516,9 +516,9 @@ def arc_from_start_end_and_radius( ------- Sketch Revised sketch state ready for further sketch actions. - - Warning - ------- + + Warnings + -------- This method may not produce the exact same radius, depending on the input parameters. This is due to the mathematical approximations involved in the arc creation. """ From 1ed6937f8a95099d7ba970c97d0c4d894e9ab93f Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:00:56 +0200 Subject: [PATCH 3/4] fix: issue --- src/ansys/geometry/core/sketch/sketch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/geometry/core/sketch/sketch.py b/src/ansys/geometry/core/sketch/sketch.py index ca873c9057..d211533970 100644 --- a/src/ansys/geometry/core/sketch/sketch.py +++ b/src/ansys/geometry/core/sketch/sketch.py @@ -516,7 +516,7 @@ def arc_from_start_end_and_radius( ------- Sketch Revised sketch state ready for further sketch actions. - + Warnings -------- This method may not produce the exact same radius, depending on the input parameters. From 6a67deb78c2618f18b73e3d4016b23eaa8d0f5ad Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Thu, 21 Aug 2025 15:04:01 +0000 Subject: [PATCH 4/4] chore: adding changelog file 2190.fixed.md [dependabot-skip] --- doc/changelog.d/2190.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/2190.fixed.md diff --git a/doc/changelog.d/2190.fixed.md b/doc/changelog.d/2190.fixed.md new file mode 100644 index 0000000000..c99134d09f --- /dev/null +++ b/doc/changelog.d/2190.fixed.md @@ -0,0 +1 @@ +Mathematical approximations leading to potential issues - allowing rounding