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_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.º 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)
Ejemplo n.º 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"
            )
Ejemplo n.º 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"
            )
Ejemplo n.º 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"
                )
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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)))
Ejemplo n.º 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))