Beispiel #1
0
    def test_create_from_matrix44(self):
        m1 = Matrix33.identity()
        m = Matrix44.from_matrix33(m1)
        self.assertTrue(np.array_equal(m, np.eye(4)))

        m = Matrix44(m1)
        self.assertTrue(np.array_equal(m, np.eye(4)))
Beispiel #2
0
    def test_create_from_matrix44(self):
        m1 = Matrix33.identity()
        m = Matrix44.from_matrix33(m1)
        self.assertTrue(np.array_equal(m, np.eye(4)))

        m = Matrix44(m1)
        self.assertTrue(np.array_equal(m, np.eye(4)))
Beispiel #3
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())
Beispiel #4
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))
Beispiel #5
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))
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
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)))
Beispiel #15
0
 def test_matrix33(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.matrix33
     self.assertTrue(m1 is m)
Beispiel #16
0
 def test_matrix33(self):
     m1 = Matrix33.identity() * Matrix33.from_x_rotation(0.5)
     m = m1.matrix33
     self.assertTrue(m1 is m)
Beispiel #17
0
 def test_identity(self):
     m = Matrix33.identity()
     self.assertTrue(np.array_equal(m, np.eye(3)))
Beispiel #18
0
 def test_identity(self):
     m = Matrix33.identity()
     self.assertTrue(np.array_equal(m, np.eye(3)))
Beispiel #19
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)))
Beispiel #20
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)))
Beispiel #21
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)))