[FEAT] Matrix add dertminant
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace Raytracer
|
||||
const Tuple operator*(const Tuple &a_tuple) const;
|
||||
|
||||
bool transpose(void);
|
||||
double determinant(void);
|
||||
|
||||
static Matrix identity(void);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user