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

matrix_ctr.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_MATRIX_CTR_HPP
9 #define EAGINE_MATH_MATRIX_CTR_HPP
10 
11 #include "../nothing.hpp"
12 #include "matrix.hpp"
13 
14 namespace eagine {
15 namespace math {
16 
17 template <template <class> class MC, typename T, int C, int R, bool RM, bool V>
18 struct constructed_matrix<MC<matrix<T, C, R, RM, V>>>
19  : std::conditional_t<
20  is_matrix_constructor_v<MC<matrix<T, C, R, RM, V>>>,
21  matrix<T, C, R, RM, V>,
22  nothing_t> {};
23 
24 template <
25  template <class, int>
26  class MC,
27  typename T,
28  int C,
29  int R,
30  bool RM,
31  bool V,
32  int I>
33 struct constructed_matrix<MC<matrix<T, C, R, RM, V>, I>>
34  : std::conditional_t<
35  is_matrix_constructor_v<MC<matrix<T, C, R, RM, V>, I>>,
36  matrix<T, C, R, RM, V>,
37  nothing_t> {};
38 
41 template <bool RM, typename MC>
42 static constexpr auto construct_matrix(const MC& c) noexcept -> std::enable_if_t<
43  is_matrix_constructor_v<MC> && is_row_major_v<constructed_matrix_t<MC>> == RM,
45  return c();
46 }
47 
48 // construct_matrix (reorder)
49 template <bool RM, typename MC>
50 static constexpr auto construct_matrix(const MC& c) noexcept -> std::enable_if_t<
51  is_matrix_constructor_v<MC> && is_row_major_v<constructed_matrix_t<MC>> != RM,
52  reordered_matrix_t<constructed_matrix_t<MC>>> {
53  return reorder_mat_ctr(c)();
54 }
55 
61 template <
62  typename MC1,
63  typename MC2,
64  typename = std::enable_if_t<
65  is_matrix_constructor_v<MC1> && is_matrix_constructor_v<MC2> &&
66  are_multiplicable<constructed_matrix_t<MC1>, constructed_matrix_t<MC2>>::value>>
67 static inline auto multiply(const MC1& mc1, const MC2& mc2) noexcept {
68  return multiply(construct_matrix<true>(mc1), construct_matrix<false>(mc2));
69 }
70 
73 template <typename MC>
74 class convertible_matrix_constructor : public MC {
75  static_assert(is_matrix_constructor_v<MC>);
76 
77 public:
79  template <typename... P>
81  : MC(std::forward<P>(p)...) {}
82 
84  operator constructed_matrix_t<MC>() const noexcept {
85  return MC::operator()();
86  }
87 };
88 
89 template <typename MC>
90 struct is_matrix_constructor<convertible_matrix_constructor<MC>>
91  : is_matrix_constructor<MC> {};
92 
93 template <typename MC>
94 struct constructed_matrix<convertible_matrix_constructor<MC>>
95  : constructed_matrix<MC> {};
96 
97 } // namespace math
98 
99 template <typename MC>
100 struct is_known_matrix_type<math::convertible_matrix_constructor<MC>>
101  : is_known_matrix_type<math::constructed_matrix_t<MC>> {};
102 
103 template <typename MC>
104 struct canonical_compound_type<math::convertible_matrix_constructor<MC>>
105  : canonical_compound_type<math::constructed_matrix_t<MC>> {};
106 
107 template <typename MC>
108 struct compound_view_maker<math::convertible_matrix_constructor<MC>> {
109  struct _result_type {
110  using M = math::constructed_matrix_t<MC>;
111  using T = typename M::element_type;
112  M _m;
113 
114  operator span<const T>() const noexcept {
115  compound_view_maker<M> cvm;
116  return cvm(_m);
117  }
118  };
119 
120  auto operator()(
121  const math::convertible_matrix_constructor<MC>& mc) const noexcept {
122  return _result_type{mc()};
123  }
124 };
125 
126 template <typename MC>
127 struct is_row_major<math::convertible_matrix_constructor<MC>>
128  : math::is_row_major<math::constructed_matrix_t<MC>> {};
129 
130 } // namespace eagine
131 
132 #endif // EAGINE_MATH_MATRIX_CTR_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
typename constructed_matrix< X >::type constructed_matrix_t
Trait returning the matrix type constructed by constructor type X.
Definition: matrix.hpp:496
convertible_matrix_constructor(P &&... p)
Forwards arguments to the basic matrix constructor.
Definition: matrix_ctr.hpp:80
Helper class used in matrix constructor implementation.
Definition: matrix_ctr.hpp:74
static constexpr auto construct_matrix(const MC &c) noexcept -> std::enable_if_t< is_matrix_constructor_v< MC > &&is_row_major_v< constructed_matrix_t< MC >>==RM, constructed_matrix_t< MC >>
Uses the specified matrix constructor c to construct a matrix.
Definition: matrix_ctr.hpp:42
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

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