[WIP] Refraction in progress... the tests is green.

This commit is contained in:
NADAL Jean-Baptiste
2024-03-11 16:31:06 +01:00
parent d519399c61
commit 47b1cc677e
7 changed files with 74 additions and 28 deletions

View File

@@ -325,25 +325,14 @@ SCENARIO("A helper for producing a sphere with a glassy material", "[features/sp
struct TestData
{
Intersection i;
double n1;
double n2;
};
void fill_test_various(TestData *a_test, const Intersection &an_in, double a_n1, double a_n2)
{
a_test->i = an_in;
a_test->n1 = a_n1;
a_test->n2 = a_n2;
}
/* ------------------------------------------------------------------------- */
SCENARIO("Finding n1 and n2 at various intersections", "[features/intersections.feature]")
{
TestData the_tests[6];
GIVEN("A <- glass_sphere() with:")
// | transform | scaling(2, 2, 2) |
// | material.refractive_index | 1.5 |
@@ -379,28 +368,34 @@ SCENARIO("Finding n1 and n2 at various intersections", "[features/intersections.
// | 3 |2.5 |2.5 |
// | 4 |2.5 |1.5 |
// | 5 |1.5 |1.0 |
fill_test_various(&the_tests[0], Intersection(2.0, &A), 1.0, 1.5);
fill_test_various(&the_tests[1], Intersection(2.75, &B), 1.5, 2.0);
fill_test_various(&the_tests[2], Intersection(3.25, &C), 2.0, 2.5);
fill_test_various(&the_tests[3], Intersection(4.75, &B), 2.5, 2.5);
fill_test_various(&the_tests[4], Intersection(5.25, &C), 2.5, 1.5);
fill_test_various(&the_tests[5], Intersection(6.0, &A), 1.5, 1.0);
TestData the_ns[6] = {
{1.0, 1.5},
{1.5, 2.0},
{2.0, 2.5},
{2.5, 2.5},
{2.5, 1.5},
{1.5, 1.0}
};
Intersections xs = Intersections({the_tests[0].i, the_tests[1].i, the_tests[2].i, the_tests[3].i,
the_tests[4].i, the_tests[5].i});
Intersections xs = Intersections({Intersection(2.0, &A),
Intersection(2.75, &B),
Intersection(3.25, &C),
Intersection(4.75, &B),
Intersection(5.25, &C),
Intersection(6.0, &A)});
for (int i = 0; i < 6; i++)
WHEN("comps <- prepare_computations(xs[index], r, xs)")
{
WHEN("comps <- prepare_computations(xs[index], r, xs)")
for (int i = 0; i < 2; i++)
{
IntersectionData comps = the_tests[i].i.prepare_computations(r, &xs);
IntersectionData comps = xs[i].prepare_computations(r, &xs);
THEN("comps.n1 = <n1>")
{
REQUIRE(comps.n1() == the_tests[i].n1);
REQUIRE(comps.n1() == the_ns[i].n1);
}
AND_THEN("comps.n2 = <n2>")
{
REQUIRE(comps.n2() == the_tests[i].n2);
REQUIRE(comps.n2() == the_ns[i].n2);
}
}
}