[FEAT] Matrix Add inverter

This commit is contained in:
NADAL Jean-Baptiste
2024-02-05 12:13:16 +01:00
parent 8461c3da6b
commit f847550686
3 changed files with 61 additions and 2 deletions

View File

@@ -27,8 +27,7 @@
#include <catch.hpp>
#include "matrix.h"
#include "tuple.h"
#include "raytracing.h"
using namespace Raytracer;
@@ -374,3 +373,32 @@ TEST_CASE("[Matrix] Testing an noninvertible matrix for invertibility", "[Matrix
REQUIRE(a.determinant() == 0);
REQUIRE(a.invertible() == false);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] Calculating the inverse of a matrix", "[Matrix]")
{
Matrix a = {
{-5, 2, 6, -8},
{ 1, -5, 1, 8},
{ 7, 7, -6, -7},
{ 1, -3, 7, 4}
};
Matrix b_inverted = {
{ 0.21805, 0.45113, 0.24060, -0.04511},
{-0.80827, -1.45677, -0.44361, 0.52068},
{-0.07895, -0.22368, -0.05263, 0.19737},
{-0.52256, -0.81391, -0.30075, 0.30639}
};
auto [b, the_status] = a.inverse();
REQUIRE(the_status == true);
REQUIRE(a.determinant() == 532);
REQUIRE(a.cofactor(2, 3) == -160);
REQUIRE(b[3][2] == -160.0 / 532.0);
REQUIRE(a.cofactor(3, 2) == 105);
REQUIRE(b[2][3] == 105.0 / 532.0);
REQUIRE(b == b_inverted);
}