Skip to content

Commit 5baa7b4

Browse files
committed
Fix geometry_factory.py::create_plane_from_point_and_line and update testing
1 parent ffa9011 commit 5baa7b4

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/ansys/dpf/core/geometry_factory.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ def create_plane_from_point_and_line(
312312
):
313313
"""Create plane from point and line.
314314
315+
Raises a ValueError if the point is on the line.
316+
315317
Parameters
316318
----------
317319
point : list, array, Points
@@ -362,9 +364,12 @@ def create_plane_from_point_and_line(
362364

363365
# Get center and normal from point and vector
364366
coords = [line[0], line[1], point]
365-
vects = [line, [line[0], point]]
367+
normal = get_normal_direction_from_coords(coords)
368+
if any(np.isnan(x) for x in normal) or (max(normal) == min(normal) == 0):
369+
raise ValueError(
370+
"create_plane_from_point_and_line: cannot create a plane from aligned point and line."
371+
)
366372
center = get_center_from_coords(coords)
367-
normal = get_cross_product(vects)
368373
return Plane(center, normal, width, height, n_cells_x, n_cells_y, server)
369374

370375

tests/test_geometry.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,14 @@ def test_create_plane_from_lines(line1, line2):
235235

236236

237237
plane_point_line_data = [
238-
([0.0, 0.0, 0.0], [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]),
239-
(lambda: Points([0.0, 0.0, 0.0]), [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]),
240-
([0.0, 0.0, 0.0], lambda: Line([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])),
238+
([1.0, 0.0, 0.0], [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]),
239+
(lambda: Points([1.0, 0.0, 0.0]), [[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]]),
240+
([1.0, 0.0, 0.0], lambda: Line([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])),
241+
pytest.param(
242+
lambda: [0.0, 0.0, 0.0],
243+
[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]],
244+
marks=pytest.mark.xfail(strict=True, raises=ValueError),
245+
),
241246
pytest.param(
242247
lambda: Points([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]),
243248
[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]],

0 commit comments

Comments
 (0)