Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TMatrixMxNBase.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/math_fwd.h"
4#include "Utility/utility.h"
5
6#include <Common/primitive_type.h>
7
8#include <string>
9#include <array>
10#include <cstddef>
11#include <type_traits>
12
13namespace ph::math
14{
15
16template<typename T, std::size_t N>
17using TRawRowVector = std::array<T, N>;
18
19template<typename T, std::size_t M>
20using TRawColVector = std::array<T, M>;
21
22template<typename T, std::size_t M, std::size_t N>
23using TRawMatrix = std::array<std::array<T, N>, M>;
24
32template<typename Derived, typename T, std::size_t M, std::size_t N>
34{
35private:
36 using Self = TMatrixMxNBase;
37
38public:
40
41 explicit TMatrixMxNBase(T elements);
42 explicit TMatrixMxNBase(Elements elements);
43
44// Hide special members as this class is not intended to be used polymorphically.
45// It is derived class's choice to expose them (by defining them in public) or not.
46protected:
48
49protected:
50 inline static constexpr auto NUM_ROWS = M;
51 inline static constexpr auto NUM_COLS = N;
52
53 constexpr std::size_t numRows() const noexcept;
54 constexpr std::size_t numCols() const noexcept;
55
56 Derived mul(T constantValue) const;
57 Derived& mulLocal(T constantValue);
58
59 Derived& set(T constantValue);
60
61 TRawColVector<T, M> multiplyVector(const TRawColVector<T, M>& rhsColVector) const;
62
63 template<std::size_t K>
64 void multiplyMatrix(const TRawMatrix<T, N, K>& rhsMatrix, TRawMatrix<T, M, K>* out_result) const;
65
66 template<std::size_t K>
67 void multiplyTransposedMatrix(const TRawMatrix<T, K, N>& rhsMatrix, TRawMatrix<T, M, K>* out_result) const;
68
69 TRawMatrix<T, N, M> transposeMatrix() const;
70
71 TRawRowVector<T, N>& operator [] (std::size_t rowIndex);
72 const TRawRowVector<T, N>& operator [] (std::size_t rowIndex) const;
73
74 std::string toString() const;
75
76protected:
77 TRawMatrix<T, M, N> m;
78};
79
80}// end namespace ph::math
81
82#include "Math/General/TMatrixMxNBase.ipp"
if constexpr(IS_ROBUST)
Definition TBvhSimdComputingContext.h:561
A base for general M by N row-major matrices.
Definition TMatrixMxNBase.h:34
void multiplyMatrix(const TRawMatrix< T, N, K > &rhsMatrix, TRawMatrix< T, M, K > *out_result) const
Definition TMatrixMxNBase.ipp:75
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TMatrixMxNBase)
Derived mul(T constantValue) const
Definition TMatrixMxNBase.ipp:36
TRawMatrix< T, M, N > m
Definition TMatrixMxNBase.h:77
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
static constexpr auto NUM_ROWS
Definition TMatrixMxNBase.h:50
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
static constexpr auto NUM_COLS
Definition TMatrixMxNBase.h:51
TRawColVector< T, M > multiplyVector(const TRawColVector< T, M > &rhsColVector) const
Definition TMatrixMxNBase.ipp:57
TRawMatrix< T, M, N > Elements
Definition TMatrixMxNBase.h:39
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