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_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_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_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))
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))
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))