From 8e4dc4827716ed7f26858d8e3ef04f22501b484e Mon Sep 17 00:00:00 2001 From: PProfizi Date: Wed, 30 Apr 2025 13:52:53 +0200 Subject: [PATCH] Fix geometry_factory.py::create_plane_from_point_and_line and update testing --- src/ansys/dpf/core/geometry_factory.py | 9 +++++++-- tests/test_geometry.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ansys/dpf/core/geometry_factory.py b/src/ansys/dpf/core/geometry_factory.py index ac042505abb..13b4a6019df 100644 --- a/src/ansys/dpf/core/geometry_factory.py +++ b/src/ansys/dpf/core/geometry_factory.py @@ -312,6 +312,8 @@ def create_plane_from_point_and_line( ): """Create plane from point and line. + Raises a ValueError if the point is on the line. + Parameters ---------- point : list, array, Points @@ -362,9 +364,12 @@ def create_plane_from_point_and_line( # Get center and normal from point and vector coords = [line[0], line[1], point] - vects = [line, [line[0], point]] + normal = get_normal_direction_from_coords(coords) + if any(np.isnan(x) for x in normal) or (max(normal) == min(normal) == 0): + raise ValueError( + "create_plane_from_point_and_line: cannot create a plane from aligned point and line." + ) center = get_center_from_coords(coords) - normal = get_cross_product(vects) return Plane(center, normal, width, height, n_cells_x, n_cells_y, server) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index d7d5dffd28c..9e16fae7ae6 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -235,9 +235,14 @@ def test_create_plane_from_lines(line1, line2): plane_point_line_data = [ - ([0.0, 0.0, 0.0], [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]), - (lambda: Points([0.0, 0.0, 0.0]), [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]), - ([0.0, 0.0, 0.0], lambda: Line([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])), + ([1.0, 0.0, 0.0], [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]), + (lambda: Points([1.0, 0.0, 0.0]), [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]), + ([1.0, 0.0, 0.0], lambda: Line([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])), + pytest.param( + lambda: [0.0, 0.0, 0.0], + [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], + marks=pytest.mark.xfail(strict=True, raises=ValueError), + ), pytest.param( lambda: Points([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]), [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]],