public void Aggregating_intersections() { var sphere = Sphere.UnitSphere(); var i1 = new Intersection(1, sphere); var i2 = new Intersection(2, sphere); var intersections = new IntersectionCollection(i1, i2); }
public void The_refracted_color_with_a_refracted_ray() { var w = World.Default(); var shape1 = w.Shapes.First(); shape1.Material.Ambient = 1.0; shape1.Material.Pattern = new TestPattern(); var shape2 = w.Shapes.Last(); shape2.Material.Transparency = 1.0; shape2.Material.RefractiveIndex = 1.5; var ray = new Ray(Tuple.Point(0, 0, 0.1), Tuple.Vector(0, 1, 0)); var xs = new IntersectionCollection( new Intersection(-0.9899, shape1), new Intersection(-0.4899, shape2), new Intersection(0.4899, shape2), new Intersection(0.9899, shape1)); var comps = xs[2].PrepareComputations(ray, xs); var c = w.RefractedColor(comps, 5); Assert.AreEqual(new Color(0, 0.998884, 0.047219), c); }
public void Shade_hit_with_a_reflective_transparent_material() { var w = World.Default(); var floor = new Plane { Transform = Transformation.Translation(0, -1, 0), Material = new Material { Reflective = 0.5, Transparency = 0.5, RefractiveIndex = 1.5 } }; w.Shapes.Add(floor); var ball = Sphere.UnitSphere(); ball.Transform = Transformation.Translation(0, -3.5, -0.5); ball.Material = new Material { Color = Color.Red, Ambient = 0.5 }; w.Shapes.Add(ball); var ray = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -C.SqrtOf2DividedBy2, C.SqrtOf2DividedBy2)); var xs = new IntersectionCollection(new Intersection(C.SqrtOf2, floor)); var comps = xs[0].PrepareComputations(ray, xs); var color = w.ShadeHit(comps, 5); Assert.AreEqual(new Color(0.933915, 0.696434, 0.69243), color); }
public void Finding_n1_and_n2_at_various_intersections(int index, double n1, double n2) { var a = Sphere.Glass(); a.Transform = Transformation.Scaling(2, 2, 2); a.Material.RefractiveIndex = 1.5; var b = Sphere.Glass(); b.Transform = Transformation.Translation(0, 0, -0.25); b.Material.RefractiveIndex = 2.0; var c = Sphere.Glass(); c.Transform = Transformation.Translation(0, 0, 0.25); c.Material.RefractiveIndex = 2.5; var ray = new Ray(Tuple.Point(0, 0, -4), Tuple.Vector(0, 0, 1)); var xs = new IntersectionCollection( new Intersection(2, a), new Intersection(2.75, b), new Intersection(3.25, c), new Intersection(4.75, b), new Intersection(5.25, c), new Intersection(6, a)); var comps = xs[index].PrepareComputations(ray, xs); Assert.AreEqual(n1, comps.n1); Assert.AreEqual(n2, comps.n2); }
public void Preparing_the_normal_on_a_smooth_triangle() { var i = new Intersection(1, _tri, 0.45, 0.25); var ray = new Ray(Tuple.Point(-0.2, 0.3, -2), Tuple.Vector(0, 0, 1)); var xs = new IntersectionCollection(i); var comps = i.PrepareComputations(ray, xs); comps.NormalVector.Should().Be(Tuple.Vector(-0.5547, 0.83205, 0)); }
public void All_Negative_Times_Give_Null_Hit() { var sphere = new Sphere(); var first = new Intersection(-5, sphere); var second = new Intersection(-10, sphere); var collection = new IntersectionCollection(first, second); var hit = collection.GetHit(); hit.ShouldBeNull(); }
public void The_hit_when_all_intersections_have_negative_t() { var sphere = Sphere.UnitSphere(); var i1 = new Intersection(-2, sphere); var i2 = new Intersection(-1, sphere); var intersections = new IntersectionCollection(i2, i1); var hit = intersections.Hit(); Assert.AreEqual(null, hit); }
public void The_Schlick_approximation_with_small_angle_and_n2_greater_than_n1() { var shape = Sphere.Glass(); var ray = new Ray(Tuple.Point(0, 0.99, -2), Tuple.Vector(0, 0, 1)); var xs = new IntersectionCollection( new Intersection(1.8589, shape)); var comps = xs[0].PrepareComputations(ray, xs); var reflectance = comps.Schlick(); Assert.AreEqual(0.48873, reflectance, C.Epsilon); }
public void The_Schlick_approximation_under_total_internal_reflection() { var shape = Sphere.Glass(); var ray = new Ray(Tuple.Point(0, 0, C.SqrtOf2DividedBy2), Tuple.Vector(0, 1, 0)); var xs = new IntersectionCollection( new Intersection(-C.SqrtOf2DividedBy2, shape), new Intersection(C.SqrtOf2DividedBy2, shape)); var comps = xs[1].PrepareComputations(ray, xs); var reflectance = comps.Schlick(); Assert.AreEqual(1.0, reflectance); }
public void The_Schlick_approximation_with_a_perpendicular_viewing_angle() { var shape = Sphere.Glass(); var ray = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 1, 0)); var xs = new IntersectionCollection( new Intersection(-1, shape), new Intersection(1, shape)); var comps = xs[1].PrepareComputations(ray, xs); var reflectance = comps.Schlick(); Assert.AreEqual(0.04, reflectance, C.Epsilon); }
public void The_hit_is_always_the_lowest_nonnegative_intersection() { var sphere = Sphere.UnitSphere(); var i1 = new Intersection(5, sphere); var i2 = new Intersection(7, sphere); var i3 = new Intersection(-3, sphere); var i4 = new Intersection(2, sphere); var intersections = new IntersectionCollection(i1, i2, i3, i4); var hit = intersections.Hit(); Assert.AreEqual(i4, hit); }
public void The_refracted_color_with_an_opaque_surface() { var w = World.Default(); var shape = w.Shapes.First(); var ray = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); var xs = new IntersectionCollection( new Intersection(4, shape), new Intersection(6, shape)); var comps = xs[0].PrepareComputations(ray, xs); var c = w.RefractedColor(comps, 5); Assert.AreEqual(Color.Black, c); }
public void Hit_Is_Lowest_Non_Negative_Intersection() { var sphere = new Sphere(); var first = new Intersection(5, sphere); var second = new Intersection(3, sphere); var third = new Intersection(10, sphere); var fourth = new Intersection(-5, sphere); var collection = new IntersectionCollection(first, second, third, fourth); var hit = collection.GetHit(); hit.ShouldNotBeNull(); hit.ShouldBe(second); }
public void The_under_point_is_offset_below_the_surface() { var r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); var shape = Sphere.Glass(); shape.Transform = Transformation.Translation(0, 0, 1); var i = new Intersection(5, shape); var xs = new IntersectionCollection(i); var comps = i.PrepareComputations(r, xs); Assert.Greater(comps.UnderPoint.z, C.Epsilon / 2); Assert.Less(comps.Point.z, comps.UnderPoint.z); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var streets = new StreetDescription(horizontalRoads: new int[] { 200, 500, 600 }, verticalRoads: new int[] { 200, 300, 400, 600, 800 }); var intersections = new IntersectionCollection(streets.Intersections); var carCollection = new CarCollection(); var form = new MainForm(streets, intersections, carCollection); var injector = new CarInjector(); var deleter = new CarDeleter(); var simulator = new Simulator(streets, intersections, carCollection, injector, deleter); Task.Run(() => MainLoop(form, simulator)); Application.Run(form); }
public void The_refracted_color_at_the_maximum_recursive_depth() { var w = World.Default(); var shape = w.Shapes.First(); shape.Material.Transparency = 1.0; shape.Material.RefractiveIndex = 1.5; var ray = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); var xs = new IntersectionCollection( new Intersection(4, shape), new Intersection(6, shape)); var comps = xs[0].PrepareComputations(ray, xs); var c = w.RefractedColor(comps, 0); Assert.AreEqual(Color.Black, c); }
public void The_refracted_color_under_total_internal_reflection() { var w = World.Default(); var shape = w.Shapes.First(); shape.Material.Transparency = 1.0; shape.Material.RefractiveIndex = 1.5; var ray = new Ray(Tuple.Point(0, 0, C.SqrtOf2DividedBy2), Tuple.Vector(0, 1, 0)); var xs = new IntersectionCollection( new Intersection(-C.SqrtOf2DividedBy2, shape), new Intersection(C.SqrtOf2DividedBy2, shape)); // Author's NOTE: this time you're inside the sphere, so you need // to look at the second intersection, xs[1], not xs[0] var comps = xs[1].PrepareComputations(ray, xs); var c = w.RefractedColor(comps, 5); Assert.AreEqual(Color.Black, c); }