Пример #1
0
 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))
Пример #2
0
 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))
Пример #3
0
 def test_find_intersection(self):
     sphere_1 = data.Sphere(data.Point(1, 1, 0), 1)
     sphere_2 = data.Sphere(data.Point(200, 200, 200), 1)
     s_list = [sphere_1, sphere_2]
     new_list = [(data.Sphere(data.Point(1, 1, 0), 1), data.Point(0, 1, 0))]
     r = data.Ray(data.Point(-1, 1, 0), data.Vector(20, 0, 0))
     self.assertEqual(collisions.find_intersection_points(s_list, r),
                      new_list)
Пример #4
0
 def test_find_intersection_2(self):
     sphere_1 = data.Sphere(data.Point(20, 20, 20), 2)
     sphere_2 = data.Sphere(data.Point(60, 60, 60), 1)
     s_list = [sphere_1, sphere_2]
     new_list = []
     r = data.Ray(data.Point(0, 0, 0), data.Vector(0, 0, 1))
     self.assertEqual(collisions.find_intersection_points(s_list, r),
                      new_list)
Пример #5
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)
Пример #6
0
 def test_sphere_equality_2(self):
     p1 = data.Point(1.0, 0.0, 0.0)
     r1 = 1.0
     s1 = data.Sphere(p1, r1)
     p2 = data.Point(0.0, 0.0, 0.0)
     r2 = 1.0
     s2 = data.Sphere(p2, r2)
     self.assertFalse(s1 == s2)
Пример #7
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))
Пример #8
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)
Пример #9
0
 def test_find_intersection_point2(self):
     #test ray 2
     ray2 = data.Ray(data.Point(1, 5, 0), data.Vector(0, -1, 0))
     spheres_list2 = [
         data.Sphere(data.Point(1, 0, 0), 1),
         data.Sphere(data.Point(1, -5, 0), 1)
     ]
     intersection_points2 = [(spheres_list2[0], data.Point(1, 1, 0)),
                             (spheres_list2[1], data.Point(1, -4, 0))]
     self.assertEqual(
         collisions.find_intersection_point(spheres_list2, ray2),
         intersection_points2)
Пример #10
0
 def test_find_intersection_point1(self):
     #test ray 1
     ray1 = data.Ray(data.Point(0, 0, 0), data.Vector(1, 0, 0))
     spheres_list1 = [
         data.Sphere(data.Point(3, 0, 0), 1),
         data.Sphere(data.Point(6, 0, 0), 1)
     ]
     intersection_points1 = [(spheres_list1[0], data.Point(2, 0, 0)),
                             (spheres_list1[1], data.Point(5, 0, 0))]
     self.assertEqual(
         collisions.find_intersection_point(spheres_list1, ray1),
         intersection_points1)
Пример #11
0
 def test1(self):
     result = commandline.process_cmdArguments(
         ['', 'test_file', '-ambient', '0.9', '0.9', '0.9'])
     sphere1 = data.Sphere(data.Point(1, 1, 0), 2, data.Color(1, 0, 1),
                           data.Finish(0.2, 0.4, 0.5, 0.05))
     sphere2 = data.Sphere(data.Point(8, -10, 110), 100,
                           data.Color(0.2, 0.2, 0.6),
                           data.Finish(0.4, 0.8, 0, 0.05))
     check = (data.Light(data.Point(-100, 100, -100),
                         data.Color(1.5, 1.5, 1.5)),
              data.Color(0.9, 0.9, 0.9), [sphere1, sphere2])
     self.assertEqual(result, check)
Пример #12
0
 def test_intersection_points_3(self):
     s1 = data.Sphere(data.Point(2, 2, 2), math.sqrt(3),
                      data.Color(0, 1, 0), data.Finish(.2, 1, 0, 0))
     s2 = data.Sphere(data.Point(-2, -2, 3), 1, data.Color(0, 1, 0),
                      data.Finish(0.2, 1, 0, 0))
     s3 = data.Sphere(data.Point(0, 3, 0), 3 * math.sqrt(2),
                      data.Color(0, 1, 0), data.Finish(.2, 1, 0, 0))
     ray = data.Ray(data.Point(0, 0, 0), data.Vector(1, 1, 1))
     s_list = [s1, s2, s3]
     result_list = [(s1, data.Point(1, 1, 1)), (s3, data.Point(3, 3, 3))]
     self.assertEqual(collisions.find_intersection_points(s_list, ray),
                      result_list)
