Beispiel #1
0
    def test_hit_when_all_intersections_have_negative_t(self):
        s = Sphere()
        i1 = Intersection(-2, s)
        i2 = Intersection(-1, s)
        xs = intersections(i1, i2)
        h = hit(xs)

        self.assertIsNone(h)
Beispiel #2
0
    def test_hit_when_some_intersections_have_negative_t(self):
        s = Sphere()
        i1 = Intersection(-1, s)
        i2 = Intersection(1, s)
        xs = intersections(i1, i2)
        h = hit(xs)

        self.assertEqual(i2, h)
Beispiel #3
0
    def test_hit_when_all_intersections_have_positive_t(self):
        s = Sphere()
        i1 = Intersection(1, s)
        i2 = Intersection(2, s)
        xs = intersections(i1, i2)
        h = hit(xs)

        self.assertEqual(i1, h)
Beispiel #4
0
    def test_aggregating_intersections(self):
        s = sphere.Sphere()
        i1 = Intersection(1, s)
        i2 = Intersection(2, s)
        xs = intersections(i1, i2)

        self.assertEqual(2, len(xs))
        self.assertEqual(1, xs[0].t)
        self.assertEqual(2, xs[1].t)
Beispiel #5
0
def color_at(world, ray):
    xss = intersect_world(world, ray)
    xs = intersections(xss)
    for item in xs:
        h = hit(item)
        if h is None:
            return black
        else:
            h.prepare_hit(ray)
            return shade_hit(world, h)
Beispiel #6
0
    def test_hit_is_always__lowest_negative_intersection(self):
        s = Sphere()
        i1 = Intersection(5, s)
        i2 = Intersection(7, s)
        i3 = Intersection(-3, s)
        i4 = Intersection(2, s)
        xs = intersections(i1, i2, i3, i4)
        h = hit(xs)

        self.assertEqual(i4, h)