[FEAT] Add all test intersections

This commit is contained in:
NADAL Jean-Baptiste
2024-02-12 17:13:47 +01:00
parent 6571fe27ee
commit 8c8e378ebd
9 changed files with 200 additions and 39 deletions

View File

@@ -150,7 +150,7 @@ TEST_CASE("[05][Rays] Aggregating intersections", "[Intersections]")
Sphere s;
Intersection i1(1, s);
Intersection i2(2, s);
Intersections xs = Intersections(i1, i2);
Intersections xs = Intersections({i1, i2});
REQUIRE(xs.count() == 2);
REQUIRE(xs[0].distance_t() == 1);
@@ -169,3 +169,61 @@ TEST_CASE("[05][Rays] Intersect set the object on the intersection", "[Intersect
REQUIRE(xs[0].object() == s);
REQUIRE(xs[1].object() == s);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] The hit, when all intersections have positive t", "[Intersections]")
{
Sphere s;
Intersection i1(1, s);
Intersection i2(2, s);
Intersections xs = Intersections({i2, i1});
Intersection i = xs.hit();
REQUIRE(i == i1);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] The hit, when some intersections have negative t", "[Intersections]")
{
Sphere s;
Intersection i1(-1, s);
Intersection i2(1, s);
Intersections xs = Intersections({i2, i1});
Intersection i = xs.hit();
REQUIRE(i == i2);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] The hit, when all intersections have negative t", "[Intersections]")
{
Sphere s;
Intersection i1(-2, s);
Intersection i2(-1, s);
Intersections xs = Intersections({i1, i2});
Intersection i = xs.hit();
REQUIRE(i.object().is_nothing());
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] The hit is always the lowest nonnegative intersection", "[Intersections]")
{
Sphere s;
Intersection i1(5, s);
Intersection i2(7, s);
Intersection i3(-3, s);
Intersection i4(2, s);
Intersections xs = Intersections({i1, i2, i3, i4});
Intersection i = xs.hit();
REQUIRE(i == i4);
}