Пример #13
0
 def test_intersection_points_2(self):
     s1 = data.Sphere(data.Point(2, 0, 2), 2, data.Color(0, 1, 0),
                      data.Finish(.2, 1, 0, 0))
     s2 = data.Sphere(data.Point(0, 2, 4), 2, data.Color(0, 1, 0),
                      data.Finish(.2, 1, 0, 0))
     s3 = data.Sphere(data.Point(2, 2, 0), 2, data.Color(0, 1, 0),
                      data.Finish(.2, 1, 0, 0))
     ray = data.Ray(data.Point(0, 0, -6), data.Vector(0, 0, 1))
     s_list = [s1, s2, s3]
     result_list = [(s1, data.Point(0, 0, 2)), (s2, data.Point(0, 0, 4))]
     self.assertEqual(collisions.find_intersection_points(s_list, ray),
                      result_list)
Пример #14
0
 def test_collides_with_spheres_1(self):
     s = data.Sphere(data.Point(0.0, 0.0, 0.0), 2.0,
                     data.Color(1.0, 0.0, 0.0),
                     data.Finish(.2, .4, .5, .05))
     s1 = data.Sphere(data.Point(5.0, 5.0, 5.0), 2.0,
                      data.Color(1.0, 0.0, 0.0),
                      data.Finish(.2, .4, .5, .05))
     ray = data.Ray(data.Point(-5, 0, 0), data.Vector(1, 0, 0))
     light = data.Light(data.Point(0, 0, -14), data.Color(1, 1, 1))
     expected = False
     self.assertEqual(
         cast.collides_with_spheres(ray, [s, s1], data.Point(-3, -3, -3),
                                    light), expected)
Пример #15
0
 def test_get_difuse_color_2(self):
     light = data.Light(data.Point(-5.0, 10.0, -10.0),
                        data.Color(1.5, 1.5, 1.5))
     a = data.Sphere(data.Point(0, 0, 0), 4.0, data.Color(.5, 0.3, .8),
                     data.Finish(.2, .4, .5, .05))
     b = data.Sphere(data.Point(.5, 1.5, -3.0),
                     .5, data.Color(1.0, 0.0, 0.0),
                     data.Finish(.4, .4, .5, .05))
     list = [a, b]
     t = (a, data.Point(2.0, 0, 0))
     result = cast.get_diffuse_color(t, light, list)
     expected = data.Color(0, 0, 0)
     self.assertEqual(result, expected)
Пример #16
0
 def test_find_sphere_intersections_1(self):
     point_ray = data.Point(-10.0, 0.0, 0.0)
     direction = data.Vector(1.0, 0.0, 0.0)
     ray = data.Ray(point_ray, direction)
     point0_sphere = data.Point(0.0, 2.0, 0.0)
     sphere0 = data.Sphere(point0_sphere, 1.0)
     point1_sphere = data.Point(0.0, 1.0, 0.0)
     sphere1 = data.Sphere(point1_sphere, 1.0)
     point2_sphere = data.Point(0.0, 0.0, 0.0)
     sphere2 = data.Sphere(point2_sphere, 1.0)
     collision_points = collisions.find_intersection_points(
         [sphere0, sphere1, sphere2], ray)
     self.assertEqual(collision_points[0][1], data.Point(0.0, 0.0, 0.0))
     self.assertEqual(collision_points[1][1], data.Point(-1.0, 0.0, 0.0))
Пример #17
0
 def test_get_color_2(self):
     ambient = data.Color(.2, .2, .2)
     light = data.Light(data.Point(-100.0, 100.0, -100.0),
                        data.Color(1.5, 1.5, 1.5))
     a = data.Sphere(data.Point(0, 0, 0), 2.0, data.Color(.5, 0.3, .8),
                     data.Finish(.2, .4, .5, .05))
     b = data.Sphere(data.Point(.5, 1.5, -3.0),
                     .5, data.Color(1.0, 0.0, 0.0),
                     data.Finish(.4, .4, .5, .05))
     list = [a, b]
     t = (a, data.Point(2.0, 0, 0))
     result = cast.get_color(a.color, ambient, t, light, list)
     expected = data.Color(0.02, 0.012, 0.032)
     self.assertEqual(result, expected)
Пример #18
0
 def test_sphere(self):
     point = data.Point(1, 2, 3)
     color = data.Color(0, 0, 0)
     finish = data.Finish(0.2, 1, 0, 0)
     sphere = data.Sphere(point, 1.0, color, finish)
     self.assertAlmostEqual(sphere.center.x, 1)
     self.assertAlmostEqual(sphere.center.y, 2)
     self.assertAlmostEqual(sphere.center.z, 3)
     self.assertEqual(sphere.center, point)
     self.assertAlmostEqual(sphere.radius, 1.0)
     self.assertEqual(sphere.center, data.Point(1, 2, 3))
     self.assertEqual(
         sphere,
         data.Sphere(data.Point(1, 2, 3), 1, data.Color(0, 0, 0),
                     data.Finish(.2, 1, 0, 0)))
