# Commits

committed e570a1a

Started working on inverse support, unfortunately broken.

• Participants
• Parent commits 3bb4e15

# File neglect/cpplib/include/neglect/matrix.hpp

`             return m_cols[row];`
`         }`
` `
`+        /* create a new matrix by exluding a row and column */`
`         matrix<T, M - 1, N - 1> exclude(size_t row, size_t column) const`
`         {`
`             assert(row < M);`
`             return rv;`
`         }`
` `
`-        T minor(size_t row, size_t column) const`
`-        {`
`-            return det(exclude(row, column));`
`-        }`
`-`
`-        T cofactor(size_t row, size_t column) const`
`-        {`
`-            return math::pow(T(-1), (row + column)) * minor(row, column);`
`-        }`
`-`
`-        T determinant() const`
`-        {`
`-            T sum = T();`
`-            for (size_t i = 0; i < N; i++)`
`-                sum += m_cols[i][0] * cofactor(i, 0);`
`-            return sum;`
`-        }`
`-`
`     private:`
`         neglect::vector<T, M> m_cols[N];`
`     };`
`         return rv;`
`     }`
` `
`+    /* determinant of a square matrix */`
`+`
`+    template <typename T, size_t N>`
`+    T determinant(const matrix<T, N, N> &mat)`
`+    {`
`+        T sum = T();`
`+        for (size_t i = 0; i < N; i++)`
`+            sum += mat[i][0] * math::pow(T(-1), static_cast<T>(i))`
`+                * determinant(mat.exclude(i, 0));`
`+        return sum;`
`+    }`
`+`
`+    template <typename T>`
`+    T determinant(const matrix<T, 2, 2> &mat)`
`+    {`
`+        return mat(0, 0) * mat(1, 1) - mat(0, 1) * mat(1, 0);`
`+    }`
`+`
`     /* creates a scale matrix */`
`     template <typename T>`
`     matrix<T, 4, 4> scale_matrix(T sx, T zy, T sz)`

# File neglect/tests/src/test_matrix.cpp

`         m1x(2, 2) = 100.0f;`
`         NUT_CHECK_NOT_EQUAL(m1x, expected);`
`     }`
`+`
`+    NUT_TESTCASE(matrix_determinant)`
`+    {`
`+        mat4 m1;`
`+        m1[0] = vec4( 1,  2,  3,  4);`
`+        m1[1] = vec4( 5,  6,  7,  8);`
`+        m1[2] = vec4( 9, 10, 11, 12);`
`+        m1[3] = vec4(13, 14, 15, 16);`
`+        NUT_CHECK_EQUAL(determinant(m1), 0);`
`+    }`
` }`