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

tmat.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_TMAT_HPP
9 #define EAGINE_MATH_TMAT_HPP
10 
11 #include "../all_are_same.hpp"
12 #include "matrix.hpp"
13 #include "matrix_identity.hpp"
14 
15 namespace eagine {
16 namespace math {
17 
20 template <typename T, int C, int R, bool RM, bool V>
21 struct tmat : matrix<T, C, R, RM, V> {
24 
26  constexpr tmat() noexcept
27  : base{identity<base>{}()} {}
28 
30  constexpr tmat(const base& m) noexcept
31  : base{m} {}
32 
34  tmat(const T* d, int n) noexcept
35  : base{base::from(d, n)} {}
36 
38  tmat(const T (&d)[C * R]) noexcept
39  : base{base::from(d, C * R)} {}
40 
41 private:
42  template <
43  typename... P,
44  typename = std::enable_if_t<
45  ((sizeof...(P)) == (C * R)) && all_are_convertible_to<T, P...>::value>>
46  static auto _make(P&&... p) {
47  T d[C * R] = {T(p)...};
48  return base::from(d, C * R);
49  }
50 
51 public:
52  template <
53  typename... P,
54  typename = std::enable_if_t<
55  ((sizeof...(P)) == (R * C)) && all_are_convertible_to<T, P...>::value>>
56  tmat(P&&... p)
57  : base(_make(std::forward<P>(p)...)) {}
58 
59  template <
60  typename... P,
61  typename = std::enable_if_t<((sizeof...(P)) == (RM ? R : C))>>
62  constexpr tmat(const vector<P, RM ? C : R, V>&... v) noexcept
63  : base{{v._v...}} {}
64 
65  template <
66  typename P,
67  int M,
68  int N,
69  typename =
70  std::enable_if_t<std::is_convertible_v<P, T> && (C <= M) && (R <= N)>>
71  constexpr tmat(const matrix<P, M, N, RM, V>& m) noexcept
72  : base{base::from(m)} {}
73 };
74 
75 template <typename T, int C, int R, bool RM, bool V>
76 struct is_row_major<math::tmat<T, C, R, RM, V>> : bool_constant<RM> {};
77 
78 } // namespace math
79 
80 template <typename T, int C, int R, bool RM, bool V>
81 struct is_known_matrix_type<math::tmat<T, C, R, RM, V>> : std::is_scalar<T> {};
82 
83 template <typename T, int C, int R, bool RM, bool V>
84 struct canonical_compound_type<math::tmat<T, C, R, RM, V>>
85  : type_identity<std::remove_cv_t<T[C][R]>> {};
86 
87 template <typename T, int C, int R, bool RM, bool V>
88 struct compound_view_maker<math::tmat<T, C, R, RM, V>> {
89  auto operator()(const math::tmat<T, C, R, RM, V>& m) const noexcept {
90  return vect::view < T, RM ? C : R, V > ::apply(m._v);
91  }
92 };
93 
94 template <typename T, int C, int R, bool RM, bool V>
95 struct is_row_major<math::tmat<T, C, R, RM, V>> : bool_constant<RM> {};
96 
97 } // namespace eagine
98 
99 #endif // EAGINE_MATH_TMAT_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
constexpr tmat() noexcept
Default constructor. Constructs identity matrix.
Definition: tmat.hpp:26
constexpr tmat(const base &m) noexcept
Construction from a base matrix.
Definition: tmat.hpp:30
std::integral_constant< bool, B > bool_constant
Alias for boolean constant type.
Definition: int_constant.hpp:20
math::tmat< T, C, R, RM, V > tmat
Template alias for math::tmat.
Definition: matrix.hpp:24
tmat(const T(&d)[C *R]) noexcept
Construction from element data array.
Definition: tmat.hpp:38
static auto from(const P *dt, span_size_t sz) noexcept -> matrix
Creates a matrix from data pointer and size.
Definition: matrix.hpp:49
matrix< T, C, R, RM, V > base
The base matrix type.
Definition: tmat.hpp:23
Basic RxC matrix implementation template.
Definition: fwd.hpp:25
tmat(const T *d, int n) noexcept
Construction from element data pointer and count.
Definition: tmat.hpp:34

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