[FEAT] Add scaling

This commit is contained in:
NADAL Jean-Baptiste
2024-02-05 17:32:22 +01:00
parent b531e0b714
commit dbac8a37c4
3 changed files with 56 additions and 0 deletions

View File

@@ -61,3 +61,44 @@ TEST_CASE("[04][TRANSFORMATION] Translation does not affect vectors", "[Matrix]"
REQUIRE(transform * v == v);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] A scaling matrix applied to a point", "[Matrix]")
{
Matrix transform = Matrix::scaling(2, 3, 4);
Tuple p = Tuple::Point(-4, 6, 8);
REQUIRE(transform * p == Tuple::Point(-8, 18, 32));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] A scaling matrix applied to a vector", "[Matrix]")
{
Matrix transform = Matrix::scaling(2, 3, 4);
Tuple v = Tuple::Vector(-4, 6, 8);
REQUIRE(transform * v == Tuple::Vector(-8, 18, 32));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] Multiplying by the inverse of a scaling matrix", "[Matrix]")
{
Matrix transform = Matrix::scaling(2, 3, 4);
Matrix inv = transform.inverse();
Tuple v = Tuple::Vector(-4, 6, 8);
REQUIRE(inv * v == Tuple::Vector(-2, 2, 2));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] Reflection is scaling by a negative value", "[Matrix]")
{
Matrix transform = Matrix::scaling(-1, 1, 1);
Tuple p = Tuple::Point(2, 3, 4);
REQUIRE(transform * p == Tuple::Point(-2, 3, 4));
}