7#include <Common/assertion.h>
35 m{m00m01.x(), m00m01.y(),
36 m10m11.x(), m10m11.y()}
42 m{static_cast<T>(other.m[0][0]), static_cast<T>(other.m[0][1]),
43 static_cast<T>(other.m[1][0]), static_cast<T>(other.m[1][1])}
49 m[0][0] =
static_cast<T
>(1); m[0][1] =
static_cast<T
>(0);
50 m[1][0] =
static_cast<T
>(0); m[1][1] =
static_cast<T
>(1);
59 this->mul(rhs, &result);
72 out_result->
m[0][0] = m[0][0] * rhs.
m[0][0] + m[0][1] * rhs.
m[1][0];
73 out_result->
m[0][1] = m[0][0] * rhs.
m[0][1] + m[0][1] * rhs.
m[1][1];
74 out_result->
m[1][0] = m[1][0] * rhs.
m[0][0] + m[1][1] * rhs.
m[1][0];
75 out_result->
m[1][1] = m[1][0] * rhs.
m[0][1] + m[1][1] * rhs.
m[1][1];
93 -m[1][0], m[0][0]).
mulLocal(
static_cast<T
>(1) / determinant());
99 return m[0][0] * m[1][1] - m[1][0] * m[0][1];
104 const std::array<T, 2>& b,
105 std::array<T, 2>*
const out_x)
const
109 std::array<std::array<T, 2>, 1> x;
110 if(solve<1>({b}, &x))
112 (*out_x)[0] = x[0][0];
113 (*out_x)[1] = x[0][1];
131 if(solve({b.
x(), b.
y()}, &x))
145template<std::
size_t N>
147 const std::array<std::array<T, 2>, N>& bs,
148 std::array<std::array<T, 2>, N>*
const out_xs)
const
150 static_assert(!std::numeric_limits<T>::is_integer);
152 const T det = determinant();
158 const T rcpDet =
static_cast<T
>(1) / determinant();
161 for(std::size_t i = 0; i < N; ++i)
163 (*out_xs)[i][0] = (m[1][1] * bs[i][0] - m[0][1] * bs[i][1]) * rcpDet;
164 (*out_xs)[i][1] = (m[0][0] * bs[i][1] - m[1][0] * bs[i][0]) * rcpDet;
167 for(std::size_t i = 0; i < N; ++i)
169 if(!std::isfinite((*out_xs)[i][0]) || !std::isfinite((*out_xs)[i][1]))
180 return "[" + std::to_string(m[0][0]) +
", " + std::to_string(m[0][1]) +
"]" +
181 "[" + std::to_string(m[1][0]) +
", " + std::to_string(m[1][1]) +
"]";
Represents a 2x2 matrix.
Definition TMatrix2.h:16
TMatrix2 mul(const TMatrix2 &rhs) const
Definition TMatrix2.ipp:56
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
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
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
Math functions and utilities.
Definition TransformInfo.h:10