mirror of
https://github.com/thunderbrewhq/typhoon.git
synced 2025-12-12 02:22:30 +00:00
feat(matrix): add C44Matrix::Determinant
This commit is contained in:
parent
7da043cd47
commit
63a478841a
3 changed files with 25 additions and 0 deletions
|
|
@ -23,3 +23,7 @@ C44Matrix C44Matrix::Adjoint() const {
|
||||||
|
|
||||||
return C44Matrix(a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3);
|
return C44Matrix(a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float C44Matrix::Determinant() {
|
||||||
|
return (this->b1 * this->c2 * this->d3 + this->c3 * this->b2 * this->d1 + this->b3 * this->c1 * this->d2 - this->c2 * this->b3 * this->d1 - this->d3 * (this->c1 * this->b2) - this->b1 * this->c3 * this->d2) * this->a0 - (this->c2 * this->b0 * this->d3 + this->c3 * this->b2 * this->d0 + this->b3 * this->c0 * this->d2 - this->b3 * this->c2 * this->d0 - this->d3 * (this->c0 * this->b2) - this->b0 * this->c3 * this->d2) * this->a1 + (this->c1 * this->b0 * this->d3 + this->c3 * this->b1 * this->d0 + this->b3 * this->c0 * this->d1 - this->b3 * this->c1 * this->d0 - this->d3 * (this->c0 * this->b1) - this->b0 * this->c3 * this->d1) * this->a2 - (this->c1 * this->b0 * this->d2 + this->c2 * this->b1 * this->d0 + this->b2 * this->c0 * this->d1 - this->b2 * this->c1 * this->d0 - this->d2 * (this->c0 * this->b1) - this->b0 * this->c2 * this->d1) * this->a3;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ class C44Matrix {
|
||||||
, d2(d2)
|
, d2(d2)
|
||||||
, d3(d3) {};
|
, d3(d3) {};
|
||||||
C44Matrix Adjoint() const;
|
C44Matrix Adjoint() const;
|
||||||
|
float Determinant();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -107,3 +107,23 @@ TEST_CASE("C44Matrix::Adjoint", "[matrix]") {
|
||||||
CHECK(matrix.d3 == 16.0f);
|
CHECK(matrix.d3 == 16.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("C44Matrix::Determinant", "[matrix]") {
|
||||||
|
SECTION("returns determinant of identity matrix") {
|
||||||
|
C44Matrix matrix;
|
||||||
|
auto determinant = matrix.Determinant();
|
||||||
|
REQUIRE(determinant == 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns determinant of zero matrix") {
|
||||||
|
auto matrix = C44Matrix(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
auto determinant = matrix.Determinant();
|
||||||
|
REQUIRE(determinant == 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns determinant of non-identity matrix") {
|
||||||
|
auto matrix = C44Matrix(-1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, -11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f);
|
||||||
|
auto determinant = matrix.Determinant();
|
||||||
|
REQUIRE(determinant == -704.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue