diff --git a/include/omath/mat.hpp b/include/omath/mat.hpp index 9bb653f..93d3771 100644 --- a/include/omath/mat.hpp +++ b/include/omath/mat.hpp @@ -359,6 +359,25 @@ namespace omath }; } + [[nodiscard]] + constexpr std::optional Inverted() const + { + const auto det = Determinant(); + + if (det == 0) + return std::nullopt; + + const auto transposed = Transposed(); + Mat result; + + for (std::size_t row = 0; row < Rows; row++) + for (std::size_t column = 0; column < Rows; column++) + result.At(row, column) = transposed.AlgComplement(row, column); + + result /= det; + + return {result}; + } private: std::array m_data; };