def test_offset1(self):
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     shape = Sphere()
     shape.transform = translate(0, 0, 1)
     i = Intersection(5, shape)
     comps = i.prepare_computations(r)
     self.assertTrue(comps.over_point.z < -EPSILON / 2)
     self.assertTrue(comps.point.z > comps.over_point.z)
Пример #2
0
 def test_world3(self):
     w = World()
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     shape = w.objs[0]
     i = Intersection(4, shape)
     comps = i.prepare_computations(r)
     c = w.shade_hit(comps)
     self.assertTrue(Color(0.38066, 0.47583, 0.2855).equals(c))
 def test_reflective2(self):
     shape = Plane()
     r = Ray(Point(0, 1, -1), Vector(0, -sqrt(2) / 2, sqrt(2) / 2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     self.assertTrue(
         Vector(0,
                sqrt(2) / 2,
                sqrt(2) / 2).equals(comps.reflectv))
Пример #4
0
 def test_reflect1(self):
     w = World()
     r = Ray(Point(0, 0, 0), Vector(0, 0, 1))
     shape = w.objs[1]
     shape.material.abmient = 1
     i = Intersection(1, shape)
     comps = i.prepare_computations(r)
     color = w.reflected_color(comps)
     self.assertTrue(Color(0, 0, 0).equals(color))
Пример #5
0
 def test_maximum_recursive_depth(self):
     w = World()
     shape = Plane()
     shape.material.reflective = 0.5
     shape.set_transform(translate(0, -1, 0))
     r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2)/2, sqrt(2)/2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     color = w.reflected_color(comps, 0)
     self.assertTrue(Color(0, 0, 0).equals(color))
    def test_prepare3(self):
        r = Ray(Point(0, 0, 0), Vector(0, 0, 1))
        s = Sphere()
        i = Intersection(1, s)
        comps = i.prepare_computations(r)

        self.assertTrue(comps.inside)
        self.assertTrue(Point(0, 0, 1).equals(comps.point))
        self.assertTrue(Vector(0, 0, -1).equals(comps.eyev))
        self.assertTrue(Vector(0, 0, -1).equals(comps.normalv))
Пример #7
0
 def test_shade_hit(self):
     w = World()
     shape = Plane()
     shape.material.reflective = 0.5
     shape.set_transform(translate(0.0, -1.0, 0.0))
     w.objs.append(shape)
     r = Ray(Point(0.0, 0.0, -3.0), Vector(0.0, -sqrt(2)/2, sqrt(2)/2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     color = w.shade_hit(comps)
     self.assertTrue(Color(0.87677, 0.92436, 0.82918).equals(color))
    def test_prepare1(self):
        r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
        s = Sphere()
        i = Intersection(4, s)
        comps = i.prepare_computations(r)

        self.assertEqual(i.t, comps.t)
        self.assertTrue(i.obj == comps.obj)
        self.assertTrue(Point(0, 0, -1).equals(comps.point))
        self.assertTrue(Vector(0, 0, -1).equals(comps.eyev))
        self.assertTrue(Vector(0, 0, -1).equals(comps.normalv))
Пример #9
0
 def test_reflect1(self):
     w = World()
     shape = Plane()
     shape.material.reflective = 0.5
     shape.set_transform(translate(0.0, -1.0, 0.0))
     w.objs.append(shape)
     r = Ray(Point(0.0, 0.0, -3.0), Vector(0.0, -sqrt(2)/2, sqrt(2)/2))
     i = Intersection(sqrt(2), shape)
     comps = i.prepare_computations(r)
     color = w.reflected_color(comps)
     # print(color)
     self.assertTrue(Color(0.19032, 0.2379, 0.14274).equals(color))
 def test_under_point1(self):
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     shape = GlassSphere()
     shape.set_transform(translate(0, 0, 1))
     i = Intersection(5, shape)
     xs = Intersections([i])
     comps = i.prepare_computations(r, xs)
     # print(comps.normalv)
     # print(comps.point)
     # print(comps.under_point.z)
     self.assertTrue(comps.under_point.z > EPSILON / 2)
     self.assertTrue(comps.point.z < comps.under_point.z)
Пример #11
0
 def test_shadow5(self):
     w = World()
     light = Light(Point(0, 0, -10), Color(1, 1, 1))
     w.light = light
     s1 = Sphere()
     s2 = Sphere()
     s2.transform = translate(0, 0, 10)
     w.objs = [s1, s2]
     r = Ray(Point(0, 0, 5), Vector(0, 0, 1))
     i = Intersection(4, s2)
     comps = i.prepare_computations(r)
     c = w.shade_hit(comps)
     self.assertTrue(Color(0.1, 0.1, 0.1).equals(c))
 def test_prepare2(self):
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     s = Sphere()
     i = Intersection(4, s)
     comps = i.prepare_computations(r)
     self.assertFalse(comps.inside)