diff --git a/lyceanem/geometry/test_geometry.py b/lyceanem/geometry/test_geometry.py new file mode 100644 index 0000000..052d7ac --- /dev/null +++ b/lyceanem/geometry/test_geometry.py @@ -0,0 +1,47 @@ +import pytest +import numpy as np +import meshio +from . import geometry_functions_meshio as GF +def are_meshes_equal(mesh1, mesh2, rtol=1e-5): + # Check vertices + assert np.allclose(mesh1.points, mesh2.points, rtol=rtol) + + + # Check cells + if len(mesh1.cells) >0: + + assert np.allclose(mesh1.cells[0].data, mesh2.cells[0].data) + + for i in mesh1.point_data: + assert np.allclose(mesh1.point_data[i], mesh2.point_data[i]) + + for i in mesh1.cell_data: + assert np.allclose(mesh1.cell_data[i], mesh2.cell_data[i]) + + + return True + +def test_tri_areas(): + refrence = np.load('areas.npy') + input = meshio.read('receive_horn.ply') + result = GF.tri_areas(input) + assert np.allclose(result, refrence) + +def test_tri_centroids(): + refrence = np.load('centroid_numpy.npy') + refrenece_mesh = meshio.read('centroid_mesh.ply') + input = meshio.read('receive_horn.ply') + result_numpy, result_mesh = GF.tri_centroids(input) + assert np.allclose(result_numpy, refrence) + assert are_meshes_equal(result_mesh, refrenece_mesh) +def test_mesh_rotate(): + refrence = meshio.read('rotated_recieve.ply') + input = meshio.read('receive_horn.ply') + rotation_vector1 = np.radians(np.asarray([90.0, 0.0, 0.0])) + centre = np.array([1.0, 1.0, 1.0]) + + + result = GF.mesh_rotate(input, rotation_vector1, centre) + + assert are_meshes_equal(result, refrence) +