| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 |
| 19 | #ifndef VMATRIX_H |
| 20 | #define VMATRIX_H |
| 21 | #include "vglobal.h" |
| 22 | #include "vpoint.h" |
| 23 | #include "vregion.h" |
| 24 |
| 25 | V_BEGIN_NAMESPACE |
| 26 |
| 27 | struct VMatrixData; |
| 28 | class VMatrix { |
| 29 | public: |
| 30 | enum class Axis { X, Y, Z }; |
| 31 | enum class MatrixType: unsigned char { |
| 32 | None = 0x00, |
| 33 | Translate = 0x01, |
| 34 | Scale = 0x02, |
| 35 | Rotate = 0x04, |
| 36 | Shear = 0x08, |
| 37 | Project = 0x10 |
| 38 | }; |
| 39 | VMatrix() = default; |
| 40 | bool isAffine() const; |
| 41 | bool isIdentity() const; |
| 42 | bool isInvertible() const; |
| 43 | bool isScaling() const; |
| 44 | bool isRotating() const; |
| 45 | bool isTranslating() const; |
| 46 | MatrixType type() const; |
| 47 | inline float determinant() const; |
| 48 |
| 49 | float m_11() const { return m11;} |
| 50 | float m_12() const { return m12;} |
| 51 | float m_13() const { return m13;} |
| 52 |
| 53 | float m_21() const { return m21;} |
| 54 | float m_22() const { return m22;} |
| 55 | float m_23() const { return m23;} |
| 56 |
| 57 | float m_tx() const { return mtx;} |
| 58 | float m_ty() const { return mty;} |
| 59 | float m_33() const { return m33;} |
| 60 |
| 61 | VMatrix &translate(VPointF pos) { return translate(pos.x(), pos.y()); }; |
| 62 | VMatrix &translate(float dx, float dy); |
| 63 | VMatrix &scale(VPointF s) { return scale(s.x(), s.y()); }; |
| 64 | VMatrix &scale(float sx, float sy); |
| 65 | VMatrix &shear(float sh, float sv); |
| 66 | VMatrix &rotate(float a, Axis axis = VMatrix::Axis::Z); |
| 67 | VMatrix &rotateRadians(float a, Axis axis = VMatrix::Axis::Z); |
| 68 |
| 69 | VPointF map(const VPointF &p) const; |
| 70 | inline VPointF map(float x, float y) const; |
| 71 | VRect map(const VRect &r) const; |
| 72 | VRegion map(const VRegion &r) const; |
| 73 |
| 74 | V_REQUIRED_RESULT VMatrix inverted(bool *invertible = nullptr) const; |
| 75 | V_REQUIRED_RESULT VMatrix adjoint() const; |
| 76 |
| 77 | VMatrix operator*(const VMatrix &o) const; |
| 78 | VMatrix & operator*=(const VMatrix &); |
| 79 | VMatrix & operator*=(float mul); |
| 80 | VMatrix & operator/=(float div); |
| 81 | bool operator==(const VMatrix &) const; |
| 82 | bool operator!=(const VMatrix &) const; |
| 83 | bool fuzzyCompare(const VMatrix &) const; |
| 84 | friend std::ostream &operator<<(std::ostream &os, const VMatrix &o); |
| 85 |
| 86 | private: |
| 87 | friend struct VSpanData; |
| 88 | float m11{1}, m12{0}, m13{0}; |
| 89 | float m21{0}, m22{1}, m23{0}; |
| 90 | float mtx{0}, mty{0}, m33{1}; |
| 91 | mutable MatrixType mType{MatrixType::None}; |
| 92 | mutable MatrixType dirty{MatrixType::None}; |
| 93 | }; |
| 94 |
| 95 | inline VPointF VMatrix::map(float x, float y) const |
| 96 | { |
| 97 | return map(VPointF(x, y)); |
| 98 | } |
| 99 |
| 100 | V_END_NAMESPACE |
| 101 |
| 102 | #endif // VMATRIX_H |
| 103 |