Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TMatrix2.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/math_fwd.h"
4
5#include <cstddef>
6#include <array>
7#include <string>
8
9namespace ph::math
10{
11
14template<typename T>
15class TMatrix2 final
16{
17public:
18 static TMatrix2 makeIdentity();
19
20public:
21 using Elements = std::array<std::array<T, 2>, 2>;
22
24
25 inline TMatrix2() = default;
26 explicit TMatrix2(T value);
27 TMatrix2(T m00, T m01, T m10, T m11);
28 TMatrix2(const TVector2<T>& m00m01, const TVector2<T>& m10m11);
29 inline TMatrix2(const TMatrix2& other) = default;
30
31 template<typename U>
32 explicit TMatrix2(const TMatrix2<U>& other);
33
35 TMatrix2 mul(const TMatrix2& rhs) const;
36 TMatrix2 mul(T value) const;
37 void mul(const TMatrix2& rhs, TMatrix2* out_result) const;
38 TMatrix2& mulLocal(T value);
39 TMatrix2 inverse() const;
40 T determinant() const;
41
42 // TODO: make solve() methods accepts all "subscriptable" types to (potentially)
43 // improve performance & less code duplications
44
55 bool solve(
56 const std::array<T, 2>& b,
57 std::array<T, 2>* out_x) const;
58
63 bool solve(
64 const TVector2<T>& b,
65 TVector2<T>* out_x) const;
66
81 template<std::size_t N>
82 bool solve(
83 const std::array<std::array<T, 2>, N>& bs,
84 std::array<std::array<T, 2>, N>* out_xs) const;
85
86 std::string toString() const;
87};
88
89}// end namespace ph::math
90
91#include "Math/TMatrix2.ipp"
Represents a 2x2 matrix.
Definition TMatrix2.h:16
TMatrix2 mul(const TMatrix2 &rhs) const
Definition TMatrix2.ipp:56
TMatrix2(const TMatrix2 &other)=default
std::string toString() const
Definition TMatrix2.ipp:178
static TMatrix2 makeIdentity()
Definition TMatrix2.ipp:17
Elements m
Definition TMatrix2.h:23
TMatrix2 & mulLocal(T value)
Definition TMatrix2.ipp:79
T determinant() const
Definition TMatrix2.ipp:97
std::array< std::array< T, 2 >, 2 > Elements
Definition TMatrix2.h:21
TMatrix2 & initIdentity()
Definition TMatrix2.ipp:47
TMatrix2 inverse() const
Definition TMatrix2.ipp:90
bool solve(const std::array< T, 2 > &b, std::array< T, 2 > *out_x) const
Solves linear systems of the form Ax = b.
Definition TMatrix2.ipp:103
Represents a 2-D vector.
Definition TVector2.h:19
Math functions and utilities.
Definition TransformInfo.h:10