Пример #1
0
    def setUp(self):
        self.A = Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9)
        self.B = Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1])
        self.C = Matrix([[3, 2, 1], [6, 5, 4], [9, 8, 7]])

        self.D = Matrix(x for x in range(11, 20))
        self.p = Point(1, 2, 3)
Пример #2
0
    def setUp(self):
        self.A = Matrix(1, 2, 3,
                        4, 5, 6,
                        7, 8, 9)
        self.B = Matrix([9, 8, 7,
                         6, 5, 4,
                         3, 2, 1])
        self.C = Matrix([[3, 2, 1],
                         [6, 5, 4],
                         [9, 8, 7]])

        self.D = Matrix(x for x in range(11, 20))
        self.p = Point(1, 2, 3)
Пример #3
0
 def test_matrix_matrix_mul(self):
     self.assertEqual(self.A * self.B,
                      Matrix(30, 24, 18, 84, 69, 54, 138, 114, 90))
Пример #4
0
 def test_matrix_isub(self):
     self.A -= self.B
     self.assertEqual(self.A, Matrix(-8, -6, -4, -2, 0, 2, 4, 6, 8))
Пример #5
0
 def test_matrix_iadd(self):
     self.A += self.D
     self.assertEqual(self.A, Matrix(12, 14, 16, 18, 20, 22, 24, 26, 28))
Пример #6
0
 def test_matrix_eq(self):
     self.assertEqual(self.A, self.A)
     self.assertEqual(self.A, Matrix(list(range(1, 10))))
Пример #7
0
class TestMatrix(unittest.TestCase):
    def setUp(self):
        self.A = Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9)
        self.B = Matrix([9, 8, 7, 6, 5, 4, 3, 2, 1])
        self.C = Matrix([[3, 2, 1], [6, 5, 4], [9, 8, 7]])

        self.D = Matrix(x for x in range(11, 20))
        self.p = Point(1, 2, 3)

    def test_matrix_from_items(self):
        self.assertEqual(self.A.vals, list(range(1, 10)))

    def test_matrix_from_list(self):
        self.assertEqual(self.B.vals, list(range(9, 0, -1)))

    def test_matrix_from_nested_lists(self):
        self.assertEqual(self.C.vals, [3, 2, 1, 6, 5, 4, 9, 8, 7])

    def test_matrix_from_iterable(self):
        self.assertEqual(self.D.vals, list(range(11, 20)))

    def test_matrix_str(self):
        self.assertEqual(str(self.A), ("[1, 2, 3,\n"
                                       " 4, 5, 6,\n"
                                       " 7, 8, 9]"))

    def test_matrix_repr(self):
        self.assertEqual(repr(self.A), ("Matrix(1, 2, 3,\n"
                                        "       4, 5, 6,\n"
                                        "       7, 8, 9)"))

    def test_matrix_eq(self):
        self.assertEqual(self.A, self.A)
        self.assertEqual(self.A, Matrix(list(range(1, 10))))

    def test_matrix_add(self):
        self.assertEqual(self.A + self.D,
                         Matrix(12, 14, 16, 18, 20, 22, 24, 26, 28))

    def test_matrix_sub(self):
        self.assertEqual(self.A - self.B, Matrix(-8, -6, -4, -2, 0, 2, 4, 6,
                                                 8))

    def test_matrix_iadd(self):
        self.A += self.D
        self.assertEqual(self.A, Matrix(12, 14, 16, 18, 20, 22, 24, 26, 28))

    def test_matrix_isub(self):
        self.A -= self.B
        self.assertEqual(self.A, Matrix(-8, -6, -4, -2, 0, 2, 4, 6, 8))

    def test_matrix_rows(self):
        self.assertEqual(list(self.A.rows()),
                         [[1, 2, 3], [4, 5, 6], [7, 8, 9]])

    def test_matrix_cols(self):
        self.assertEqual(list(self.A.cols()),
                         [[1, 4, 7], [2, 5, 8], [3, 6, 9]])

    def test_matrix_point_mul(self):
        self.assertEqual(self.A * self.p, Point(14, 32, 50))

    def test_matrix_matrix_mul(self):
        self.assertEqual(self.A * self.B,
                         Matrix(30, 24, 18, 84, 69, 54, 138, 114, 90))
