Ejemplo n.º 1
0
    def test_operators_matrix33(self):
        m1 = Matrix33.identity()
        m2 = Matrix33.from_x_rotation(0.5)

        # add
        self.assertTrue(np.array_equal(m1 + m2, matrix33.create_identity() + matrix33.create_from_x_rotation(0.5)))

        # subtract
        self.assertTrue(np.array_equal(m1 - m2, matrix33.create_identity() - matrix33.create_from_x_rotation(0.5)))

        # multiply
        self.assertTrue(np.array_equal(m1 * m2, matrix33.multiply(matrix33.create_from_x_rotation(0.5), matrix33.create_identity())))

        # divide
        self.assertRaises(ValueError, lambda: m1 / m2)

        # inverse
        self.assertTrue(np.array_equal(~m2, matrix33.inverse(matrix33.create_from_x_rotation(0.5))))

        # ==
        self.assertTrue(Matrix33() == Matrix33())
        self.assertFalse(Matrix33() == Matrix33([1. for n in range(9)]))

        # !=
        self.assertTrue(Matrix33() != Matrix33([1. for n in range(9)]))
        self.assertFalse(Matrix33() != Matrix33())
Ejemplo n.º 2
0
    def test_create_from_matrix44(self):
        m1 = Matrix44.identity()
        m = Matrix33.from_matrix44(m1)
        self.assertTrue(np.array_equal(m, np.eye(3)))

        m = Matrix33(m1)
        self.assertTrue(np.array_equal(m, np.eye(3)))
Ejemplo n.º 3
0
    def test_create_from_quaternion(self):
        q = Quaternion()
        m = Matrix33.from_quaternion(q)
        self.assertTrue(np.array_equal(m, np.eye(3)))
        self.assertTrue(np.array_equal(m.quaternion, q))

        m = Matrix33(q)
        self.assertTrue(np.array_equal(m, np.eye(3)))
Ejemplo n.º 4
0
    def test_multiply(self):
        m1 = Matrix33(np.arange(self._size))
        m2 = Matrix33(np.arange(self._size)[::-1])
        m = m1 * m2
        self.assertTrue(np.array_equal(m, matrix33.multiply(m2, m1)))

        m1 = Matrix33(np.arange(self._size))
        m2 = Matrix44(np.arange(16))
        m = m1 * m2
        self.assertTrue(np.array_equal(m, matrix33.multiply(matrix33.create_from_matrix44(m2), m1)))
Ejemplo n.º 5
0
    def test_create(self):
        m = Matrix33()
        self.assertTrue(np.array_equal(m, np.zeros(self._shape)))
        self.assertEqual(m.shape, self._shape)

        m = Matrix33(np.arange(self._size))
        self.assertEqual(m.shape, self._shape)

        m = Matrix33([[1,2,3],[4,5,6],[7,8,9]])
        self.assertEqual(m.shape, self._shape)

        m = Matrix33(Matrix33())
        self.assertTrue(np.array_equal(m, np.zeros(self._shape)))
        self.assertEqual(m.shape, self._shape)
Ejemplo n.º 6
0
    def test_operators_number(self):
        m = Matrix33.identity()
        fv = np.empty((1,), dtype=[('i', np.int16, 1),('f', np.float32, 1)])
        fv[0] = (2, 2.0)
        
        # add
        self.assertTrue(np.array_equal(m + 1.0, matrix33.create_identity()[:] + 1.0))
        self.assertTrue(np.array_equal(m + 1, matrix33.create_identity()[:] + 1.0))
        self.assertTrue(np.array_equal(m + np.float(1.), matrix33.create_identity()[:] + 1.0))
        self.assertTrue(np.array_equal(m + fv[0]['f'], matrix33.create_identity()[:] + 2.0))
        self.assertTrue(np.array_equal(m + fv[0]['i'], matrix33.create_identity()[:] + 2.0))

        # subtract
        self.assertTrue(np.array_equal(m - 1.0, matrix33.create_identity()[:] - 1.0))
        self.assertTrue(np.array_equal(m - 1, matrix33.create_identity()[:] - 1.0))
        self.assertTrue(np.array_equal(m - np.float(1.), matrix33.create_identity()[:] - 1.0))
        self.assertTrue(np.array_equal(m - fv[0]['f'], matrix33.create_identity()[:] - 2.0))
        self.assertTrue(np.array_equal(m - fv[0]['i'], matrix33.create_identity()[:] - 2.0))

        # multiply
        self.assertTrue(np.array_equal(m * 2.0, matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * 2, matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * np.float(2.), matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * fv[0]['f'], matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * fv[0]['i'], matrix33.create_identity()[:] * 2.0))

        # divide
        self.assertTrue(np.array_equal(m / 2.0, matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / 2, matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / np.float(2.), matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / fv[0]['f'], matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / fv[0]['i'], matrix33.create_identity()[:] / 2.0))
