Example #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())
Example #2
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)
Example #3
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)
Example #4
0
    def test_create_identity( self ):
        result = matrix33.create_identity()

        expected = numpy.eye( 3 )

        self.assertTrue(
            numpy.array_equal( result, expected ),
            "Matrix44 identity incorrect"
            )
Example #5
0
    def test_create_from_matrix33( self ):
        mat = matrix33.create_identity()
        result = matrix44.create_from_matrix33( mat )

        expected = numpy.eye( 4 )

        self.assertTrue(
            numpy.array_equal( result, expected ),
            "Matrix44 create_from_matrix33 incorrect"
            )
Example #6
0
        def identity():
            mat = matrix33.create_identity()
            vec = vector3.unit.x

            result = matrix33.apply_to_vector( mat, vec )

            expected = vec

            self.assertTrue(
                numpy.array_equal( result, expected ),
                "Matrix33 apply_to_vector incorrect with identity"
                )
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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)
Example #11
0
 def test_create_identity(self):
     result = matrix33.create_identity()
     np.testing.assert_almost_equal(result, np.eye(3), decimal=5)
     self.assertTrue(result.dtype == np.float)
Example #12
0
 def test_multiply_identity(self):
     m1 = matrix33.create_identity()
     m2 = matrix33.create_identity()
     result = matrix33.multiply(m1, m2)
     self.assertTrue(np.allclose(result, np.dot(m1, m2)))
Example #13
0
 def test_apply_to_vector_identity(self):
     mat = matrix33.create_identity()
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = vec
     self.assertTrue(np.array_equal(result, expected))
Example #14
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))
Example #15
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))
Example #16
0
 def test_create_identity(self):
     result = matrix33.create_identity()
     np.testing.assert_almost_equal(result, np.eye(3), decimal=5)
     self.assertTrue(result.dtype == np.float)
Example #17
0
 def test_multiply_identity(self):
     m1 = matrix33.create_identity()
     m2 = matrix33.create_identity()
     result = matrix33.multiply(m1, m2)
     self.assertTrue(np.allclose(result, np.dot(m1,m2)))
Example #18
0
 def test_apply_to_vector_identity(self):
     mat = matrix33.create_identity()
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = vec
     self.assertTrue(np.array_equal(result, expected))