def test_intersect5(self): r = Ray(point(0, 0, 5), vector(0, 0, 1)) s = Sphere() i = s.intersect(r) self.assertEqual(2, len(i)) self.assertEqual(-6.0, i[0].t) self.assertEqual(-4.0, i[1].t)
def test_intersect_sphere1(self): s = Sphere() r = Ray(point(0, 0, -5), vector(0, 0, 1)) s.set_transform(xf_scale(2, 2, 2)) i = s.intersect(r) self.assertEqual(2, len(i)) self.assertEqual(i[0].t, 3.0) self.assertEqual(i[1].t, 7.0)
def test_translate_ray2(self): r = Ray(point(1, 2, 3), vector(0, 1, 0)) m = xf_scale(2, 3, 4) r2 = r.transform(m) self.assertEqual(r2.origin, point(2, 6, 12)) self.assertEqual(r2.direction, vector(0, 3, 0))
def test_translate_ray1(self): r = Ray(point(1, 2, 3), vector(0, 1, 0)) m = xf_translate(3, 4, 5) r2 = r.transform(m) self.assertEqual(r2.origin, point(4, 6, 8)) self.assertEqual(r2.direction, vector(0, 1, 0))
def test_intersect3(self): r = Ray(point(0, 2, -5), vector(0, 0, 1)) s = Sphere() i = s.intersect(r) self.assertEqual(0, len(i))
def test_ray_postion1(self): r = Ray(point(2, 3, 4), vector(1, 0, 0)) self.assertEqual(r.position(0), point(2, 3, 4)) self.assertEqual(r.position(1), point(3, 3, 4)) self.assertEqual(r.position(-1), point(1, 3, 4)) self.assertEqual(r.position(2.5), point(4.5, 3, 4))
def test_scaling1(self): p = point(-4, 6, 8) m = xf_scale(2, 3, 4) self.assertEqual(p.transform(m), point(-8, 18, 32))
def test_translate3(self): p = point(-3, 4, 5) m = xf_translate(5, -3, 2) self.assertEqual(p.transform(m.invert()), point(-8, 7, 3))
def test_translate1(self): p = point(-3, 4, 5) m = xf_translate(5, -3, 2) self.assertEqual(p.transform(m), point(2, 1, 7))
def _parse_vertex(self, line): try: return point(float(line[1]), float(line[2]), float(line[3])) except ValueError as e: print(e, line) raise