testing some special cases
This commit is contained in:
parent
8f88480790
commit
10d5b2e791
|
@ -10,7 +10,33 @@ n = 1000
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def default():
|
def default():
|
||||||
"""A set of n random rotations."""
|
"""A set of n random rotations."""
|
||||||
return [Rotation.fromRandom() for r in range(n)]
|
specials =[np.array([ 1.0, 0.0, 0.0, 0.0]),
|
||||||
|
#-----------------------------------------------
|
||||||
|
np.array([ 1.0, 1.0, 0.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 1.0, 0.0, 1.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 1.0, 0.0, 0.0, 1.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 1.0, 1.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 1.0, 0.0, 1.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 0.0, 1.0, 1.0])*np.sqrt(2.)*.5,
|
||||||
|
#-----------------------------------------------
|
||||||
|
np.array([ 1.0,-1.0, 0.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 1.0, 0.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 1.0, 0.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 1.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 1.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 0.0, 1.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
#-----------------------------------------------
|
||||||
|
np.array([ 0.0, 1.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 1.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 0.0, 1.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
#-----------------------------------------------
|
||||||
|
np.array([ 0.0,-1.0,-1.0, 0.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0,-1.0, 0.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
np.array([ 0.0, 0.0,-1.0,-1.0])*np.sqrt(2.)*.5,
|
||||||
|
#-----------------------------------------------
|
||||||
|
]
|
||||||
|
return [Rotation.fromQuaternion(s) for s in specials] + \
|
||||||
|
[Rotation.fromRandom() for r in range(n-len(specials))]
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def reference_dir(reference_dir_base):
|
def reference_dir(reference_dir_base):
|
||||||
|
@ -22,35 +48,41 @@ class TestRotation:
|
||||||
|
|
||||||
def test_Eulers(self,default):
|
def test_Eulers(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asQuaternion(),
|
c = Rotation.fromEulers(rot.asEulers())
|
||||||
Rotation.fromEulers(rot.asEulers()).asQuaternion())
|
ok = np.allclose(rot.asQuaternion(),c.asQuaternion())
|
||||||
|
if np.isclose(rot.asQuaternion()[0],0.0,atol=1.e-13,rtol=0.0):
|
||||||
|
ok = ok or np.allclose(rot.asQuaternion(),c.asQuaternion()*-1.)
|
||||||
|
assert ok
|
||||||
|
|
||||||
def test_AxisAngle(self,default):
|
def test_AxisAngle(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asEulers(),
|
c = Rotation.fromAxisAngle(rot.asAxisAngle())
|
||||||
Rotation.fromAxisAngle(rot.asAxisAngle()).asEulers())
|
assert np.allclose(rot.asEulers(),c.asEulers())
|
||||||
|
|
||||||
def test_Matrix(self,default):
|
def test_Matrix(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asAxisAngle(),
|
c = Rotation.fromMatrix(rot.asMatrix())
|
||||||
Rotation.fromMatrix(rot.asMatrix()).asAxisAngle())
|
ok = np.allclose(rot.asAxisAngle(),c.asAxisAngle())
|
||||||
|
if np.isclose(rot.asAxisAngle()[3],np.pi):
|
||||||
|
ok = ok or np.allclose(rot.asAxisAngle(),c.asAxisAngle()*np.array([-1.,-1.,-1.,1.]))
|
||||||
|
assert ok
|
||||||
|
|
||||||
def test_Rodriques(self,default):
|
def test_Rodriques(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asMatrix(),
|
c = Rotation.fromRodrigues(rot.asRodrigues())
|
||||||
Rotation.fromRodrigues(rot.asRodrigues()).asMatrix())
|
assert np.allclose(rot.asMatrix(),c.asMatrix())
|
||||||
|
|
||||||
def test_Homochoric(self,default):
|
def test_Homochoric(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asRodrigues(),
|
c = Rotation.fromHomochoric(rot.asHomochoric())
|
||||||
Rotation.fromHomochoric(rot.asHomochoric()).asRodrigues(),rtol=1.e-4)
|
assert np.allclose(np.clip(rot.asRodrigues(),None,1.e9),np.clip(c.asRodrigues(),None,1.e9))
|
||||||
|
|
||||||
def test_Cubochoric(self,default):
|
def test_Cubochoric(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asHomochoric(),
|
c = Rotation.fromCubochoric(rot.asCubochoric())
|
||||||
Rotation.fromCubochoric(rot.asCubochoric()).asHomochoric())
|
assert np.allclose(rot.asHomochoric(),c.asHomochoric())
|
||||||
|
|
||||||
def test_Quaternion(self,default):
|
def test_Quaternion(self,default):
|
||||||
for rot in default:
|
for rot in default:
|
||||||
assert np.allclose(rot.asCubochoric(),
|
c = Rotation.fromQuaternion(rot.asQuaternion())
|
||||||
Rotation.fromQuaternion(rot.asQuaternion()).asCubochoric())
|
assert np.allclose(rot.asCubochoric(),c.asCubochoric())
|
||||||
|
|
Loading…
Reference in New Issue