OGLplus  (0.59.0) a C++ wrapper for rendering APIs

matrix_inverse.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_INVERSE_HPP
9 #define EAGINE_MATH_MATRIX_INVERSE_HPP
10 
11 #include "../valid_if/decl.hpp"
12 #include "matrix_gauss.hpp"
13 #include "matrix_identity.hpp"
14 
15 namespace eagine::math {
16 //------------------------------------------------------------------------------
19 template <typename T, int N, bool RM, bool V>
20 static inline auto inverse_matrix(matrix<T, N, N, RM, V> m) noexcept
22  auto i = identity<matrix<T, N, N, RM, V>>()();
23  if(gauss_jordan_elimination(m, i)) {
24  return {i, true};
25  }
26  return {};
27 }
28 //------------------------------------------------------------------------------
31 template <typename Ctr, typename = std::enable_if_t<is_matrix_constructor_v<Ctr>>>
32 static inline auto inverse_matrix(const Ctr& ctr) noexcept {
33  // TODO: reorder to row major?
34  return inverse_matrix(ctr());
35 }
36 //------------------------------------------------------------------------------
37 } // namespace eagine::math
38 
39 #endif // EAGINE_MATH_MATRIX_INVERSE_HPP
static auto inverse_matrix(matrix< T, N, N, RM, V > m) noexcept -> optionally_valid< matrix< T, N, N, RM, V >>
Returns the inverse matrix to the matrix passed as argument.
Definition: matrix_inverse.hpp:20
Primary template for conditionally valid values.
Definition: decl.hpp:49
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
static auto gauss_jordan_elimination(matrix< T, Ca, R, true, V > &a, matrix< T, Cb, R, true, V > &b) noexcept -> bool
Implements gauss-jordan elimination on matrices a and b.
Definition: matrix_gauss.hpp:112
Basic RxC matrix implementation template.
Definition: fwd.hpp:25

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).