This template represents 2x2 matrix. It uses row major order of data.
You can find more information in comments below.
template<class TYPE>
union TMat2
{
struct
{
TYPE _11, _12; // First row
TYPE _21, _22; // Second row
};
TVec2<TYPE> Rows[2]; // Rows as vectors
TYPE Data[4]; // Elements as array
TMatrix<TYPE, 2, 2> M; // As TMatrix
TMat2() = default;
TMat2(const TMat2 &other) = default;
TMat2(TMat2 &&other) = default;
// Create with specified elements
TMat2(
const TYPE m11, const TYPE m12,
const TYPE m21, const TYPE m22);
// Create with specified rows
TMat2(const TVec2<TYPE> &row1, const TVec2<TYPE> &row2);
// Create diagonal matrix
TMat2(const TYPE diagonal, const TYPE other);
// Create from TMatrix
TMat2(const TMatrix<TYPE, 2, 2> &m);
TMat2 &operator=(const TMat2 &other) = default;
TMat2 &operator=(TMat2 &&other) = default;
TVec2<TYPE> operator[](const size_t row) const; // Return specified row. Used when matrix is a constant
TVec2<TYPE> &operator[](const size_t row); // Return specified row
};
Additionally following operators exists.
template<class TYPE>
bool operator==(const TMat2<TYPE> &a, const TMat2<TYPE> &b); // Check whether matrices are equal. Can be used for non-float data types only
template<class TYPE>
bool operator!=(const TMat2<TYPE> &a, const TMat2<TYPE> &b); // Check whether matrices aren't equal. Can be used for non-float data types only
template<class TYPE>
TMat2<TYPE> operator+(const TMat2<TYPE> &m, const TYPE val); // Add matrix and scalar
template<class TYPE>
TMat2<TYPE> operator-(const TMat2<TYPE> &m, const TYPE val); // Subtruct matrix and scalar
template<class TYPE>
TMat2<TYPE> operator*(const TMat2<TYPE> &m, const TYPE val); // Multiply matrix and scalar
template<class TYPE>
TMat2<TYPE> operator/(const TMat2<TYPE> &m, const TYPE val); // Divide matrix and scalar
template<class TYPE>
TMat2<TYPE> operator+(const TYPE val, const TMat2<TYPE> &m); // Add scalar and matrix
template<class TYPE>
TMat2<TYPE> operator-(const TYPE val, const TMat2<TYPE> &m); // Subtruct scalar and matrix
template<class TYPE>
TMat2<TYPE> operator*(const TYPE val, const TMat2<TYPE> &m); // Multiply scalar and matrix
template<class TYPE>
TMat2<TYPE> operator/(const TYPE val, const TMat2<TYPE> &m); // Divide scalar and matrix
template<class TYPE>
TMat2<TYPE> &operator+=(TMat2<TYPE> &m, const TYPE val); // Add scalar to matrix
template<class TYPE>
TMat2<TYPE> &operator-=(TMat2<TYPE> &m, const TYPE val); // Subtract scalar from matrix
template<class TYPE>
TMat2<TYPE> &operator*=(TMat2<TYPE> &m, const TYPE val); // Multiply matrix by scalar
template<class TYPE>
TMat2<TYPE> &operator/=(TMat2<TYPE> &m, const TYPE val); // Divide matrix by scalar
template<class TYPE>
TVec2<TYPE> operator*(const TVec2<TYPE> &v, const TMat2<TYPE> &m); // Multiply vector and matrix
template<class TYPE>
TVec2<TYPE> operator*(const TMat2<TYPE> &m, const TVec2<TYPE> &v); // Multiply matrix and vector
template<class TYPE>
TVec2<TYPE> &operator*=(TVec2<TYPE> &v, const TMat2<TYPE> &m); // Multiply vector by matrix
template<class TYPE>
TMat2<TYPE> operator*(const TMat2<TYPE> &a, const TMat2<TYPE> &b); // Multiply matrices
template<class TYPE>
TMat2<TYPE> &operator*=(TMat2<TYPE> &a, const TMat2<TYPE> &b); // Multiply matrix by matrix
Also there are some functions which can be used with TMat2 template. Here they are.
Namespace: | ntl |
Include: | NTL/Core/Mat2.h |