[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

@@ -64,6 +64,46 @@ TEST_CASE("[Tuple] a tuple with w=0 is a vector", "[Tuple]")
/* ------------------------------------------------------------------------- */
TEST_CASE("[Tuple] access of data with []", "[Tuple]")
{
Tuple a(4.3, -4.2, 3.1, 0.0);
REQUIRE(a[0] == 4.3);
REQUIRE(a[1] == -4.2);
REQUIRE(a[2] == 3.1);
REQUIRE(a[3] == 0.0);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Tuple] constructor with std::vector", "[Tuple]")
{
std::vector<double> v = {4.3, -4.2, 3.1, 0.0};
Tuple a(v);
REQUIRE(a[0] == 4.3);
REQUIRE(a[1] == -4.2);
REQUIRE(a[2] == 3.1);
REQUIRE(a[3] == 0.0);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Tuple] test copy constructor", "[Tuple]")
{
Tuple a;
Tuple b(4.3, -4.2, 3.1, 0.0);
a = b;
REQUIRE(a[0] == 4.3);
REQUIRE(a[1] == -4.2);
REQUIRE(a[2] == 3.1);
REQUIRE(a[3] == 0.0);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Tuple] Tuple could be copy", "[Tuple]")
{
Tuple p = Tuple::Point(4, -4, 3);

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));
}