def test_hit_should_offset_the_point():
    r = Ray(point(0, 0, -5), vector(0, 0, 1))
    shape = Sphere(transformation=translation(0, 0, 1))
    i = Intersection(5, shape)
    comps = i.prepare_computations(r)

    assert(comps.point[2] < -EPSILON/2)
def test_aggregating_intersections():
    s = Sphere()
    i1 = Intersection(1, s)
    i2 = Intersection(2, s)
    xs = Intersections(i1, i2)

    assert(xs[0].t == 1)
    assert(xs[1].t == 2)
def test_the_hit_when_an_intersection_occurs_on_the_outside():
    r = Ray(point(0, 0, -5), vector(0, 0, 1))
    shape = Sphere()
    i = Intersection(4, shape)

    comps = i.prepare_computations(r)

    assert(comps.inside == False)
def test_hit_when_all_intersections_are_negative():
    s = Sphere()
    i1 = Intersection(-2, s)
    i2 = Intersection(-1, s)
    xs = Intersections(i2, i1)

    i = xs.hit()

    assert(i is None)
def test_hit_when_some_intersections_have_negative_t():
    s = Sphere()
    i1 = Intersection(-1, s)
    i2 = Intersection(1, s)
    xs = Intersections(i2, i1)

    i = xs.hit()

    assert(i is i2)
def test_hit_when_all_intersections_have_positive_t():
    s = Sphere()
    i1 = Intersection(1.0, s)
    i2 = Intersection(2.0, s)
    xs = Intersections(i2, i1)

    i = xs.hit()

    assert(i is i1)
Esempio n. 7
0
 def intersect(self, ray):
     transformation = invert(self.transformation)
     transformed_ray = ray.transform(transformation)
     ts = intersect_fast(transformed_ray.origin, transformed_ray.direction)
     if len(ts) == 2:
         i1 = Intersection(ts[0], self)
         i2 = Intersection(ts[1], self)
         return Intersections(i1, i2)
     return []
Esempio n. 8
0
def test_shading_an_intersection():
    w = default_world()
    r = Ray(point(0, 0, -5), vector(0, 0, 1))
    shape = w[0]
    i = Intersection(4, shape)

    comps = i.prepare_computations(r)
    c = w.shade_hit(comps)

    assert(np.allclose(color(0.38066, 0.47583, 0.2855), c, atol=0.0001))
def test_hit_is_always_the_lowest_non_negative_intersection():
    s = Sphere()
    i1 = Intersection(5.0, s)
    i2 = Intersection(7.0, s)
    i3 = Intersection(-3, s)
    i4 = Intersection(2, s)
    xs = Intersections(i1, i2, i3, i4)

    i = xs.hit()

    assert(i is i4)
def test_the_hit_when_an_intersection_occurs_on_the_inside():
    r = Ray(point(0, 0, 0), vector(0, 0, 1))
    shape = Sphere()
    i = Intersection(1, shape)

    comps = i.prepare_computations(r)

    assert(np.allclose(point(0, 0, 1), comps.point))
    assert(np.allclose(vector(0, 0, -1), comps.eyev))
    assert(comps.inside == True)
    assert(np.allclose(vector(0, 0, -1), comps.normalv))
Esempio n. 11
0
def test_shading_an_intersection_from_the_inside():
    w = default_world()
    w._light = PointLight(point(0, 0.25, 0), color(1, 1, 1))
    r = Ray(point(0, 0, 0), vector(0, 0, 1))
    shape = w[1]
    i = Intersection(0.5, shape)

    comps = i.prepare_computations(r)
    c = w.shade_hit(comps)

    assert(np.allclose(color(0.90498, 0.90498, 0.90498), c))
Esempio n. 12
0
def test_shade_hit_is_given_an_intersection_in_shadow():
    light = PointLight(point(0, 0, -10), color(1, 1, 1))
    s1 = Sphere()
    s2 = Sphere(transformation=translation(0, 0, 10))
    w = World(light, 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)

    assert(np.allclose(color(0.1, 0.1, 0.1), c))
def test_precompute_the_state_of_an_intersection():
    r = Ray(point(0, 0, -5), vector(0, 0, 1))
    shape = Sphere()
    i = Intersection(4, shape)

    comps = i.prepare_computations(r)

    assert(comps.t == i.t)
    assert(comps.object is i.object)
    assert(np.allclose(point(0, 0, -1), comps.point))
    assert(np.allclose(vector(0, 0, -1), comps.eyev))
    assert(np.allclose(vector(0, 0, -1), comps.normalv))
def test_an_intersection_encapsulates_t_and_object():
    s = Sphere()
    i = Intersection(3.5, s)

    assert(i.object is s)
    assert(i.t == 3.5)