Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ansys/dpf/core/geometry_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@
):
"""Create plane from point and line.

Raises a ValueError if the point is on the line.

Parameters
----------
point : list, array, Points
Expand Down Expand Up @@ -362,9 +364,12 @@

# 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(

Check warning on line 369 in src/ansys/dpf/core/geometry_factory.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/geometry_factory.py#L367-L369

Added lines #L367 - L369 were not covered by tests
"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)


Expand Down
11 changes: 8 additions & 3 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
Loading