def test_default(self): p = TestPattern() I = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) self.assertTrue(matrix.equals(I, p.transform))
def test_inv5(self): A = Matrix([[9, 3, 0, 9], [-5, -2, -6, -3], [-4, 9, 6, 4], [-7, 6, 6, 2]]) B = Matrix([[-0.04074, -0.07778, 0.14444, -0.22222], [-0.07778, 0.03333, 0.36667, -0.33333], [-0.02901, -0.14630, -0.10926, 0.12963], [0.17778, 0.06667, -0.26667, 0.33333]]) self.assertTrue(matrix.equals(A.inverse(), B))
def test_transform1(self): pfrom = Point(0, 0, 0) pto = Point(0, 0, -1) vup = Vector(0, 1, 0) t = view_transform(pfrom, pto, vup) I = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) self.assertTrue(matrix.equals(I, t))
def test_inv4(self): A = Matrix([[8, -5, 9, 2], [7, 5, 6, 1], [-6, 0, 9, 6], [-3, 0, -9, -4]]) B = Matrix([[-0.15385, -0.15385, -0.28205, -0.53846], [-0.07692, 0.12308, 0.02564, 0.03077], [0.35897, 0.35897, 0.43590, 0.92308], [-0.69231, -0.69231, -0.76923, -1.92308]]) self.assertTrue(matrix.equals(A.inverse(), B))
def test_transform2(self): pfrom = Point(0, 0, 0) pto = Point(0, 0, 1) vup = Vector(0, 1, 0) t = view_transform(pfrom, pto, vup) s = scale(-1, 1, -1) self.assertTrue(matrix.equals(s, t))
def test_camera1(self): hsize = 160 vsize = 120 field_of_view = pi / 2 c = Camera(hsize, vsize, field_of_view) self.assertEqual(hsize, c.hsize) self.assertEqual(vsize, c.vsize) self.assertEqual(field_of_view, pi / 2) I = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) self.assertTrue(matrix.equals(c.transform, I))
def test_minor1(self): A = Matrix([[3, 5, 0], [2, -1, 7], [6, -1, 5]]) B = A.submatrix(1, 0) C = Matrix([[5, 0], [-1, 5]]) self.assertTrue(matrix.equals(A.submatrix(1, 0), C)) self.assertEqual(B.determinant(), 25) self.assertEqual(A.minor(1, 0), 25)
def test_transform4(self): pfrom = Point(1, 3, 2) pto = Point(4, -2, 8) vup = Vector(1, 1, 0) t = view_transform(pfrom, pto, vup) m = Matrix([[-0.50709, 0.50709, 0.67612, -2.36643], [0.76772, 0.60609, 0.12122, -2.82843], [-0.35857, 0.59761, -0.71714, 0.00000], [0.00000, 0.00000, 0.00000, 1.00000]]) self.assertTrue(matrix.equals(m, t))
def test_inv3(self): A = Matrix([[-5, 2, 6, -8], [1, -5, 1, 8], [7, 7, -6, -7], [1, -3, 7, 4]]) B = A.inverse() C = Matrix([[0.21805, 0.45113, 0.24060, -0.04511], [-0.80827, -1.45677, -0.44361, 0.52068], [-0.07895, -0.22368, -0.05263, 0.19737], [-0.52256, -0.81391, -0.30075, 0.30639]]) self.assertEqual(A.determinant(), 532) self.assertEqual(A.cofactor(2, 3), -160) self.assertEqual(B[3][2], -160. / 532) self.assertEqual(A.cofactor(3, 2), 105) self.assertEqual(B[2][3], 105. / 532) self.assertTrue(matrix.equals(B, C))
def test_transform2(self): s = TestShape() t = translate(2, 3, 4) s.set_transform(t) self.assertTrue(matrix.equals(s.transform, t))
def test_transform1(self): s = TestShape() I = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) self.assertTrue(matrix.equals(s.transform, I))
def test_transform1(self): p = TestPattern() p.set_pattern_transform(translate(1, 2, 3)) self.assertTrue(matrix.equals(p.transform, translate(1, 2, 3)))
def test_mul1(self): A = Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 8, 7, 6], [5, 4, 3, 2]]) B = Matrix([[-2, 1, 2, 3], [3, 2, 1, -1], [4, 3, 6, 5], [1, 2, 7, 8]]) C = Matrix([[20, 22, 50, 48], [44, 54, 114, 108], [40, 58, 110, 102], [16, 26, 46, 42]]) self.assertTrue(matrix.equals(C, A * B))
def test_tranpose1(self): A = Matrix([[0, 9, 3, 0], [9, 8, 0, 8], [1, 8, 5, 3], [0, 0, 5, 8]]) B = Matrix([[0, 9, 1, 0], [9, 8, 8, 0], [3, 0, 5, 5], [0, 8, 3, 8]]) self.assertTrue(matrix.equals(A.transpose(), B))
def test_subm3(self): A = Matrix([[3, 5, 0], [2, -1, 7], [6, -1, 5]]) B = Matrix([[5, 0], [-1, 5]]) self.assertTrue(matrix.equals(A.submatrix(1, 0), B))
def test_subm2(self): A = Matrix([[-6, 1, 1, 6], [-8, 5, 8, 6], [-1, 0, 8, 2], [-7, 1, -1, 1]]) B = Matrix([[-6, 1, 6], [-8, 8, 6], [-7, -1, 1]]) self.assertTrue(matrix.equals(A.submatrix(2, 1), B))
def test_subm1(self): A = Matrix([[1, 5, 0], [-3, 2, 7], [0, 6, -3]]) B = Matrix([[-3, 2], [0, 6]]) self.assertTrue(matrix.equals(A.submatrix(0, 2), B))
def test_create2(self): A = Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 8, 7, 6], [5, 4, 3, 2]]) B = Matrix([[2, 2, 3, 4], [5, 6, 7, 8], [9, 8, 7, 6], [5, 4, 3, 2]]) self.assertFalse(matrix.equals(A, B))
def test_transform3(self): pfrom = Point(0, 0, 8) pto = Point(0, 0, 0) vup = Vector(0, 1, 0) t = view_transform(pfrom, pto, vup) self.assertTrue(matrix.equals(translate(0, 0, -8), t))
def test_inv6(self): A = Matrix([[3, -9, 7, 3], [3, -8, 2, -9], [-4, 4, 4, 1], [-6, 5, -1, 1]]) B = Matrix([[8, 2, 2, 2], [3, -1, 7, 0], [7, 0, 5, 4], [6, -2, 0, 5]]) C = A * B self.assertTrue(matrix.equals(C * B.inverse(), A))
def test_default1(self): s = GlassSphere() self.assertTrue(matrix.equals(I(), s.transform)) self.assertEqual(s.material.transparency, 1.0) self.assertEqual(s.material.refractive_index, 1.5)
def test_ide1(self): I = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) A = Matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 8, 7, 6], [5, 4, 3, 2]]) self.assertTrue(matrix.equals(A, A * I))