[FEAT] Matrix add dertminant

This commit is contained in:
NADAL Jean-Baptiste
2024-02-02 16:39:45 +01:00
parent 76144ffba2
commit bab4ba5a2b
3 changed files with 20 additions and 0 deletions

View File

@@ -190,6 +190,13 @@ bool Matrix::transpose(void)
/* ------------------------------------------------------------------------- */
double Matrix::determinant(void)
{
return (m_data[0][0] * m_data[1][1]) - (m_data[0][1] * m_data[1][0]);
}
/* ------------------------------------------------------------------------- */
Matrix Matrix::identity(void)
{
Matrix the_identity = {

View File

@@ -58,6 +58,7 @@ namespace Raytracer
const Tuple operator*(const Tuple &a_tuple) const;
bool transpose(void);
double determinant(void);
static Matrix identity(void);

View File

@@ -227,3 +227,15 @@ TEST_CASE("[Matrix] Transposing the identity matrix", "[Matrix]")
REQUIRE(a == Matrix::identity());
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] Calculating the determinant of a 2x2 matrix", "[Matrix]")
{
Matrix a = {
{ 1, 5},
{-3, 2}
};
REQUIRE(a.determinant() == 17);
}