Huge speed up by changing how Intersect are shared.

This commit is contained in:
Godzil
2020-03-12 00:11:26 +00:00
parent 0aa949c60b
commit b00bb75189
38 changed files with 116 additions and 153 deletions

View File

@@ -17,7 +17,7 @@ TEST(SphereTest, A_ray_intersect_a_sphere_at_two_points)
{
Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
Sphere s = Sphere();
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 2);
ASSERT_EQ(xs[0].t, 4.0);
@@ -28,7 +28,7 @@ TEST(SphereTest, A_ray_intersect_a_sphere_at_a_tangent)
{
Ray r = Ray(Point(0, 1, -5), Vector(0, 0, 1));
Sphere s = Sphere();
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 2);
ASSERT_EQ(xs[0].t, 5.0);
@@ -39,7 +39,7 @@ TEST(SphereTest, A_ray_miss_a_sphere)
{
Ray r = Ray(Point(0, 2, -5), Vector(0, 0, 1));
Sphere s = Sphere();
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 0);
}
@@ -48,7 +48,7 @@ TEST(SphereTest, A_ray_originate_inside_a_sphere)
{
Ray r = Ray(Point(0, 0, 0), Vector(0, 0, 1));
Sphere s = Sphere();
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 2);
ASSERT_EQ(xs[0].t, -1.0);
@@ -59,7 +59,7 @@ TEST(SphereTest, A_sphere_is_behind_a_ray)
{
Ray r = Ray(Point(0, 0, 5), Vector(0, 0, 1));
Sphere s = Sphere();
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 2);
ASSERT_EQ(xs[0].t, -6.0);
@@ -89,7 +89,7 @@ TEST(SphereTest, Intersecting_a_scaled_sphere_with_a_ray)
s.setTransform(scaling(2, 2, 2));
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 2);
ASSERT_EQ(xs[0].t, 3.0);
@@ -103,7 +103,7 @@ TEST(SphereTest, Intersecting_a_translated_sphere_with_a_ray)
s.setTransform(translation(5, 0, 0));
Intersect xs = s.intersect(r);
Intersect xs; s.intersect(r, xs);
ASSERT_EQ(xs.count(), 0);
}