[FEAT] add tuple reflect

This commit is contained in:
NADAL Jean-Baptiste
2024-02-16 17:09:56 +01:00
parent 8c75d297a7
commit cb4149ae60
3 changed files with 53 additions and 0 deletions

View File

@@ -168,3 +168,47 @@ SCENARIO("Computing the normal on a transformed sphere", "[features/spheres.feat
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Reflecting a vector approaching at 45°", "[features/tuples.feature]")
{
GIVEN("v <-vector(1, -1, 0)")
{
Tuple v = Tuple::Vector(1, -1, 0);
AND_GIVEN("n <-vector(0, 1, 0)")
{
Tuple n = Tuple::Vector(0, 1, 0);
WHEN("r <- reflect(v,n)")
{
Tuple r = v.reflect(n);
THEN("r = vector(1,1,0)")
{
REQUIRE(r == Tuple::Vector(1, 1, 0));
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Reflecting a vector off a slanted surface", "[features/tuples.feature]")
{
GIVEN("v <-vector(0, -1, 0)")
{
Tuple v = Tuple::Vector(0, -1, 0);
AND_GIVEN("n <-vector(sqrt(2)/2, sqrt(2)/2, 0)")
{
Tuple n = Tuple::Vector(sqrt(2) / 2, sqrt(2) / 2, 0);
WHEN("r <- reflect(v,n)")
{
Tuple r = v.reflect(n);
THEN("r = vector(1,0,0)")
{
REQUIRE(r == Tuple::Vector(1, 0, 0));
}
}
}
}
}