Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TMatrixMxNBase.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <utility>
8
9namespace ph::math
10{
11
12template<typename Derived, typename T, std::size_t M, std::size_t N>
14{
15 set(elements);
16}
17
18template<typename Derived, typename T, std::size_t M, std::size_t N>
20 m(std::move(elements))
21{}
22
23template<typename Derived, typename T, std::size_t M, std::size_t N>
24inline constexpr std::size_t TMatrixMxNBase<Derived, T, M, N>::numRows() const noexcept
25{
26 return NUM_ROWS;
27}
28
29template<typename Derived, typename T, std::size_t M, std::size_t N>
30inline constexpr std::size_t TMatrixMxNBase<Derived, T, M, N>::numCols() const noexcept
31{
32 return NUM_COLS;
33}
34
35template<typename Derived, typename T, std::size_t M, std::size_t N>
36inline auto TMatrixMxNBase<Derived, T, M, N>::mul(const T constantValue) const
37-> Derived
38{
39 return Derived(static_cast<const Derived&>(*this)).mulLocal(constantValue);
40}
42template<typename Derived, typename T, std::size_t M, std::size_t N>
43inline auto TMatrixMxNBase<Derived, T, M, N>::mulLocal(const T constantValue)
44-> Derived&
45{
46 for(std::size_t ri = 0; ri < M; ++ri)
47 {
48 for(std::size_t ci = 0; ci < N; ++ci)
49 {
50 m[ri][ci] *= constantValue;
51 }
52 }
53 return static_cast<Derived&>(*this);
55
56template<typename Derived, typename T, std::size_t M, std::size_t N>
61 for(std::size_t ri = 0; ri < M; ++ri)
62 {
63 T result = static_cast<T>(0);
64 for(std::size_t ci = 0; ci < N; ++ci)
65 {
66 result += m[ri][ci] * rhsColVector[ci];
67 }
68 col[ri] = result;
69 }
70 return col;
73template<typename Derived, typename T, std::size_t M, std::size_t N>
74template<std::size_t K>
76{
77 PH_ASSERT(out_result);
78
79 for(std::size_t mi = 0; mi < M; ++mi)
80 {
81 for(std::size_t ki = 0; ki < K; ++ki)
82 {
83 T result = static_cast<T>(0);
84 for(std::size_t ni = 0; ni < N; ++ni)
85 {
86 result += m[mi][ni] * rhsMatrix[ni][ki];
87 }
88 (*out_result)[mi][ki] = result;
89 }
90 }
91}
92
93template<typename Derived, typename T, std::size_t M, std::size_t N>
94template<std::size_t K>
96{
97 PH_ASSERT(out_result);
98
99 for(std::size_t mi = 0; mi < M; ++mi)
100 {
101 for(std::size_t ki = 0; ki < K; ++ki)
102 {
103 T result = static_cast<T>(0);
104 for(std::size_t ni = 0; ni < N; ++ni)
105 {
106 result += m[mi][ni] * rhsMatrix[ki][ni];
107 }
108 (*out_result)[mi][ki] = result;
109 }
110 }
111}
112
113template<typename Derived, typename T, std::size_t M, std::size_t N>
115-> TRawMatrix<T, N, M>
116{
117 TRawMatrix<T, N, M> result;
118 for(std::size_t ri = 0; ri < M; ++ri)
119 {
120 for(std::size_t ci = 0; ci < N; ++ci)
121 {
122 result[ci][ri] = m[ri][ci];
123 }
124 }
125 return result;
126}
127
128template<typename Derived, typename T, std::size_t M, std::size_t N>
129inline auto TMatrixMxNBase<Derived, T, M, N>::set(const T constantValue)
130-> Derived&
131{
132 for(std::size_t ri = 0; ri < M; ++ri)
133 {
134 m[ri].fill(constantValue);
135 }
136 return static_cast<Derived&>(*this);
137}
138
139template<typename Derived, typename T, std::size_t M, std::size_t N>
140inline auto TMatrixMxNBase<Derived, T, M, N>::operator [] (const std::size_t rowIndex)
142{
143 PH_ASSERT_LT(rowIndex, M);
144
145 return m[rowIndex];
146}
147
148template<typename Derived, typename T, std::size_t M, std::size_t N>
149inline auto TMatrixMxNBase<Derived, T, M, N>::operator [] (const std::size_t rowIndex) const
150-> const TRawRowVector<T, N>&
151{
152 PH_ASSERT_LT(rowIndex, M);
153
154 return m[rowIndex];
155}
156
157template<typename Derived, typename T, std::size_t M, std::size_t N>
159{
160 std::string result = "\n";
161 for(std::size_t ri = 0; ri < M; ++ri)
162 {
163 result += "[";
164 for(std::size_t ci = 0; ci < N; ++ci)
165 {
166 result += std::to_string(m[ri][ci]);
167 result += (ci + 1 == N ? "" : ", ");
168 }
169 result += "]\n";
170 }
171 return result;
172}
173
174}// end namespace ph::math
void multiplyMatrix(const TRawMatrix< T, N, K > &rhsMatrix, TRawMatrix< T, M, K > *out_result) const
Definition TMatrixMxNBase.ipp:75
Derived mul(T constantValue) const
Definition TMatrixMxNBase.ipp:36
TRawMatrix< T, N, M > transposeMatrix() const
Definition TMatrixMxNBase.ipp:114
Derived & mulLocal(T constantValue)
Definition TMatrixMxNBase.ipp:43
constexpr std::size_t numRows() const noexcept
Definition TMatrixMxNBase.ipp:24
Derived & set(T constantValue)
Definition TMatrixMxNBase.ipp:129
std::string toString() const
Definition TMatrixMxNBase.ipp:158
constexpr std::size_t numCols() const noexcept
Definition TMatrixMxNBase.ipp:30
void multiplyTransposedMatrix(const TRawMatrix< T, K, N > &rhsMatrix, TRawMatrix< T, M, K > *out_result) const
Definition TMatrixMxNBase.ipp:95
TMatrixMxNBase(T elements)
Definition TMatrixMxNBase.ipp:13
TRawColVector< T, M > multiplyVector(const TRawColVector< T, M > &rhsColVector) const
Definition TMatrixMxNBase.ipp:57
TRawMatrix< T, M, N > Elements
Definition TMatrixMxNBase.h:39
TRawRowVector< T, N > & operator[](std::size_t rowIndex)
Definition TMatrixMxNBase.ipp:140
Math functions and utilities.
Definition TransformInfo.h:10
std::array< T, M > TRawColVector
Definition TMatrixMxNBase.h:20
std::array< std::array< T, N >, M > TRawMatrix
Definition TMatrixMxNBase.h:23
std::array< T, N > TRawRowVector
Definition TMatrixMxNBase.h:17
Definition TAABB2D.h:96