Пример #8
0
class TestMatrix(unittest.TestCase):

    def setUp(self):
        self.A = Matrix(1, 2, 3,
                        4, 5, 6,
                        7, 8, 9)
        self.B = Matrix([9, 8, 7,
                         6, 5, 4,
                         3, 2, 1])
        self.C = Matrix([[3, 2, 1],
                         [6, 5, 4],
                         [9, 8, 7]])

        self.D = Matrix(x for x in range(11, 20))
        self.p = Point(1, 2, 3)

    def test_matrix_from_items(self):
        self.assertEqual(self.A.vals, range(1, 10))

    def test_matrix_from_list(self):
        self.assertEqual(self.B.vals, range(9, 0, -1))

    def test_matrix_from_nested_lists(self):
        self.assertEqual(self.C.vals, [3, 2, 1, 6, 5, 4, 9, 8, 7])

    def test_matrix_from_iterable(self):
        self.assertEqual(self.D.vals, range(11, 20))

    def test_matrix_str(self):
        self.assertEqual(str(self.A), ("[1, 2, 3,\n"
                                       " 4, 5, 6,\n"
                                       " 7, 8, 9]"))

    def test_matrix_repr(self):
        self.assertEqual(repr(self.A), ("Matrix(1, 2, 3,\n"
                                        "       4, 5, 6,\n"
                                        "       7, 8, 9)"))

    def test_matrix_eq(self):
        self.assertEqual(self.A, self.A)
        self.assertEqual(self.A, Matrix(range(1, 10)))

    def test_matrix_add(self):
        self.assertEqual(self.A + self.D, Matrix(12, 14, 16, 18, 20, 22, 24, 26, 28))

    def test_matrix_sub(self):
        self.assertEqual(self.A - self.B, Matrix(-8, -6, -4, -2, 0, 2, 4, 6, 8))

    def test_matrix_iadd(self):
        self.A += self.D
        self.assertEqual(self.A, Matrix(12, 14, 16, 18, 20, 22, 24, 26, 28))

    def test_matrix_isub(self):
        self.A -= self.B
        self.assertEqual(self.A, Matrix(-8, -6, -4, -2, 0, 2, 4, 6, 8))

    def test_matrix_rows(self):
        self.assertEqual(list(self.A.rows()), [[1, 2, 3], [4, 5, 6], [7, 8, 9]])

    def test_matrix_cols(self):
        self.assertEqual(list(self.A.cols()), [[1, 4, 7], [2, 5, 8], [3, 6, 9]])

    def test_matrix_point_mul(self):
        self.assertEqual(self.A * self.p, Point(14, 32, 50))

    def test_matrix_matrix_mul(self):
        self.assertEqual(self.A * self.B, Matrix(30, 24, 18, 84, 69, 54, 138, 114, 90))
Пример #9
0
from rubik.maths import Point, Matrix

RIGHT = X_AXIS = Point(1, 0, 0)
LEFT = Point(-1, 0, 0)
UP = Y_AXIS = Point(0, 1, 0)
DOWN = Point(0, -1, 0)
FRONT = Z_AXIS = Point(0, 0, 1)
BACK = Point(0, 0, -1)

FACE = 'face'
EDGE = 'edge'
CORNER = 'corner'

# 90 degree rotations in the XY plane. CW is clockwise, CC is counter-clockwise.
ROT_XY_CW = Matrix(0, 1, 0, -1, 0, 0, 0, 0, 1)
ROT_XY_CC = Matrix(0, -1, 0, 1, 0, 0, 0, 0, 1)

# 90 degree rotations in the XZ plane (around the y-axis when viewed pointing toward you).
ROT_XZ_CW = Matrix(0, 0, -1, 0, 1, 0, 1, 0, 0)
ROT_XZ_CC = Matrix(0, 0, 1, 0, 1, 0, -1, 0, 0)

# 90 degree rotations in the YZ plane (around the x-axis when viewed pointing toward you).
ROT_YZ_CW = Matrix(1, 0, 0, 0, 0, 1, 0, -1, 0)
ROT_YZ_CC = Matrix(1, 0, 0, 0, 0, -1, 0, 1, 0)


def get_rot_from_face(face):
    """
    :param face: One of FRONT, BACK, LEFT, RIGHT, UP, DOWN
    :return: A pair (CW, CC) given the clockwise and counterclockwise rotations for that face