From fc4d096f392ae4631ab83dd0f368fa9f6711e18f Mon Sep 17 00:00:00 2001 From: MaNyh <nyhuis@tfd.uni-hannover.de> Date: Fri, 10 Dec 2021 10:47:04 +0100 Subject: [PATCH] more tests more tests --- ntrfc/utils/math/vectorcalc.py | 22 +++++++-------- tests/test_ntrfc_math.py | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/ntrfc/utils/math/vectorcalc.py b/ntrfc/utils/math/vectorcalc.py index e7b2bf43..91ca006b 100644 --- a/ntrfc/utils/math/vectorcalc.py +++ b/ntrfc/utils/math/vectorcalc.py @@ -32,6 +32,11 @@ def calc_largedistant_idx(x_koords, y_koords): return index_1, index_2 def symToMatrix(symTensor): + """ + tested translates symmetric tensor notation to complete matrix + :param symTensor: + :return: + """ # xx,xy,xz,yy,yz,zz Matrix = np.array([[symTensor[0], symTensor[1], symTensor[2]], [symTensor[1], symTensor[3], symTensor[4]], @@ -39,15 +44,12 @@ def symToMatrix(symTensor): return Matrix -def symToMatrixPVPoly(symTensor): - # xx,xy,xz,yy,yz,zz - Matrix = np.array([[symTensor[0], symTensor[3], symTensor[4]], - [symTensor[3], symTensor[1], symTensor[5]], - [symTensor[4], symTensor[5], symTensor[2]]]) - return Matrix - - def gradToRad(angle): + """ + tested method to translate from grad to rad + :param angle: + :return: + """ return (angle / 180) * np.pi @@ -62,6 +64,7 @@ def Rx(xAngle): [0, -np.sin(xAngle), np.cos(xAngle)]]) + def Ry(yAngle): """ using radiant @@ -220,8 +223,6 @@ def minDists(vecs): return mDist - - def vecProjection(direction, vector): unitDir = unitVec(direction) return np.dot(vector, unitDir) * unitDir @@ -255,4 +256,3 @@ def lineseg_dist(p, a, b): return np.hypot(h, np.linalg.norm(c)) - diff --git a/tests/test_ntrfc_math.py b/tests/test_ntrfc_math.py index c12d35eb..fb12bd46 100644 --- a/tests/test_ntrfc_math.py +++ b/tests/test_ntrfc_math.py @@ -1,6 +1,8 @@ import numpy as np import pyvista as pv +from ntrfc.utils.math.vectorcalc import lineseg_dist + def test_absVec(): from ntrfc.utils.math.vectorcalc import vecAbs @@ -28,3 +30,51 @@ def test_randomUnitVec(): from ntrfc.utils.math.vectorcalc import randomUnitVec, vecAbs rvec = randomUnitVec() assert vecAbs(rvec)==1 + + +def test_gradToRad(): + from ntrfc.utils.math.vectorcalc import gradToRad + angle_grad = 180 + angle_rad = gradToRad(angle_grad) + assert np.pi == angle_rad + + +def test_symToMatrix(): + from ntrfc.utils.math.vectorcalc import symToMatrix + A = np.array([1,1,1,1,1,1]) + R = symToMatrix(A) + assert all(np.equal(np.ones((3,3)),R).flatten()) + + +def test_Rx(): + from ntrfc.utils.math.vectorcalc import gradToRad, Rx + angle = 90 + R = Rx(gradToRad(angle)) + test_vec = np.array([0,0,1]) + new_vec = np.dot(R,test_vec) + assert all(np.isclose(new_vec,np.array([0,1,0]))) + + +def test_Ry(): + from ntrfc.utils.math.vectorcalc import gradToRad, Ry + angle = 90 + R = Ry(gradToRad(angle)) + test_vec = np.array([1,0,0]) + new_vec = np.dot(R,test_vec) + assert all(np.isclose(new_vec,np.array([0,0,1]))) + +def test_Rz(): + from ntrfc.utils.math.vectorcalc import gradToRad, Rz + angle = 90 + R = Rz(gradToRad(angle)) + test_vec = np.array([0,1,0]) + new_vec = np.dot(R,test_vec) + assert all(np.isclose(new_vec,np.array([1,0,0]))) + + +def test_lineseg(): + import pyvista as pv + line = pv.Line() + testpt = np.array([0,1,0]) + pt_a, pt_b = line.points[0], line.points[-1] + assert line.length == lineseg_dist(testpt, pt_a, pt_b) -- GitLab