[FEAT] Matrix : add minor

This commit is contained in:
NADAL Jean-Baptiste
2024-02-02 17:50:54 +01:00
parent a584bf54d8
commit 45dc3049e7
3 changed files with 25 additions and 0 deletions

View File

@@ -226,6 +226,13 @@ Matrix Matrix::sub_matrix(uint8_t a_rows, uint8_t a_cols)
/* ------------------------------------------------------------------------- */
double Matrix::minor(uint8_t a_rows, uint8_t a_cols)
{
return sub_matrix(a_rows, a_cols).determinant();
}
/* ------------------------------------------------------------------------- */
Matrix Matrix::identity(void)
{
Matrix the_identity = {

View File

@@ -62,6 +62,7 @@ namespace Raytracer
bool transpose(void);
double determinant(void);
Matrix sub_matrix(uint8_t a_rows, uint8_t a_cols);
double minor(uint8_t a_rows, uint8_t a_cols);
static Matrix identity(void);

View File

@@ -277,3 +277,20 @@ TEST_CASE("[Matrix] A submatrix of a 4x4 matrix is a 3x3 matrix", "[Matrix]")
REQUIRE(a.sub_matrix(2, 1) == b);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] Calculating a minor of a 3x3 matrix", "[Matrix]")
{
Matrix a = {
{3, 5, 0},
{2, -1, -7},
{6, -1, 5}
};
Matrix b = a.sub_matrix(1, 0);
REQUIRE(b.determinant() == 25);
REQUIRE(a.minor(1, 0) == 25);
}