def precomputing_the_reflection_vector(): # Given shape = Plane() r = Ray(Point(0, 1, -1), Vector(0, -sqrt(2) / 2, sqrt(2) / 2)) i = Intersection(sqrt(2), shape) # When comps = i.prepare_computations(r) # Then assert comps.reflectv == Vector(0, sqrt(2) / 2, sqrt(2) / 2)
def test_the_hit__when_an_intersection_occurs_on_the_outside(): # Given r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) shape = Sphere() i = Intersection(4, shape) # When comps = i.prepare_computations(r) # Then assert comps.inside is False
def test_the_hit_should_offset_the_point(): # Given r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) shape = Sphere() shape.transform = translation(0, 0, 1) i = Intersection(5, shape) # When comps = i.prepare_computations(r) # Then assert comps.over_point.z < -EPSILON / 2 assert comps.point.z > comps.over_point.z
def test_shading_an_intersection(): # Given w = default_world() r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) shape = w.objects[0] i = Intersection(4, shape) # When comps = i.prepare_computations(r) c = w.shade_hit(comps) # Then assert c == Color(0.38066, 0.47583, 0.2855)
def test_the_under_point_is_offset_below_the_surface(): # Given r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) shape = glass_sphere() shape.transform = translation(0, 0, 1) i = Intersection(5, shape) xs = Intersections(i) # When comps = i.prepare_computations(r, xs) # Then assert comps.under_point.z > EPSILON / 2 assert comps.point.z < comps.under_point.z
def test_the_hit__when_an_intersection_occurs_on_the_inside(): # Given r = Ray(Point(0, 0, 0), Vector(0, 0, 1)) shape = Sphere() i = Intersection(1, shape) # When comps = i.prepare_computations(r) # Then assert comps.point == Point(0, 0, 1) assert comps.eyev == Vector(0, 0, -1) assert comps.inside is True assert comps.normalv == Vector(0, 0, -1)
def test_shading_an_intersection_from_the_inside(): # Given 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.objects[1] i = Intersection(0.5, shape) # When comps = i.prepare_computations(r) c = w.shade_hit(comps) # Then assert c == Color(0.90498, 0.90498, 0.90498)
def test_the_reflected_color_for_a_nonreflective_material(): # Given w = default_world() r = Ray(Point(0, 0, 0), Vector(0, 0, 1)) shape = Sphere() shape.material.ambient = 1 i = Intersection(1, shape) # When comps = i.prepare_computations(r) color = w.reflected_color(comps) # Then assert color == Color(0, 0, 0) # black
def test_precomputing_the_state_of_an_intersection(): # Given r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) shape = Sphere() i = Intersection(4, shape) # When comps = i.prepare_computations(r) # Then assert comps.t == i.t assert comps.object == i.object assert comps.point == Point(0, 0, -1) assert comps.eyev == Vector(0, 0, -1) assert comps.normalv == Vector(0, 0, -1)
def test_the_reflected_color_at_the_maximum_recursive_depth(): # Given w = default_world() shape = Plane() shape.material.reflective = 0.5 shape.transform = translation(0, -1, 0) w.objects.append(shape) r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2) / 2, sqrt(2) / 2)) i = Intersection(sqrt(2), shape) # When comps = i.prepare_computations(r) color = w.reflected_color(comps, 0) # Then assert color == Color(0, 0, 0)
def test__shade_hit__with_a_reflective_material(): # Given w = default_world() shape = Plane() shape.material.reflective = 0.5 shape.transform = translation(0, -1, 0) w.objects.append(shape) r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2) / 2, sqrt(2) / 2)) i = Intersection(sqrt(2), shape) # When comps = i.prepare_computations(r) color = w.shade_hit(comps) # Then assert color == Color(0.87675, 0.92434, 0.82918)
def test__shade_hit__is_given_an_intersection_in_shadow(): # Given w = World() w.light = PointLight(Point(0, 0, -10), Color(1, 1, 1)) s1 = Sphere() w.objects.append(s1) s2 = Sphere() s2.transform = translation(0, 0, 10) w.objects.append(s2) r = Ray(Point(0, 0, 5), Vector(0, 0, 1)) i = Intersection(4, s2) # When comps = i.prepare_computations(r) c = w.shade_hit(comps) # Then assert c == Color(0.1, 0.1, 0.1)