9 #ifndef CUBBYFLOW_MATRIX2X2_IMPL_H 10 #define CUBBYFLOW_MATRIX2X2_IMPL_H 80 size_t height = list.size();
81 size_t width = (height > 0) ? list.begin()->size() : 0;
86 auto rowIter = list.begin();
87 for (
size_t i = 0; i < height; ++i)
89 assert(width == rowIter->size());
91 auto colIter = rowIter->begin();
92 for (
size_t j = 0; j < width; ++j)
94 (*this)(i, j) = static_cast<T>(*colIter);
102 template <
typename T>
105 for (
size_t i = 0; i < 4; ++i)
107 m_elements[i] = m.m_elements[i];
111 template <
typename T>
114 for (
size_t i = 0; i < 4; ++i)
116 m_elements[i] = arr[i];
120 template <
typename T>
127 template <
typename T>
134 template <
typename T>
137 m_elements[i * 2] = row.
x;
138 m_elements[i * 2 + 1] = row.
y;
141 template <
typename T>
144 m_elements[i] = col.
x;
145 m_elements[i + 2] = col.
y;
148 template <
typename T>
152 (std::fabs(m_elements[0] - m.m_elements[0]) < tol) &&
153 (std::fabs(m_elements[1] - m.m_elements[1]) < tol) &&
154 (std::fabs(m_elements[2] - m.m_elements[2]) < tol) &&
155 (std::fabs(m_elements[3] - m.m_elements[3]) < tol);
158 template <
typename T>
164 template <
typename T>
170 template <
typename T>
176 template <
typename T>
179 return m_elements.data();
182 template <
typename T>
185 return m_elements.data();
188 template <
typename T>
192 m_elements[0] + s, m_elements[1] + s,
193 m_elements[2] + s, m_elements[3] + s);
196 template <
typename T>
200 m_elements[0] + m.m_elements[0], m_elements[1] + m.m_elements[1],
201 m_elements[2] + m.m_elements[2], m_elements[3] + m.m_elements[3]);
204 template <
typename T>
208 m_elements[0] - s, m_elements[1] - s,
209 m_elements[2] - s, m_elements[3] - s);
212 template <
typename T>
216 m_elements[0] - m.m_elements[0], m_elements[1] - m.m_elements[1],
217 m_elements[2] - m.m_elements[2], m_elements[3] - m.m_elements[3]);
220 template <
typename T>
224 m_elements[0] * s, m_elements[1] * s,
225 m_elements[2] * s, m_elements[3] * s);
228 template <
typename T>
232 m_elements[0] * v.
x + m_elements[1] * v.
y,
233 m_elements[2] * v.
x + m_elements[3] * v.
y);
236 template <
typename T>
240 m_elements[0] * m.m_elements[0] + m_elements[1] * m.m_elements[2],
241 m_elements[0] * m.m_elements[1] + m_elements[1] * m.m_elements[3],
242 m_elements[2] * m.m_elements[0] + m_elements[3] * m.m_elements[2],
243 m_elements[2] * m.m_elements[1] + m_elements[3] * m.m_elements[3]);
246 template <
typename T>
250 m_elements[0] / s, m_elements[1] / s,
251 m_elements[2] / s, m_elements[3] / s);
254 template <
typename T>
258 s + m_elements[0], s + m_elements[1],
259 s + m_elements[2], s + m_elements[3]);
262 template <
typename T>
266 m.m_elements[0] + m_elements[0], m.m_elements[1] + m_elements[1],
267 m.m_elements[2] + m_elements[2], m.m_elements[3] + m_elements[3]);
270 template <
typename T>
274 s - m_elements[0], s - m_elements[1],
275 s - m_elements[2], s - m_elements[3]);
278 template <
typename T>
282 m.m_elements[0] - m_elements[0], m.m_elements[1] - m_elements[1],
283 m.m_elements[2] - m_elements[2], m.m_elements[3] - m_elements[3]);
286 template <
typename T>
290 s * m_elements[0], s * m_elements[1],
291 s * m_elements[2], s * m_elements[3]);
294 template <
typename T>
300 template <
typename T>
304 s / m_elements[0], s / m_elements[1],
305 s / m_elements[2], s / m_elements[3]);
308 template <
typename T>
317 template <
typename T>
320 m_elements[0] += m.m_elements[0];
321 m_elements[1] += m.m_elements[1];
322 m_elements[2] += m.m_elements[2];
323 m_elements[3] += m.m_elements[3];
326 template <
typename T>
335 template <
typename T>
338 m_elements[0] -= m.m_elements[0];
339 m_elements[1] -= m.m_elements[1];
340 m_elements[2] -= m.m_elements[2];
341 m_elements[3] -= m.m_elements[3];
344 template <
typename T>
353 template <
typename T>
359 template <
typename T>
368 template <
typename T>
371 std::swap(m_elements[1], m_elements[2]);
374 template <
typename T>
380 m.m_elements[0] = m_elements[3];
381 m.m_elements[1] = -m_elements[1];
382 m.m_elements[2] = -m_elements[2];
383 m.m_elements[3] = m_elements[0];
389 template <
typename T>
394 for (
size_t i = 0; i < 4; ++i)
396 sum += m_elements[i];
402 template <
typename T>
408 template <
typename T>
411 return m_elements[std::distance(std::begin(m_elements), std::min_element(std::begin(m_elements), std::end(m_elements)))];
414 template <
typename T>
417 return m_elements[std::distance(std::begin(m_elements), std::max_element(std::begin(m_elements), std::end(m_elements)))];
420 template <
typename T>
426 template <
typename T>
432 template <
typename T>
435 return m_elements[0] + m_elements[3];
438 template <
typename T>
442 m_elements[0] * m_elements[3] -
443 m_elements[1] * m_elements[2];
446 template <
typename T>
454 template <
typename T>
462 template <
typename T>
470 template <
typename T>
478 template <
typename T>
483 m_elements[2], m_elements[3]);
486 template <
typename T>
490 m_elements[0], m_elements[1],
494 template <
typename T>
498 m_elements[0], m_elements[2],
499 m_elements[1], m_elements[3]);
502 template <
typename T>
510 template <
typename T>
511 template <
typename U>
515 static_cast<U
>(m_elements[0]),
516 static_cast<U>(m_elements[1]),
517 static_cast<U
>(m_elements[2]),
518 static_cast<U>(m_elements[3]));
521 template <
typename T>
528 template <
typename T>
535 template <
typename T>
542 template <
typename T>
549 template <
typename T>
556 template <
typename T>
563 template <
typename T>
570 template <
typename T>
577 template <
typename T>
580 return m_elements[i];
583 template <
typename T>
586 return m_elements[i];
589 template <
typename T>
592 return m_elements[i * 2 + j];
595 template <
typename T>
598 return m_elements[i * 2 + j];
601 template <
typename T>
605 m_elements[0] == m.m_elements[0] &&
606 m_elements[1] == m.m_elements[1] &&
607 m_elements[2] == m.m_elements[2] &&
608 m_elements[3] == m.m_elements[3];
611 template <
typename T>
615 m_elements[0] != m.m_elements[0] ||
616 m_elements[1] != m.m_elements[1] ||
617 m_elements[2] != m.m_elements[2] ||
618 m_elements[3] != m.m_elements[3];
621 template <
typename T>
627 template <
typename T>
633 template <
typename T>
639 template <
typename T>
642 return MakeScaleMatrix(s.
x, s.
y);
645 template <
typename T>
649 std::cos(rad), -std::sin(rad),
650 std::sin(rad), std::cos(rad));
653 template <
typename T>
659 template <
typename T>
665 template <
typename T>
671 template <
typename T>
677 template <
typename T>
683 template <
typename T>
689 template <
typename T>
695 template <
typename T>
701 template <
typename T>
707 template <
typename T>
713 template <
typename T>
719 template <
typename T>
725 template <
typename T>
Matrix RAdd(T s) const
Returns input scalar + this matrix.
Definition: Matrix2x2-Impl.h:255
bool IsSimilar(const MatrixExpression< T, E > &other, double tol=std::numeric_limits< double >::epsilon()) const
Definition: Matrix-Impl.h:169
T x
X (or the first) component of the vector.
Definition: Vector2.h:29
static MatrixConstant< T > MakeZero()
Makes a M x N matrix with zeros.
Definition: Matrix-Impl.h:823
MatrixDiagonal< T, Matrix > Diagonal() const
Returns diagonal part of this matrix.
Definition: Matrix-Impl.h:633
MatrixDiagonal< T, Matrix > OffDiagonal() const
Returns off-diagonal part of this matrix.
Definition: Matrix-Impl.h:639
T Sum() const
Returns sum of all elements.
Definition: Matrix-Impl.h:483
Matrix & operator*=(const T &s)
Multiplication assignment with input scalar.
Definition: Matrix-Impl.h:737
Matrix & operator/=(const T &s)
Division assignment with input scalar.
Definition: Matrix-Impl.h:752
T * data()
Returns data pointer of this matrix.
Definition: Matrix-Impl.h:217
void SetDiagonal(const T &s)
Sets diagonal elements with input scalar.
Definition: Matrix-Impl.h:92
Matrix< T, 2, 2 > operator+(const Matrix< T, 2, 2 > &a, const Matrix< T, 2, 2 > &b)
Returns a + b (element-size).
Definition: Matrix2x2-Impl.h:660
void IMul(const T &s)
Multiplies input scalar to this matrix.
Definition: Matrix-Impl.h:376
MatrixScalarRSub< T, Matrix > RSub(const T &s) const
Returns input scalar - this matrix.
Definition: Matrix-Impl.h:318
T AbsMaxN(const T *x, size_t n)
Returns absolute maximum among n-elements.
Definition: MathUtils-Impl.h:64
void IAdd(const T &s)
Adds input scalar to this matrix.
Definition: Matrix-Impl.h:350
void Set(const T &s)
Sets whole matrix with input scalar.
Definition: Matrix-Impl.h:52
MatrixScalarAdd< T, Matrix > Add(const T &s) const
Returns this matrix + input scalar.
Definition: Matrix-Impl.h:253
Matrix Sub(T s) const
Returns this matrix - input scalar.
Definition: Matrix2x2-Impl.h:205
void SetRow(size_t i, const VectorExpression< T, E > &row)
Sets i-th row with input vector.
Definition: Matrix-Impl.h:116
void IDiv(const T &s)
Divides this matrix with input scalar.
Definition: Matrix-Impl.h:390
bool operator!=(const MatrixExpression< T, E > &m) const
Returns true if is not equal to m.
Definition: Matrix-Impl.h:791
Matrix RDiv(T s) const
Returns input scalar / this matrix.
Definition: Matrix2x2-Impl.h:301
void ISub(const T &s)
Subtracts input scalar from this matrix.
Definition: Matrix-Impl.h:363
constexpr size_t Cols() const
Returns number of columns of this matrix.
Definition: Matrix-Impl.h:211
T Max() const
Returns maximum among all elements.
Definition: Matrix-Impl.h:515
Matrix & operator+=(const T &s)
Addition assignment with input scalar.
Definition: Matrix-Impl.h:707
MatrixScalarDiv< T, Matrix > Div(const T &s) const
Returns this matrix / input scalar.
Definition: Matrix-Impl.h:299
MatrixScalarSub< T, Matrix > Sub(const T &s) const
Returns this matrix - input scalar.
Definition: Matrix-Impl.h:266
Matrix Inverse() const
Returns inverse matrix.
Definition: Matrix-Impl.h:677
Matrix Add(T s) const
Returns this matrix + input scalar.
Definition: Matrix2x2-Impl.h:189
MatrixScalarMul< T, Matrix > RMul(const T &s) const
Returns input scalar * this matrix.
Definition: Matrix-Impl.h:331
MatrixScalarAdd< T, Matrix > RAdd(const T &s) const
Returns input scalar + this matrix.
Definition: Matrix-Impl.h:305
T AbsMinN(const T *x, size_t n)
Returns absolute minimum among n-elements.
Definition: MathUtils-Impl.h:51
Static-sized M x N matrix class.
Definition: Matrix.h:30
MatrixScalarMul< T, Matrix > Mul(const T &s) const
Returns this matrix * input scalar.
Definition: Matrix-Impl.h:279
void Invert()
Inverts this matrix.
Definition: Matrix-Impl.h:402
Matrix< T, 2, 2 > operator/(const Matrix< T, 2, 2 > &a, T b)
Definition: Matrix2x2-Impl.h:720
Definition: pybind11Utils.h:24
T & operator[](size_t i)
Returns reference of i-th element.
Definition: Matrix-Impl.h:759
bool operator==(const MatrixExpression< T, E > &m) const
Returns true if is equal to m.
Definition: Matrix-Impl.h:784
Matrix Mul(T s) const
Returns this matrix * input scalar.
Definition: Matrix2x2-Impl.h:221
Matrix RSub(T s) const
Returns input scalar - this matrix.
Definition: Matrix2x2-Impl.h:271
constexpr bool IsSquare() const
Returns true if this matrix is a square matrix.
Definition: Matrix-Impl.h:193
Matrix< T, 2, 2 > operator-(const Matrix< T, 2, 2 > &a)
Returns a matrix with opposite sign.
Definition: Matrix2x2-Impl.h:654
T y
Y (or the second) component of the vector.
Definition: Vector2.h:35
Matrix & operator-=(const T &s)
Subtraction assignment with input scalar.
Definition: Matrix-Impl.h:722
Matrix & operator=(const E &m)
Assigns input matrix.
const Matrix< T, M, N > & operator()() const
Returns actual implementation (the subclass).
Definition: MatrixExpression-Impl.h:34
T Trace() const
Definition: Matrix-Impl.h:554
T Avg() const
Returns average of all elements.
Definition: Matrix-Impl.h:496
Matrix RMul(T s) const
Returns input scalar * this matrix.
Definition: Matrix2x2-Impl.h:287
T Determinant() const
Returns determinant of this matrix.
Definition: Matrix-Impl.h:569
2-D vector class.
Definition: Vector2.h:26
void Transpose()
Transposes this matrix.
Definition: Matrix-Impl.h:396
static MatrixIdentity< T > MakeIdentity()
Makes a M x N matrix with all diagonal elements to 1, and other elements to 0.
Definition: Matrix-Impl.h:829
T Min() const
Returns minimum among all elements.
Definition: Matrix-Impl.h:502
T AbsMin() const
Returns absolute minimum among all elements.
Definition: Matrix-Impl.h:528
Vector< T, 3 > operator*(const Quaternion< T > &q, const Vector< T, 3 > &v)
Returns quaternion q * vector v.
Definition: Quaternion-Impl.h:481
void SetOffDiagonal(const T &s)
Sets off-diagonal elements with input scalar.
Definition: Matrix-Impl.h:103
MatrixTypeCast< U, Matrix, T > CastTo() const
MatrixScalarRDiv< T, Matrix > RDiv(const T &s) const
Returns input matrix / this scalar.
Definition: Matrix-Impl.h:344
constexpr size_t Rows() const
Returns number of rows of this matrix.
Definition: Matrix-Impl.h:205
Matrix< T, N, M > Transposed() const
Returns transposed matrix.
Definition: Matrix-Impl.h:669
T AbsMax() const
Returns absolute maximum among all elements.
Definition: Matrix-Impl.h:541
Matrix Div(T s) const
Returns this matrix / input scalar.
Definition: Matrix2x2-Impl.h:247
Matrix()
Definition: Matrix-Impl.h:15
2-D matrix class.
Definition: Matrix2x2.h:28
void SetColumn(size_t j, const VectorExpression< T, E > &col)
Sets j-th column with input vector.
Definition: Matrix-Impl.h:130