Matrix tests
============

Scale, rotation, and translation
--------------------------------

>>> from pyffi.formats.nif import NifFormat
>>> mat = NifFormat.Matrix44()
>>> mat.set_identity()
>>> print(mat)
[  1.000  0.000  0.000  0.000 ]
[  0.000  1.000  0.000  0.000 ]
[  0.000  0.000  1.000  0.000 ]
[  0.000  0.000  0.000  1.000 ]
<BLANKLINE>
>>> s, r, t = mat.get_scale_rotation_translation()
>>> print(s)
1.0
>>> print(r)
[  1.000  0.000  0.000 ]
[  0.000  1.000  0.000 ]
[  0.000  0.000  1.000 ]
<BLANKLINE>
>>> print(t)
[  0.000  0.000  0.000 ]
>>> mat.get_matrix_33().is_scale_rotation()
True
>>> mat.m_21 = 2.0
>>> mat.get_matrix_33().is_scale_rotation()
False
>>> mat = NifFormat.Matrix33()
>>> mat.m_11 = -0.434308
>>> mat.m_12 =  0.893095
>>> mat.m_13 = -0.117294
>>> mat.m_21 = -0.451770
>>> mat.m_22 = -0.103314
>>> mat.m_23 =  0.886132
>>> mat.m_31 =  0.779282
>>> mat.m_32 =  0.437844
>>> mat.m_33 =  0.448343
>>> mat == mat
True
>>> mat != mat
False
>>> print("%.4f" % mat.get_determinant())
1.0000
>>> mat.is_rotation()
True
>>> print(mat.get_transpose())
[ -0.434 -0.452  0.779 ]
[  0.893 -0.103  0.438 ]
[ -0.117  0.886  0.448 ]
<BLANKLINE>
>>> mat.get_inverse() == mat.get_transpose()
True
>>> mat *= 0.321
>>> print("%.5f"%mat.get_scale())
0.32100
>>> s, r = mat.get_inverse().get_scale_rotation()
>>> print("%.5f"%s)
3.11526
>>> abs(0.321 - 1/s) < NifFormat.EPSILON
True
>>> print(r) # same as print mat.get_transpose() above
[ -0.434 -0.452  0.779 ]
[  0.893 -0.103  0.438 ]
[ -0.117  0.886  0.448 ]
<BLANKLINE>
>>> abs(mat.get_determinant() - 0.321 ** 3) < NifFormat.EPSILON
True
>>> mat *= -2
>>> print(mat)
[  0.279 -0.573  0.075 ]
[  0.290  0.066 -0.569 ]
[ -0.500 -0.281 -0.288 ]
<BLANKLINE>
>>> print("%.5f"%mat.get_scale())
-0.64200
>>> abs(mat.get_determinant() + 0.642 ** 3) < NifFormat.EPSILON
True
>>> mat2 = NifFormat.Matrix44()
>>> mat2.set_identity()
>>> mat2.set_matrix_33(mat)
>>> t = NifFormat.Vector3()
>>> t.x = 1.2
>>> t.y = 3.4
>>> t.z = 5.6
>>> mat2.set_translation(t)
>>> print(mat2)
[  0.279 -0.573  0.075  0.000 ]
[  0.290  0.066 -0.569  0.000 ]
[ -0.500 -0.281 -0.288  0.000 ]
[  1.200  3.400  5.600  1.000 ]
<BLANKLINE>
>>> mat2 == mat2
True
>>> mat2 != mat2
False
>>> print(mat2.get_inverse())
[  0.676  0.704 -1.214  0.000 ]
[ -1.391  0.161 -0.682  0.000 ]
[  0.183 -1.380 -0.698  0.000 ]
[  2.895  6.338  7.686  1.000 ]
<BLANKLINE>
>>> print(mat2.get_inverse(fast=False) + 0.000001) # workaround for -0.000
[  0.676  0.704 -1.214  0.000 ]
[ -1.391  0.161 -0.682  0.000 ]
[  0.183 -1.380 -0.698  0.000 ]
[  2.895  6.338  7.686  1.000 ]
<BLANKLINE>
>>> (mat2 * mat2.get_inverse()).is_identity()
True

sup_norm
-------

>>> from pyffi.formats.nif import NifFormat
>>> mat = NifFormat.Matrix44()
>>> mat.set_identity()
>>> mat.sup_norm()
1.0
>>> mat.m_11 = -0.434308
>>> mat.m_12 =  0.893095
>>> mat.m_13 = -0.117294
>>> mat.m_21 = -0.451770
>>> mat.m_22 = -0.103314
>>> mat.m_23 =  0.886132
>>> mat.m_31 =  0.779282
>>> mat.m_32 =  0.437844
>>> mat.m_33 =  0.448343
>>> mat.m_41 = 3
>>> mat.m_41 = 4
>>> mat.m_41 = 8
>>> mat.sup_norm()
8.0

