[FEAT] Add Normal

This commit is contained in:
NADAL Jean-Baptiste
2024-02-16 16:14:51 +01:00
parent 53cf65fda2
commit 8c75d297a7
7 changed files with 99 additions and 17 deletions

View File

@@ -324,9 +324,7 @@ SCENARIO("Transposing a matrix", "[features/matrices.feature]")
{0, 8, 3, 8}
};
A.transpose();
REQUIRE(A == transposed);
REQUIRE(A.transpose() == transposed);
}
}
}
@@ -337,9 +335,8 @@ SCENARIO("Transposing the identity matrix", "[features/matrices.feature]")
{
GIVEN("A <- transpose(identity_matrix)")
{
Matrix A = Matrix::identity();
Matrix A = Matrix::identity().transpose();
A.transpose();
THEN("A = identity_matrix")
{
REQUIRE(A == Matrix::identity());

View File

@@ -120,3 +120,51 @@ SCENARIO("The normal is a normalized vector", "[features/spheres.feature]")
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Computing the normal on a translated sphere", "[features/spheres.feature]")
{
GIVEN("s <- sphere()")
{
Sphere s;
AND_GIVEN("set_transform(s, translation(0,1,0))")
{
s.set_transform(Matrix::translation(0, 1, 0));
WHEN("n <- normal_at(s,point(0,1.70711,-0.70711))")
{
Tuple n = s.normal_at(Tuple::Point(0, 1.70711, -0.70711));
THEN("n = vector(0,0.70711, -0.70711)")
{
REQUIRE(n == Tuple::Vector(0, 0.70711, -0.70711));
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Computing the normal on a transformed sphere", "[features/spheres.feature]")
{
GIVEN("s <- sphere()")
{
Sphere s;
AND_GIVEN("m <- scaling(1,0.5,1) * rotation_z(pi/5)")
{
Matrix m = Matrix::scaling(1, 0.5, 1) * Matrix::rotation_z(std::numbers::pi / 5);
AND_GIVEN("set_transform(s, m)")
{
s.set_transform(m);
WHEN("n <- normal_at(s,point(0,sqrt(2)/2,sqrt(2)/2))")
{
Tuple n = s.normal_at(Tuple::Point(0, sqrt(2) / 2, -sqrt(2) / 2));
THEN("n = vector(0,97014, -0.24254)")
{
REQUIRE(n == Tuple::Vector(0, 0.97014, -0.24254));
}
}
}
}
}
}