-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for converted functions bar mesh conversion
mesh conversion will be tested indirectly by other tests- come back later for additional test
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|