Ejemplo n.º 7
0
    def test_accessors(self):
        m = Matrix33(np.arange(self._size))
        self.assertTrue(np.array_equal(m.m1,[0,1,2]))
        self.assertTrue(np.array_equal(m.m2,[3,4,5]))
        self.assertTrue(np.array_equal(m.m3,[6,7,8]))

        self.assertTrue(np.array_equal(m.r1,[0,1,2]))
        self.assertTrue(np.array_equal(m.r2,[3,4,5]))
        self.assertTrue(np.array_equal(m.r3,[6,7,8]))

        self.assertTrue(np.array_equal(m.c1,[0,3,6]))
        self.assertTrue(np.array_equal(m.c2,[1,4,7]))
        self.assertTrue(np.array_equal(m.c3,[2,5,8]))

        self.assertEqual(m.m11, 0)
        self.assertEqual(m.m12, 1)
        self.assertEqual(m.m13, 2)
        self.assertEqual(m.m21, 3)
        self.assertEqual(m.m22, 4)
        self.assertEqual(m.m23, 5)
        self.assertEqual(m.m31, 6)
        self.assertEqual(m.m32, 7)
        self.assertEqual(m.m33, 8)

        m.m11 = 1
        self.assertEqual(m.m11, 1)
        self.assertEqual(m[0,0], 1)
        m.m11 += 1
        self.assertEqual(m.m11, 2)
        self.assertEqual(m[0,0], 2)
Ejemplo n.º 8
0
    def test_operators_number(self):
        m = Matrix33.identity()
        fv = np.empty((1,), dtype=[('i', np.int16, 1),('f', np.float32, 1)])
        fv[0] = (2, 2.0)

        # add
        self.assertTrue(np.array_equal(m + 1.0, matrix33.create_identity()[:] + 1.0))
        self.assertTrue(np.array_equal(m + 1, matrix33.create_identity()[:] + 1.0))
        self.assertTrue(np.array_equal(m + np.float(1.), matrix33.create_identity()[:] + 1.0))
        self.assertTrue(np.array_equal(m + fv[0]['f'], matrix33.create_identity()[:] + 2.0))
        self.assertTrue(np.array_equal(m + fv[0]['i'], matrix33.create_identity()[:] + 2.0))

        # subtract
        self.assertTrue(np.array_equal(m - 1.0, matrix33.create_identity()[:] - 1.0))
        self.assertTrue(np.array_equal(m - 1, matrix33.create_identity()[:] - 1.0))
        self.assertTrue(np.array_equal(m - np.float(1.), matrix33.create_identity()[:] - 1.0))
        self.assertTrue(np.array_equal(m - fv[0]['f'], matrix33.create_identity()[:] - 2.0))
        self.assertTrue(np.array_equal(m - fv[0]['i'], matrix33.create_identity()[:] - 2.0))

        # multiply
        self.assertTrue(np.array_equal(m * 2.0, matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * 2, matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * np.float(2.), matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * fv[0]['f'], matrix33.create_identity()[:] * 2.0))
        self.assertTrue(np.array_equal(m * fv[0]['i'], matrix33.create_identity()[:] * 2.0))

        # divide
        self.assertTrue(np.array_equal(m / 2.0, matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / 2, matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / np.float(2.), matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / fv[0]['f'], matrix33.create_identity()[:] / 2.0))
        self.assertTrue(np.array_equal(m / fv[0]['i'], matrix33.create_identity()[:] / 2.0))
Ejemplo n.º 9
0
    def test_create_from_matrix44(self):
        m1 = Matrix44.identity()
        m = Matrix33.from_matrix44(m1)
        self.assertTrue(np.array_equal(m, np.eye(3)))

        m = Matrix33(m1)
        self.assertTrue(np.array_equal(m, np.eye(3)))
