test_lmatrix4.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import pytest
  2. from copy import copy
  3. from panda3d import core
  4. def test_mat4_aliases():
  5. assert core.LMatrix4 is core.Mat4
  6. assert core.LMatrix4f is core.Mat4F
  7. assert core.LMatrix4d is core.Mat4D
  8. assert (core.LMatrix4f is core.Mat4) != (core.LMatrix4d is core.Mat4)
  9. @pytest.mark.parametrize("type", (core.LMatrix4d, core.LMatrix4f))
  10. def test_mat4_constructor(type):
  11. # Test that three ways of construction produce the same matrix.
  12. mat1 = type((1, 2, 3, 4),
  13. (5, 6, 7, 8),
  14. (9, 10, 11, 12),
  15. (13, 14, 15, 16))
  16. mat2 = type(1, 2, 3, 4,
  17. 5, 6, 7, 8,
  18. 9, 10, 11, 12,
  19. 13, 14, 15, 16)
  20. mat3 = type((1, 2, 3, 4,
  21. 5, 6, 7, 8,
  22. 9, 10, 11, 12,
  23. 13, 14, 15, 16))
  24. assert mat1 == mat2
  25. assert mat2 == mat3
  26. assert mat1 == mat3
  27. @pytest.mark.parametrize("type", (core.LMatrix4d, core.LMatrix4f))
  28. def test_mat4_copy_constuctor(type):
  29. mat1 = type((1, 2, 3, 4),
  30. (5, 6, 7, 8),
  31. (9, 10, 11, 12),
  32. (13, 14, 15, 16))
  33. # Make a copy. Changing it should not change the original.
  34. mat2 = type(mat1)
  35. assert mat1 == mat2
  36. mat2[0][0] = 100
  37. assert mat1 != mat2
  38. # Make a copy by unpacking.
  39. mat2 = type(*mat1)
  40. assert mat1 == mat2
  41. mat2[0][0] = 100
  42. assert mat1 != mat2
  43. # Make a copy by calling copy.copy.
  44. mat2 = copy(mat1)
  45. assert mat1 == mat2
  46. mat2[0][0] = 100
  47. assert mat1 != mat2
  48. @pytest.mark.parametrize("type", (core.LMatrix4d, core.LMatrix4f))
  49. def test_mat4_invert_same_type(type):
  50. mat = type((1, 0, 0, 0,
  51. 0, 1, 0, 0,
  52. 0, 0, 1, 0,
  53. 1, 2, 3, 1))
  54. inv = core.invert(mat)
  55. assert mat.__class__ == inv.__class__
  56. @pytest.mark.parametrize("type", (core.LMatrix4d, core.LMatrix4f))
  57. def test_mat4_invert_correct(type):
  58. mat = type((1, 0, 0, 0,
  59. 0, 1, 0, 0,
  60. 0, 0, 1, 0,
  61. 1, 2, 3, 1))
  62. inv = type()
  63. assert inv.invert_from(mat)
  64. assert inv == type(( 1, 0, 0, 0,
  65. 0, 1, 0, 0,
  66. 0, 0, 1, 0,
  67. -1, -2, -3, 1))
  68. assert (mat * inv).is_identity()
  69. assert (inv * mat).is_identity()