def test_cast_ray_4(self): ray = data.Ray(data.Point(0.0, -3.0, -3.0), data.Vector(2.0, 1.0, 1.0)) sphere1 = data.Sphere(data.Point(0.0, 2.0, 2.0), 6.0, data.Color(1.0, 0.0, 0.0)) sphere2 = data.Sphere(data.Point(-10.0, -15.0, -20.0), 2.0, data.Color(0.0, 0.0, 1.0)) sphere_list = [sphere1, sphere2] casted = cast.cast_ray(ray, sphere_list) self.assertEqual(casted, data.Color(1.0, 0.0, 0.0))
def test_cast_ray_1(self): ray = data.Ray(data.Point(0, 10, 6), data.Vector(0, 0, -2)) sphere_list = [ data.Sphere(data.Point(0, 10, -2), 3, data.Color(0, 0.5, 1.0), data.Finish(0.5, 0.4, 0.5, 0.05)), data.Sphere(data.Point(0, 10, -20), 0.5, data.Color(0, 0.3, 0.2), data.Finish(0.5, 0.4, 0.5, 0.05)), ] ambient_color = data.Color(0.25, 0.5, 0.75) light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) eye_position = data.Point(0, 0, -14) cr = cast.cast_ray(ray, sphere_list, ambient_color, light, eye_position) inter_point = collisions.sphere_intersection_point(ray, sphere_list[0]) normal = collisions.sphere_normal_at_point(sphere_list[0], inter_point) off_pt = cast.find_pt_off_sphere(inter_point, normal) l_dir = vector_math.normalize_vector(vector_math.vector_from_to(off_pt, light.pt)) l_dot_n = vector_math.dot_vector(normal, l_dir) diffuse_list = cast.determine_diffuse_contribution( sphere_list[0], off_pt, light, normal, sphere_list, l_dir, l_dot_n ) spec_list = cast.determine_specular_contribution( l_dir, l_dot_n, normal, eye_position, off_pt, light.color, sphere_list[0].finish ) self.assertEqual( cr, data.Color( 0 + diffuse_list[0] + spec_list[0], 0.125 + diffuse_list[1] + spec_list[1], 0.375 + diffuse_list[2] + spec_list[2], ), )
def test_cast_ray_5(self): ray = data.Ray(data.Point(0.0, 0.0, 0.0), data.Vector(5.0, 0.0, 0.0)) sphere1 = data.Sphere(data.Point(5.0, 0.0, -5.0), 5.0, data.Color(1.0, 0.0, 0.0)) sphere2 = data.Sphere(data.Point(17.0, 0.0, 5.0), 5.0, data.Color(0.0, 0.0, 1.0)) sphere_list = [sphere1, sphere2] casted = cast.cast_ray(ray, sphere_list) self.assertEqual(casted, data.Color(1.0, 0.0, 0.0))
def test_cast_ray(self): r = data.Ray(data.Point(0, 0, 0), data.Vector(0, 50, 0)) sphere_list = [ data.Sphere(data.Point(0, 50, 0), 10, data.Color(0.0, 1.0, 1.0)), data.Sphere(data.Point(0, 100, 0), 10, data.Color(1.0, 1.0, 0.0)) ] self.assertEqual(cast.cast_ray(r, sphere_list), data.Color(0.0, 1.0, 1.0))
def test_cast_ray1(self): ray = data.Ray(data.Point(0, 0, 0), data.Vector(1, 0, 0)) sphere_list = [ data.Sphere(data.Point(1, 1, 1), 3), data.Sphere(data.Point(3, 3, 3), 1) ] boolean = cast.cast_ray(ray, sphere_list) self.assertEqual(boolean, True)
def test_cast_ray(self): sph1 = data.Sphere(data.Point(0, 3, 3), 5, data.Color(1.0, 1.0, 0.0), \ data.Finish(0.5, 0.4, 0.5, 0.05)) sph2 = data.Sphere(data.Point(5, 1, 2), 2, data.Color(0.0, 1.0, 1.0), \ data.Finish(0.9, 0.4, 0.5, 0.05)) sph3 = data.Sphere(data.Point(2, 2, 2), 4, data.Color(1.0, 0.0, 1.0), \ data.Finish(0.8, 0.4, 0.5, 0.05)) N = [sph1, sph2, sph3] ray1 = data.Ray(data.Point(4, 4, 4), data.Vector(-2, -2, -2)) self.assertTrue(cast.cast_ray(ray1, N, 0.8, data.Light(data.Point(-100.0, \ 100.0, -100.0), data.Color(1.5, 1.5, 1.5)), data.Point(0.0, 0.0, -14.0)), \ data.Color(0.8, 0.8, 0.8)) ray2 = data.Ray(data.Point(3, 5, 1), data.Vector(-3, 1, 4)) self.assertTrue(cast.cast_ray(ray2, N, 0.5, data.Light(data.Point(-100.0, \ 100.0, -100.0), data.Color(1.5, 1.5, 1.5)), data.Point(0.0, 0.0, -14.0)), \ data.Color(1.0, 1.0, 1.0))
def test_cast_ray(self): ray = data.Ray(data.Point(0, 0, 0), data.Vector(1, 0, 0)) sphere_list = [ data.Sphere(data.Point(1, 1, 1), 1), data.Sphere(data.Point(3, 3, 3), 1) ] color = data.Color boolean = cast.cast_ray(ray, sphere_list, color) self.assertEqual(boolean, False)
def test_cast_ray_2(self): ray = data.Ray(data.Point(0, 10, 6), data.Vector(0, 0, -2)) sphere_list = [ data.Sphere(data.Point(20, 10, -2), 3, data.Color(0.0, 0.0, 0.0), data.Finish(0.5, 0.4, 0.5, 0.05)), data.Sphere(data.Point(30, 10, -20), 0.5, data.Color(0, 0.0, 0.0), data.Finish(0.5, 0.4, 0.5, 0.05)), ] ambient_color = data.Color(0.25, 0.5, 0.75) light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) eye_position = data.Point(0, 0, -14) cr = cast.cast_ray(ray, sphere_list, ambient_color, light, eye_position) self.assertEqual(cr, ambient_color)
def test_cast_ray_1(self): finish = data.Finish(.4,.4, .5, .05) one = data.Sphere(data.Point(2,2,0), 1.0, data.Color(.4,.2,.1), finish) two = data.Sphere(data.Point(6,6,0), 2.0, data.Color(.2,.3,.5), finish) three = data.Sphere(data.Point(-2,-2,0), 1.0, data.Color(1,1,1), finish) four = data.Sphere(data.Point(-6,-6,0), 15.0, data.Color(.5,.5,.5), finish) ray = data.Ray(data.Point(0,0,-14), data.Vector(0,0,1)) l = [one,two,three,four] light = data.Light(data.Point(0,0,-14), data.Color(1.5,1.5,1.5)) ambient_color = data.Color(.2,.2,.2) result = cast.cast_ray(ray,l,ambient_color, light, data.Point(0,0,-14)) expected = data.Color(0.286793135633, 0.286793135633, 0.286793135633) self.assertEqual(result, expected)
def test_cast_ray_1(self): sphere_list = [ data.Sphere(data.Point(0, 0, 0), 1, data.Color(0, 0, 0), data.Finish(.2, 1, 0, 0)) ] ray = data.Ray(data.Point(0, 0, -15), data.Vector(0, 0, 1)) light = data.Light(data.Point(0, 0, 3), data.Color(1, 1, 1)) ambient_color = data.Color(1, 1, 1) eye_point = data.Point(0, 0, -14) calc_color = cast.cast_ray(ray, sphere_list, ambient_color, light, eye_point) exp_color = data.Color(0, 0, 0) self.assertEqual(calc_color, exp_color)
def test_cast_ray_1(self): pt = data.Point(0,0,0) dir = data.Vector(0,0,1) ray = data.Ray(pt,dir) center_1 = data.Point(12,0,0) center_2 = data.Point(0,5,0) center_3 = data.Point(5,0,0) center_4 = data.Point(50,0,0) radius = 2 color = data.Color(1,0,.1) finish = data.Finish(1,.2,1,1) light = data.Light(data.Color(1.5,1.5,1.5),data.Point(0,0,0)) eye_point = data.Point(1,1,1) sphere_list = [data.Sphere(center_1,radius,color,finish),data.Sphere(center_2,radius,color,finish),data.Sphere(center_3,radius,color,finish),data.Sphere(center_4,radius,color,finish)] test_cast_ray_1 = cast.cast_ray(ray,sphere_list,finish,light,eye_point) self.assertTrue(test_cast_ray_1 == data.Color(1,1,1))
def test_cast_ray2(self): spheres = [ data.Sphere(data.Point(6.0, 0.0, 0.0), 1.0, data.Color(1, 0, 0), data.Finish(0.5, 0.4, 0.5, 0.05)), data.Sphere(data.Point(0.0, 5.0, 0.0), 1.0, data.Color(0, 0, 1), data.Finish(0.5, 0.4, 0.5, 0.05)), data.Sphere(data.Point(0.0, -4.0, 0.0), 1.0, data.Color(0, 1, 0), data.Finish(0.5, 0.4, 0.5, 0.05)), data.Sphere(data.Point(0.0, 8.0, 0.0), 1.0, data.Color(0, 0, 0), data.Finish(0.5, 0.4, 0.5, 0.05)) ] ray = data.Ray(data.Point(0.0, 0.0, 0.0), data.Vector(0.0, 1.0, 0.0)) result = cast.cast_ray( ray, spheres, data.Color(1, 1, 1), data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)), data.Point(0, 0, -14)) self.assertEqual(result, data.Color(0, 0, 0.5))
def test_cast_ray_2(self): pt = data.Point(0,0,0) dir = data.Vector(0,1,0) ray = data.Ray(pt,dir) center_1 = data.Point(0,0,5) center_2 = data.Point(0,5,0) center_3 = data.Point(5,0,0) radius = 2 color = data.Color(0,1,0) color_1 = data.Color(0,0,0) finish = data.Finish(1,1,1,1) light = data.Light(data.Point(1,1,1),data.Color(1,1,1)) eye_point = data.Point(1,1,1) ambient = data.Color(1,1,1) sphere_list = [data.Sphere(center_1,radius,color_1,finish),data.Sphere(center_2,radius,color,finish),data.Sphere(center_3,radius,color_1,finish)] test_cast_ray_2 = cast.cast_ray(ray,sphere_list,ambient,light,eye_point) self.assertTrue(test_cast_ray_2 == data.Color(0.328870320968,2.14399924358,0.328870320968))
def test_cast_ray_1(self): finish = data.Finish(.4, .4, .5, .05) one = data.Sphere(data.Point(2, 2, 0), 1.0, data.Color(.4, .2, .1), finish) two = data.Sphere(data.Point(6, 6, 0), 2.0, data.Color(.2, .3, .5), finish) three = data.Sphere(data.Point(-2, -2, 0), 1.0, data.Color(1, 1, 1), finish) four = data.Sphere(data.Point(-6, -6, 0), 15.0, data.Color(.5, .5, .5), finish) ray = data.Ray(data.Point(0, 0, -14), data.Vector(0, 0, 1)) l = [one, two, three, four] light = data.Light(data.Point(0, 0, -14), data.Color(1.5, 1.5, 1.5)) ambient_color = data.Color(.2, .2, .2) result = cast.cast_ray(ray, l, ambient_color, light, data.Point(0, 0, -14)) expected = data.Color(0.286793135633, 0.286793135633, 0.286793135633) self.assertEqual(result, expected)
def test_cast_ray_1(self): ray = data.Ray(data.Point(0.0, 0.0, 5.0), data.Vector(0.0, 0.0, -5.0)) sphere_list = [data.Sphere(data.Point(0.0, 0.0, 0.0), 2.0, data.Color(0.0, 1.0, 1.0))] casted = cast.cast_ray(ray, sphere_list) self.assertEqual(casted, data.Color(0.0, 1.0, 1.0))
def test_cast_ray_2(self): ray = data.Ray(data.Point(0.0, 0.0, 0.0), data.Vector(0.0, 0.0, 1.0)) sphere_list = [] casted = cast.cast_ray(ray,sphere_list) self.assertEqual(casted, data.Color(1.0,1.0,1.0))
def test_cast_ray_4(self): ray = data.Ray(eye, vm.vector_from_to(eye, spheres[1].center)) result = cast.cast_ray(ray, spheres, ambientColor, blackPointLight, eye) self.assertEqual(result.green < result.blue and result.blue > result.red, True) # ensure that the dominant color is blue pass
def test_cast_ray_2(self): ray = data.Ray(eye, vm.vector_from_to(spheres[0].center, eye)) result = cast.cast_ray(ray, spheres, ambientColor, blackPointLight, eye) self.assertEqual(result == data.Color(1.0, 1.0, 1.0), True) pass