[FEAT] Matrix : add minor
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user