Пример #19
0
 def test_sphere_2(self):
     point2 = data.Point(0, -1, -2.0)
     color2 = data.Color(0, 1, 0)
     finish2 = data.Finish(0.2, 1, 0, 0)
     sphere2 = data.Sphere(point2, 2.5, color2, finish2)
     self.assertAlmostEqual(sphere2.center.x, 0)
     self.assertAlmostEqual(sphere2.center.y, -1)
     self.assertAlmostEqual(sphere2.center.z, -2.0)
     self.assertEqual(sphere2.center, point2)
     self.assertAlmostEqual(sphere2.radius, 2.5)
     self.assertEqual(point2, data.Point(0, -1, -2))
     self.assertEqual(
         sphere2,
         data.Sphere(data.Point(0, -1, -2), 2.5, data.Color(0, 1, 0),
                     data.Finish(0.2, 1, 0, 0)))
Пример #20
0
 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))
Пример #21
0
 def test_computePe2(self):
     result = auxiliary.compute_Pe(
         (data.Sphere(data.Point(0.0, 2.0, 0.0), 1.0, data.Color(1, 1, 1),
                      data.Finish(0.5, 0.4, 0.5,
                                  0.05)), data.Point(0, 1, 0)))
     check = data.Point(0, 0.99, 0)
     self.assertEqual(result, check)
Пример #22
0
 def test_sphere_intersection_point_2(self):
     #ray intersects at two points
     sphere = data.Sphere(data.Point(0, 0, 0), 5)
     ray = data.Ray(data.Point(0, -10, 0), data.Vector(0, 5, 0))
     outcome = data.Point(0, -5, 0)
     self.assertEqual(collisions.sphere_intersection_point(ray, sphere),
                      outcome)
Пример #23
0
 def test_sphere_intersection_point(self):
     #no intersection with sphere
     sphere = data.Sphere(data.Point(0, 0, 0), 1)
     ray = data.Ray(data.Point(5, 0, 0), data.Vector(10, 0, 0))
     outcome = None
     self.assertEqual(collisions.sphere_intersection_point(ray, sphere),
                      outcome)
Пример #24
0
 def test_sphere_2(self):
     sphere2 = data.Sphere(data.Point(1, 1, 2), 4.0)
     self.assertAlmostEqual(sphere2.center.x, 1)
     self.assertAlmostEqual(sphere2.center.y, 1)
     self.assertAlmostEqual(sphere2.center.z, 2)
     self.assertAlmostEqual(sphere2.radius, 4.0)
     pass
Пример #25
0
 def test_sphere_intersection_point1(self):
     theRay = data.Ray(data.Point(0, 0, 0), data.Vector(1, 0, 0))
     theSphere = data.Sphere(data.Point(0, 0, 0), 1)
     pointt = collisions.sphere_intersection_point(theRay, theSphere)
     self.assertAlmostEqual(pointt.x, 1.0)
     self.assertAlmostEqual(pointt.y, 0.0)
     self.assertAlmostEqual(pointt.z, 0.0)
Пример #26
0
 def test_get_pE_2(self):
     sphere = data.Sphere(data.Point(0.0, 0.0, 0.0), 2.0,
                          data.Color(0.0, 0.0, 1.0),
                          data.Finish(.2, .4, .5, .05))
     tuple = (sphere, data.Point(0, 2, 0))
     pe = cast.get_pe(tuple)
     expected = data.Point(0, 2.01, 0)
     self.assertEqual(pe, expected)
Пример #27
0
 def test_sphere_2(self):
     center = data.Point(7.7, 9.9, 17.8)
     radius = 10.8
     my_sphere = data.Sphere(center, radius)
     self.assertAlmostEqual(my_sphere.center.x, 7.7)
     self.assertAlmostEqual(my_sphere.center.y, 9.9)
     self.assertAlmostEqual(my_sphere.center.z, 17.8)
     self.assertAlmostEqual(my_sphere.radius, 10.8)
Пример #28
0
 def test_sphere_1(self):
     center = data.Point(1.1, 1.3, 2.2)
     radius = 5.9
     my_sphere = data.Sphere(center, radius)
     self.assertAlmostEqual(my_sphere.center.x, 1.1)
     self.assertAlmostEqual(my_sphere.center.y, 1.3)
     self.assertAlmostEqual(my_sphere.center.z, 2.2)
     self.assertAlmostEqual(my_sphere.radius, 5.9)
Пример #29
0
 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))
Пример #30
0
 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))