Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TMatrix22.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3
4namespace sf
5{
6
7// Forward declaration.
8template<typename T>
9class TVector2D;
10
14template<typename T>
16{
17 public:
21 typedef T value_type;
22
27
32
36 TMatrix22(TMatrix22&&) noexcept;
37
41 TMatrix22(std::initializer_list<T> list);
42
46 TMatrix22(T m00, T m01, T m10, T m11);
47
51 TMatrix22(T scale_x, T scale_y);
52
57 explicit TMatrix22(T angle);
58
65
70 TMatrix22& assign(const T[2][2]);
71
77
82 TMatrix22& operator=(const TMatrix22& m);
83
87 TMatrix22& operator=(TMatrix22&& m) noexcept;
88
93 TMatrix22& operator*=(const TMatrix22& m);
94
99 TVector2D<T> transformed(const TVector2D<T>&) const;
100
105 TVector2D<T> operator*(const TVector2D<T>&) const;
106
110 constexpr operator T*();
111
115 constexpr operator const T*() const;
116
123 bool isEqual(const TMatrix22& m, T tol = tolerance) const;
124
129 bool operator==(const TMatrix22&) const;
130
135 bool operator!=(const TMatrix22&) const;
136
143
148 void setRotation(T angle);
149
153 T getRotation() const;
154
158 std::string toString() const;
159
165 TMatrix22& fromString(const std::string& s) noexcept(false);
166
170 void copyTo(T[2][2]) const;
171
177 static constexpr auto tolerance = TVector2D<T>::tolerance;
178
179 protected:
184 {
185 T array[2 * 2];
186 T mtx[2][2];
187 } _data = {0, 0, 0, 0};
188};
189
197template<typename T>
198std::ostream& operator<<(std::ostream& os, const TMatrix22<T>& mtx)
199{
200 return os << mtx.toString();
201}
202
210template<typename T>
211std::istream& operator>>(std::istream& is, TMatrix22<T>& mtx) noexcept(false)
212{
213 std::string s;
214 constexpr auto delimiter = ')';
215 std::getline(is, s, delimiter);
216 mtx.fromString(s.append(1, delimiter));
217 return is;
218}
219
220}// namespace sf
221
222// Include all inlined functions and template implementations.
223#include <math/TMatrix22.hpp>
Generic 2 x 2 matrix template.
Definition TMatrix22.h:16
static constexpr auto tolerance
Tolerance for when comparing in the equal operator.
Definition TMatrix22.h:177
void copyTo(T[2][2]) const
Copy to matrix to 2 by 2 value_type array.
TMatrix22 transposed() const
Gets the transposed version of the matrix. A transposed rotation matrix inverts the rotation.
TMatrix22 & fromString(const std::string &s) noexcept(false)
Gets matrix values from the string representation formed like '({1.2,4.5},{5.6,7.8})'....
TMatrix22 & resetOrientation()
Reset the matrix to the so-called 'identity' matrix where a vector is not changed during transformati...
bool isEqual(const TMatrix22 &m, T tol=tolerance) const
Compares the passed matrix within the set tolerance.
TMatrix22(const TMatrix22 &m)
Copy constructor.
T getRotation() const
Gets the rotation of the matrix when it is a square matrix.
TMatrix22()
Default constructor.
TVector2D< T > transformed(const TVector2D< T > &) const
Vector transformation method.
T value_type
Type accessible when implemented.
Definition TMatrix22.h:21
std::string toString() const
Gets the string representation of the matrix formed like '((m00,m01),(m10,m11))'.
TMatrix22(TMatrix22 &&) noexcept
Move constructor.
TMatrix22 & assign(const T[2][2])
Assignment using a 2 by 2 array.
void setRotation(T angle)
Sets the rotation for the matrix.
union sf::TMatrix22::data_type _data
2-dimensional vector for math operations.
Definition TVector2D.h:23
Definition Application.h:10
_GII_FUNC std::istream & operator>>(std::istream &is, ResultData &)
Stream operator for setting up this instance with a setup std::string.
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
Storage union of the 2x2 matrix.
Definition TMatrix22.h:184