Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface subclass: plane, and tests #293

Merged
merged 8 commits into from
Aug 24, 2023
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
1 change: 1 addition & 0 deletions elastica/surface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__doc__ = """Surface classes"""
from elastica.surface.surface_base import SurfaceBase
from elastica.surface.plane import Plane
31 changes: 31 additions & 0 deletions elastica/surface/plane.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
__doc__ = """plane surface class"""

from elastica.surface.surface_base import SurfaceBase
import numpy as np
from numpy.testing import assert_allclose
from elastica.utils import Tolerance


class Plane(SurfaceBase):
def __init__(self, plane_origin: np.ndarray, plane_normal: np.ndarray):
"""
Plane surface initializer.

Parameters
----------
plane_origin: np.ndarray
Origin of the plane.
Expect (3,1)-shaped array.
plane_normal: np.ndarray
The normal vector of the plane, must be normalized.
Expect (3,1)-shaped array.
"""

assert_allclose(
np.linalg.norm(plane_normal),
1,
atol=Tolerance.atol(),
err_msg="plane normal is not a unit vector",
)
self.normal = np.asarray(plane_normal).reshape(3)
self.origin = np.asarray(plane_origin).reshape(3, 1)
41 changes: 41 additions & 0 deletions tests/test_surface/test_plane.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
__doc__ = """Tests for plane surface class"""
import numpy as np
from numpy.testing import assert_allclose
from elastica.utils import Tolerance
from elastica.surface import Plane
import pytest


# tests Initialisation of plane
def test_plane_initialization():
"""
This test case is for testing initialization of rigid sphere and it checks the
validity of the members of sphere class.

Returns
-------

"""
# setting up test params
plane_origin = np.random.rand(3).reshape(3, 1)
plane_normal_direction = np.random.rand(3).reshape(3)
plane_normal = plane_normal_direction / np.linalg.norm(plane_normal_direction)

test_plane = Plane(plane_origin, plane_normal)
# checking plane origin
assert_allclose(
test_plane.origin,
plane_origin,
atol=Tolerance.atol(),
)

# checking plane normal
assert_allclose(test_plane.normal, plane_normal, atol=Tolerance.atol())

# check unnormalized error message
invalid_plane_normal = np.zeros(
3,
)
with pytest.raises(AssertionError) as excinfo:
test_plane = Plane(plane_origin, invalid_plane_normal)
assert "plane normal is not a unit vector" in str(excinfo.value)