Ejemplo n.º 10
0
    def test_operators_matrix33(self):
        m1 = Matrix44.identity()
        m2 = Matrix33.from_x_rotation(0.5)

        # add
        self.assertTrue(
            np.array_equal(
                m1 + m2,
                matrix44.create_identity() +
                matrix44.create_from_x_rotation(0.5)))

        # subtract
        self.assertTrue(
            np.array_equal(
                m1 - m2,
                matrix44.create_identity() -
                matrix44.create_from_x_rotation(0.5)))

        # multiply
        self.assertTrue(
            np.array_equal(
                m1 * m2,
                matrix44.multiply(matrix44.create_identity(),
                                  matrix44.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: m1 / m2)
Ejemplo n.º 11
0
    def test_create_from_quaternion(self):
        q = Quaternion()
        m = Matrix33.from_quaternion(q)
        self.assertTrue(np.array_equal(m, np.eye(3)))
        self.assertTrue(np.array_equal(m.quaternion, q))

        m = Matrix33(q)
        self.assertTrue(np.array_equal(m, np.eye(3)))
Ejemplo n.º 12
0
    def test_operators_vector4(self):
        m = Matrix33.identity()
        v = Vector4([1,1,1,1])

        # add
        self.assertRaises(ValueError, lambda: m + v)

        # subtract
        self.assertRaises(ValueError, lambda: m - v)

        # multiply
        self.assertTrue(ValueError, lambda: m * v)

        # divide
        self.assertRaises(ValueError, lambda: m / v)
Ejemplo n.º 13
0
    def test_operators_vector3(self):
        m = Matrix33.identity()
        v = Vector3([1,1,1])

        # add
        self.assertRaises(ValueError, lambda: m + v)

        # subtract
        self.assertRaises(ValueError, lambda: m - v)

        # multiply
        self.assertTrue(np.array_equal(m * v, matrix33.apply_to_vector(matrix33.create_identity(), [1,1,1])))

        # divide
        self.assertRaises(ValueError, lambda: m / v)
Ejemplo n.º 14
0
    def test_operators_quaternion(self):
        m = Matrix33.identity()
        q = Quaternion.from_x_rotation(0.7)

        # add
        self.assertRaises(ValueError, lambda: m + q)

        # subtract
        self.assertRaises(ValueError, lambda: m - q)

        # multiply
        self.assertTrue(np.array_equal(m * q, matrix33.multiply(matrix33.create_from_quaternion(quaternion.create_from_x_rotation(0.7)), matrix33.create_identity())))

        # divide
        self.assertRaises(ValueError, lambda: m / q)
Ejemplo n.º 15
0
    def test_operators_matrix33(self):
        v = Vector3()
        m = Matrix33.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: v + m)

        # subtract
        self.assertRaises(ValueError, lambda: v - m)

        # multiply
        self.assertRaises(ValueError, lambda: v - m)

        # divide
        self.assertRaises(ValueError, lambda: v / m)
Ejemplo n.º 16
0
    def test_operators_vector4(self):
        m = Matrix33.identity()
        v = Vector4([1,1,1,1])
        
        # add
        self.assertRaises(ValueError, lambda: m + v)

        # subtract
        self.assertRaises(ValueError, lambda: m - v)

        # multiply
        self.assertTrue(ValueError, lambda: m * v)

        # divide
        self.assertRaises(ValueError, lambda: m / v)
Ejemplo n.º 17
0
    def test_operators_matrix33(self):
        q = Quaternion()
        m = Matrix33.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: q + m)

        # subtract
        self.assertRaises(ValueError, lambda: q - m)

        # multiply
        self.assertTrue(np.array_equal(q * m, quaternion.cross(quaternion.create(), quaternion.create_from_matrix(matrix33.create_from_x_rotation(0.5)))))

        # divide
        self.assertRaises(ValueError, lambda: q / m)
Ejemplo n.º 18
0
    def test_operators_matrix33(self):
        v = Vector3()
        m = Matrix33.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: v + m)

        # subtract
        self.assertRaises(ValueError, lambda: v - m)

        # multiply
        self.assertRaises(ValueError, lambda: v - m)

        # divide
        self.assertRaises(ValueError, lambda: v / m)
Ejemplo n.º 19
0
    def test_operators_vector3(self):
        m = Matrix33.identity()
        v = Vector3([1,1,1])
        
        # add
        self.assertRaises(ValueError, lambda: m + v)

        # subtract
        self.assertRaises(ValueError, lambda: m - v)

        # multiply
        self.assertTrue(np.array_equal(m * v, matrix33.apply_to_vector(matrix33.create_identity(), [1,1,1])))

        # divide
        self.assertRaises(ValueError, lambda: m / v)
