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

matrix_identity.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_IDENTITY_HPP
9 #define EAGINE_MATH_MATRIX_IDENTITY_HPP
10 
11 #include "matrix_ctr.hpp"
12 
13 namespace eagine::math {
14 
15 template <typename X>
16 class identity;
17 
18 // is_matrix_constructor<identity>
19 template <typename T, int R, int C, bool RM, bool V>
20 struct is_matrix_constructor<identity<matrix<T, R, C, RM, V>>>
21  : std::true_type {};
22 
27 template <typename T, int R, int C, bool RM, bool V>
28 class identity<matrix<T, R, C, RM, V>> {
29 public:
31  constexpr auto operator()() const noexcept -> matrix<T, R, C, RM, V> {
32  using _riS = _make_useq<RM ? R : C>;
33  return _identity(_riS());
34  }
35 
36 private:
37  template <int... U>
38  using _useq = std::integer_sequence<int, U...>;
39 
40  template <int N>
41  using _make_useq = std::make_integer_sequence<int, N>;
42 
43  template <int... I>
44  static constexpr auto _identity(_useq<I...>) noexcept
46  return {{vect::axis < T, RM ? C : R, I, V > ::apply(1)...}};
47  }
48 };
49 
50 // multiply
51 template <typename T, int C, int R, bool RM1, bool RM2, bool V>
52 static constexpr auto multiply(
53  const identity<matrix<T, C, R, RM1, V>>&,
54  const identity<matrix<T, C, R, RM2, V>>&) noexcept
55  -> identity<matrix<T, C, R, RM1, V>> {
56  return {};
57 }
58 
59 // multiply
60 template <
61  typename MC,
62  typename T,
63  int C,
64  int R,
65  bool RM,
66  bool V,
67  typename = std::enable_if_t<
68  is_matrix_constructor_v<MC> &&
69  are_multiplicable<constructed_matrix_t<MC>, matrix<T, C, R, RM, V>>::value>>
70 static constexpr auto
71 multiply(const MC& mc, const identity<matrix<T, C, R, RM, V>>&) noexcept -> MC {
72  return mc;
73 }
74 
75 template <
76  typename T,
77  int C,
78  int R,
79  bool RM,
80  bool V,
81  typename MC,
82  typename = std::enable_if_t<
83  is_matrix_constructor_v<MC> &&
84  are_multiplicable<matrix<T, C, R, RM, V>, constructed_matrix_t<MC>>::value>>
85 static constexpr auto
86 multiply(const identity<matrix<T, C, R, RM, V>>&, const MC& mc) noexcept -> MC {
87  return mc;
88 }
89 
90 // reorder_mat_ctr(identity)
91 template <typename T, int R, int C, bool RM, bool V>
92 static constexpr auto
93 reorder_mat_ctr(const identity<matrix<T, R, C, RM, V>>&) noexcept
94  -> identity<matrix<T, R, C, !RM, V>> {
95  return {};
96 }
97 
98 } // namespace eagine::math
99 
100 #endif // EAGINE_MATH_MATRIX_IDENTITY_HPP
constexpr auto operator()() const noexcept -> matrix< T, R, C, RM, V >
Returns an identity matrix.
Definition: matrix_identity.hpp:31
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
static auto multiply(const matrix< T, K, M, RM1, V > &m1, const matrix< T, N, K, RM2, V > &m2) noexcept -> matrix< T, N, M, RM1, V >
Matrix multiplication function.
Definition: matrix.hpp:529
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).