PoDoFo 1.2.0
Loading...
Searching...
No Matches
Matrix.h
1// SPDX-FileCopyrightText: 2021 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef AUX_MATRIX_H
5#define AUX_MATRIX_H
6
7#include "MathBase.h"
8#include "Vector2.h"
9
10namespace PoDoFo
11{
12 class PdfArray;
13
14 class PODOFO_API Matrix final
15 {
16 public:
17 static Matrix Identity;
18
19 public:
21 Matrix();
22 Matrix(double a, double b, double c, double d, double e, double f);
23
24 public:
25 static Matrix FromArray(const double arr[6]);
26 static Matrix FromArray(const PdfArray& arr);
27 static Matrix CreateTranslation(const Vector2& tx);
28 static Matrix CreateScale(const Vector2& scale);
29 static Matrix CreateRotation(double teta);
30 static Matrix CreateRotation(const Vector2& center, double teta);
31
32 public:
33 // Prepend the given translation to the current matrix
34 Matrix& Translate(const Vector2& tx);
35
36 // Return the matrix with the given translation prepended
37 Matrix Translated(const Vector2& tx) const;
38
39 // TODO: Rotate/Scale
40
41 public:
42 template <AlgebraicTrait trait>
43 double Get() const
44 {
45 return MatrixTraits<trait>::Get(m_mat);
46 }
47
48 template <AlgebraicTrait trait>
49 void Set(double value)
50 {
51 MatrixTraits<trait>::Set(m_mat, value);
52 }
53
54 // Apply (prepend) the given operation
55 template <AlgebraicTrait trait>
56 Matrix& Apply(double value)
57 {
58 MatrixTraits<trait>::Apply(m_mat, value);
59 return *this;
60 }
61
62 public:
63 Matrix operator*(const Matrix& m) const;
64
65 public:
66 Matrix GetScalingRotation() const;
67 Matrix GetRotation() const;
68 Vector2 GetScaleVector() const;
69 Vector2 GetTranslationVector() const;
70 void ToArray(double arr[6]) const;
71 void ToArray(PdfArray& arr) const;
72 PdfArray ToArray() const;
73
74 public:
75 Matrix(const Matrix&) = default;
76 Matrix& operator=(const Matrix&) = default;
77 bool operator==(const Matrix& m) const;
78 bool operator!=(const Matrix& m) const;
79
80 public:
81 const double& operator[](unsigned idx) const;
82
83 private:
84 Matrix(const double arr[6]);
85
86 private:
87 double m_mat[6];
88 };
89}
90
91#endif // AUX_MATRIX_H
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13