Ejemplo n.º 20
0
    def test_operators_matrix44(self):
        m1 = Matrix33.identity()
        m2 = Matrix44.from_x_rotation(0.5)

        # add
        self.assertTrue(np.array_equal(m1 + m2, matrix33.create_identity() + matrix33.create_from_x_rotation(0.5)))

        # subtract
        self.assertTrue(np.array_equal(m1 - m2, matrix33.create_identity() - matrix33.create_from_x_rotation(0.5)))

        # multiply
        self.assertTrue(np.array_equal(m1 * m2, matrix33.multiply(matrix33.create_identity(), matrix33.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: m1 / m2)
Ejemplo n.º 21
0
    def test_operators_quaternion(self):
        m = Matrix33.identity()
        q = Quaternion.from_x_rotation(0.7)
        
        # add
        self.assertRaises(ValueError, lambda: m + q)

        # subtract
        self.assertRaises(ValueError, lambda: m - q)

        # multiply
        self.assertTrue(np.array_equal(m * q, matrix33.multiply(matrix33.create_identity(), matrix33.create_from_quaternion(quaternion.create_from_x_rotation(0.7)))))

        # divide
        self.assertRaises(ValueError, lambda: m / q)
Ejemplo n.º 22
0
 def test_create_from_inverse_quaternion(self):
     q = Quaternion.from_x_rotation(0.5)
     m = Matrix33.from_inverse_of_quaternion(q)
     expected = matrix33.create_from_quaternion(quaternion.inverse(quaternion.create_from_x_rotation(0.5)))
     np.testing.assert_almost_equal(np.array(m), expected, decimal=5)
Ejemplo n.º 23
0
 def test_matrix33(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.matrix33
     self.assertTrue(m1 is m)
Ejemplo n.º 24
0
 def test_create_from_eulers(self):
     e = Vector3([1,2,3])
     m = Matrix33.from_eulers(e)
     self.assertTrue(np.array_equal(m, matrix33.create_from_eulers([1,2,3])))
Ejemplo n.º 25
0
 def test_create_from_scale(self):
     v = Vector3([1,2,3])
     m = Matrix33.from_scale(v)
     self.assertTrue(np.array_equal(m, np.diag([1,2,3])))
Ejemplo n.º 26
0
 def test_matrix44(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.matrix44
     self.assertTrue(np.array_equal(m, matrix44.create_from_matrix33(m1)))
Ejemplo n.º 27
0
 def test_identity(self):
     m = Matrix33.identity()
     self.assertTrue(np.array_equal(m, np.eye(3)))
Ejemplo n.º 28
0
 def test_create_from_inverse_quaternion(self):
     q = Quaternion.from_x_rotation(0.5)
     m = Matrix33.from_inverse_of_quaternion(q)
     expected = matrix33.create_from_quaternion(quaternion.inverse(quaternion.create_from_x_rotation(0.5)))
     np.testing.assert_almost_equal(np.array(m), expected, decimal=5)
Ejemplo n.º 29
0
 def test_matrix44(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.matrix44
     self.assertTrue(np.array_equal(m, matrix44.create_from_matrix33(m1)))
Ejemplo n.º 30
0
 def test_matrix33(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.matrix33
     self.assertTrue(m1 is m)
Ejemplo n.º 31
0
 def test_inverse(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.inverse
     self.assertTrue(np.array_equal(m, matrix33.inverse(m1)))
Ejemplo n.º 32
0
 def test_inverse(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.inverse
     self.assertTrue(np.array_equal(m, matrix33.inverse(m1)))
Ejemplo n.º 33
0
 def test_identity(self):
     m = Matrix33.identity()
     self.assertTrue(np.array_equal(m, np.eye(3)))
Ejemplo n.º 34
0
 def test_create_from_eulers(self):
     e = Vector3([1,2,3])
     m = Matrix33.from_eulers(e)
     self.assertTrue(np.array_equal(m, matrix33.create_from_eulers([1,2,3])))
Ejemplo n.º 35
0
 def test_create_from_scale(self):
     v = Vector3([1,2,3])
     m = Matrix33.from_scale(v)
     self.assertTrue(np.array_equal(m, np.diag([1,2,3])))