[FEAT] Add Matrix * Tuple

This commit is contained in:
NADAL Jean-Baptiste
2024-02-01 18:43:27 +01:00
parent 7201bfdf4c
commit 221a1e01e3
6 changed files with 201 additions and 9 deletions

View File

@@ -28,6 +28,7 @@
#include <catch.hpp>
#include "matrix.h"
#include "tuple.h"
using namespace Raytracer;
@@ -129,3 +130,44 @@ TEST_CASE("[Matrix] Matrix equality with different matrices", "[Matrix]")
REQUIRE(a != b);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] Multiplying two matrices", "[Matrix]")
{
Matrix a = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 8, 7, 6},
{5, 4, 3, 2}
};
Matrix b = {
{-2, 1, 2, 3},
{ 3, 2, 1, -1},
{ 4, 3, 6, 5},
{ 1, 2, 7, 8}
};
Matrix c = {
{20, 22, 50, 48},
{44, 54, 114, 108},
{40, 58, 110, 102},
{16, 26, 46, 42}
};
REQUIRE((a * b) == c);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] a matrix multiplied by a tuple", "[Matrix]")
{
Matrix a = {
{1, 2, 3, 4},
{2, 4, 4, 2},
{8, 6, 4, 1},
{0, 0, 0, 1}
};
Tuple b(1, 2, 3, 1);
REQUIRE((a * b) == Tuple(18, 24, 33, 1));
}