65 Tmat2(
const DT in00,
const DT in01,
66 const DT in10,
const DT in11);
86 void set(
const DT val);
158 this->v[0][0] = this->v[1][1] = diagValue;
159 this->v[1][0] = this->v[0][1] = 0;
176 this->v[0] = mat.
v[0];
177 this->v[1] = mat.
v[1];
197 const DT in10,
const DT in11)
199 this->v[0][0] = in00; this->v[0][1] = in01;
200 this->v[1][0] = in10; this->v[1][1] = in11;
207 this->v[0][0] =
static_cast<DT
>(mat[0]); this->v[0][1] =
static_cast<DT
>(mat[1]);
208 this->v[1][0] =
static_cast<DT
>(mat[2]); this->v[1][1] =
static_cast<DT
>(mat[3]);
215 this->v[0][0] =
static_cast<DT
>(mat[0]); this->v[0][1] =
static_cast<DT
>(mat[1]);
216 this->v[1][0] =
static_cast<DT
>(mat[2]); this->v[1][1] =
static_cast<DT
>(mat[3]);
225 mat[0] =
static_cast<float>(this->v[0][0]); mat[1] =
static_cast<float>(this->v[0][1]);
226 mat[2] =
static_cast<float>(this->v[1][0]); mat[3] =
static_cast<float>(this->v[1][1]);
235 mat[0] =
static_cast<double>(this->v[0][0]); mat[1] =
static_cast<double>(this->v[0][1]);
236 mat[2] =
static_cast<double>(this->v[1][0]); mat[3] =
static_cast<double>(this->v[1][1]);
243 return Tmat2(val, val,
251 this->v[0] = this->v[1] =
Tvec2<DT>(val);
265 this->v[0][0] = scale; this->v[0][1] = 0;
266 this->v[1][0] = 0; this->v[1][1] = scale;
281 return this->v[0][0]*this->v[1][1] - this->v[0][1]*this->v[1][0];
289 Tvec2<DT>(this->v[0][1], this->v[1][1]));
296 this->v[0].
apply(fct);
297 this->v[1].apply(fct);
316 DT determinant = det();
318 if (isInvertible ==
nullptr){
321 "Returning identity");
324 *isInvertible =
false;
326 retMat = getIdentity();
330 determinant = (
static_cast<DT
>(1))/determinant;
331 retMat[0][0] =
static_cast<DT
>(this->v[1][1]*determinant);
333 retMat[1][0] = this->v[1][0];
334 retMat[1][0] *=
static_cast<DT
>(-determinant);
336 retMat[0][1] = this->v[0][1];
337 retMat[0][1] *=
static_cast<DT
>(-determinant);
339 retMat[1][1] =
static_cast<DT
>(this->v[0][0]*determinant);
342 if (isInvertible !=
nullptr){ *isInvertible =
true; }
369 this->v[0] += m.
v[0];
370 this->v[1] += m.
v[1];
378 this->v[0] -= m.
v[0];
379 this->v[1] -= m.
v[1];
410 #define _ML_MAT2_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j]
427 return ((a[0] == b[0]) &&
448 return Tmat2<DT>(a) *=
static_cast<DT
>(-1.0);
494 return Tvec2<DT>(a[0][0]*v[0] + a[0][1]*v[1], a[1][0]*v[0] + a[1][1]*v[1]);
530 inline std::ostream&
operator<<(std::ostream& os,
const ML_LA_NAMESPACE::Tmat2<DT> &m)
532 return os << m[0] <<
'\n' << m[1];
537 inline std::istream&
operator>>(std::istream&
is, ML_LA_NAMESPACE::Tmat2<DT>& m)
539 ML_LA_NAMESPACE::Tmat2<DT> m_tmp;
540 is >> m_tmp[0] >> m_tmp[1];
541 if (
is){ m = m_tmp; }
Base class of all matrix classes that holds the data buffer and provides some general access methods.
VectorT v[size]
The rows constituting the matrix.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component-wise division of lhs by specialized rhs of type MLdouble.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
FloatingPointVector< T, size, DataContainer > operator+(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise addition of lhs and rhs.
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component-wise subtraction of rhs from lhs.
Declaration of matrix type traits.
Tmat2(const float mat[4])
Constructor from four floating point values in an array given by mat, row by row.
void getValues(double mat[4]) const
Copies the contents of *this into mat, row by row.
Tmat2< DT > transpose() const
Returns the transposed matrix.
Tmat2(const DT in00, const DT in01, const DT in10, const DT in11)
Initializes all matrix elements explicitly with scalars, row by row.
const Tmat2< DT > & operator+=(const Tmat2< DT > &m)
Increments by a Tmat2.
const Tmat2< DT > & operator/=(const DT d)
Divides by a constant d. Division by zero is not handled and must be avoided by caller.
DT det() const
Returns the determinant of this matrix.
const Tmat2< DT > & operator-=(const Tmat2< DT > &m)
Decrements by a Tmat2.
Tmat2< DT > inverse(bool *isInvertible=nullptr) const
Tmat2()
Constructs the matrix from four zero elements.
void setScaleMatrix(const DT scale)
Sets a diagonal matrix with scale on the diagonal.
Tmat2(const Tmat2< DT > &mat)
Copy constructor from the Tmat2 mat.
bool operator<(const Tmat2< DT > &) const
Dummy 'lesser than operator' that always returns false.
const Tmat2< DT > & operator*=(const DT d)
Multiplies by a constant d.
DT ComponentType
A typedef to 'export' the type of components.
const Tmat2< DT > & operator=(const Tmat2< DT > &m)
Assigns from a Tmat2.
void setValues(const double mat[4])
Copies the contents of mat into *this, row by row.
void set(const DT val)
Sets all values to val.
static Tmat2< DT > getIdentity()
Returns the identity matrix.
Tmat2(const Tvec2< DT > &row0, const Tvec2< DT > &row1)
Composes a matrix from the two vectors row0 and row1.
Tmat2(const double mat[4])
Constructor from four double values in an array given by mat, row by row.
Tmat2(const DT diagValue)
Constructs the matrix that has the argument diagValue as the diagonal values, zero otherwise.
const Tmat2< DT > & apply(MLDblFuncPtr fct)
Applies the method fct to all vectors of *this and returns the matrix.
static Tmat2< DT > getMat(const DT val)
Returns a matrix filled with values val.
void getValues(float mat[4]) const
Copies the contents of *this into mat, row by row.
void setValues(const float mat[4])
Copies the contents of mat into *this, row by row.
Declaration of float vector type traits.
bool MLValueIs0WOM(MLint8 a)
Returns true if value is 0; otherwise, it returns false.
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm,...
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.
#define _ML_MAT2_RC(i, j)
double(* MLDblFuncPtr)(double)
A function pointer type to a function that returns a double and takes a double as argument.
Tmat2< MLldouble > Matrix2ld
A 2x2 matrix of type long double.
void ML_UTILS_EXPORT printTemplateError(const char *location, MLErrorCode reason, const std::string_view &handling)
FloatingPointVector< T, size, DataContainer > & operator/=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component-wise division of *this by scalar value.
FloatingPointVector< T, size, DataContainer > & operator-=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise subtraction of buffer from *this.
Tmat2< MLfloat > Matrix2f
A 2x2 matrix of type float.
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Returns true if yes.
Tmat2< MLdouble > Matrix2
The standard 2x2 matrix of type double.
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Returns true if yes.
Tmat2< MLdouble > Matrix2d
A 2x2 matrix of type double.
constexpr Is< T > is(T d)
FloatingPointVector< T, size, DataContainer > & operator+=(FloatingPointVector< T, size, DataContainer > &op1, const FloatingPointVector< T, size, DataContainer > &buffer)
Arithmetic assignment: Component-wise addition.
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component-wise multiplication *this with specialized MLdouble scalar value.