11 #pragma warning(disable : 4365 4987)
24 lhs[1] * rhs[2] - lhs[2] * rhs[1],
25 lhs[2] * rhs[0] - lhs[0] * rhs[2],
26 lhs[0] * rhs[1] - lhs[1] * rhs[0]
30template<dim_t L,
typename T>
32 return (lhs * rhs).sum();
35template<dim_t L,
typename T>
40template<dim_t R, dim_t C,
typename T>
45template<dim_t L,
typename T>
46inline typename std::enable_if<std::is_floating_point<T>::value, T>::type
length(
const vec<L, T>& v) {
50template<dim_t L,
typename T>
56template<dim_t R, dim_t C,
typename T>
68#pragma push_macro("minor")
71template<dim_t N,
typename T>
73 for (
dim_t outRow{}, inRow{}; inRow < dimensions; ++inRow) {
74 for (
dim_t outCol{}, inCol{}; inCol < dimensions; ++inCol) {
75 if ((inRow != i) && (inCol != j)) {
76 output(outRow, outCol) = input(inRow, inCol);
78 if (outCol == (dimensions -
static_cast<dim_t>(1))) {
87template<dim_t N,
typename T>
89 if (dimensions ==
static_cast<dim_t>(1)) {
95 auto sign =
static_cast<T
>(1);
97 for (
dim_t j{}; j < dimensions; ++j) {
98 minor(m, dimensions, i, j, temp);
99 result += (sign * m(i, j) *
determinant(temp, dimensions - 1));
106template<dim_t N,
typename T>
108 if (m.rows() ==
static_cast<dim_t>(1)) {
114 for (
dim_t row{}; row < m.rows(); ++row) {
115 for (
dim_t col{}; col < m.columns(); ++col) {
116 minor(m, N, row, col, temp);
117 const T sign =
static_cast<T
>((row + col) % 2u == 0u ? 1 : -1);
118 result(col, row) = (sign *
determinant(temp, N - 1));
124#pragma pop_macro("minor")
128template<dim_t N,
typename T>
133template<dim_t N,
typename T>
142 for (
dim_t row{}; row < m.rows(); ++row) {
143 for (
dim_t col{}; col < m.columns(); ++col) {
144 inv(row, col) = adj(row, col) / det;
150template<dim_t N,
typename T>
153 for (
dim_t row{}; row < m.rows(); ++row) {
154 trace += m(row, row);
void minor(const mat< N, N, T > &input, dim_t dimensions, dim_t i, dim_t j, mat< N, N, T > &output)
Definition: Computations.h:72
mat< N, N, T > adjoint(const mat< N, N, T > &m)
Definition: Computations.h:107
T determinant(const mat< N, N, T > &m, dim_t dimensions)
Definition: Computations.h:88
Definition: Computations.h:19
std::enable_if< std::is_floating_point< T >::value, vec< L, T > >::type normalize(vec< L, T > v)
Definition: Computations.h:51
std::size_t dim_t
Definition: Types.h:22
T dot(const vec< L, T > &lhs, const vec< L, T > &rhs)
Definition: Computations.h:31
vec< L, T > negate(vec< L, T > v)
Definition: Computations.h:36
T determinant(const mat< N, N, T > &m)
Definition: Computations.h:129
std::enable_if< std::is_floating_point< T >::value, T >::type length(const vec< L, T > &v)
Definition: Computations.h:46
vec3< T > cross(const vec3< T > &lhs, const vec3< T > &rhs)
Definition: Computations.h:22
mat< C, R, T > transpose(const mat< R, C, T > &m)
Definition: Computations.h:57
T trace(const mat< N, N, T > &m)
Definition: Computations.h:151
mat< N, N, T > inverse(const mat< N, N, T > &m)
Definition: Computations.h:134
mat & apply(F func)
Definition: Mat.h:140
std::enable_if< std::is_floating_point< V >::value, V >::type length() const
Definition: Vec.h:168
vec & negate()
Definition: Vec.h:178
std::enable_if< std::is_floating_point< V >::value, vec & >::type normalize()
Definition: Vec.h:174