updated licenses info.
[platform/core/uifw/lottie-player.git] / src / vector / vmatrix.h
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
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
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     VMatrix &translate(VPointF pos) { return translate(pos.x(), pos.y()); };
50     VMatrix &translate(float dx, float dy);
51     VMatrix &scale(VPointF s) { return scale(s.x(), s.y()); };
52     VMatrix &scale(float sx, float sy);
53     VMatrix &shear(float sh, float sv);
54     VMatrix &rotate(float a, Axis axis = VMatrix::Axis::Z);
55     VMatrix &rotateRadians(float a, Axis axis = VMatrix::Axis::Z);
56
57     VPointF        map(const VPointF &p) const;
58     inline VPointF map(float x, float y) const;
59     VRect          map(const VRect &r) const;
60     VRegion        map(const VRegion &r) const;
61
62     V_REQUIRED_RESULT VMatrix inverted(bool *invertible = nullptr) const;
63     V_REQUIRED_RESULT VMatrix adjoint() const;
64
65     VMatrix              operator*(const VMatrix &o) const;
66     VMatrix &            operator*=(const VMatrix &);
67     VMatrix &            operator*=(float mul);
68     VMatrix &            operator/=(float div);
69     bool                 operator==(const VMatrix &) const;
70     bool                 operator!=(const VMatrix &) const;
71     bool                 fuzzyCompare(const VMatrix &) const;
72     friend std::ostream &operator<<(std::ostream &os, const VMatrix &o);
73
74 private:
75     friend struct VSpanData;
76     float              m11{1}, m12{0}, m13{0};
77     float              m21{0}, m22{1}, m23{0};
78     float              mtx{0}, mty{0}, m33{1};
79     mutable MatrixType mType{MatrixType::None};
80     mutable MatrixType dirty{MatrixType::None};
81 };
82
83 inline VPointF VMatrix::map(float x, float y) const
84 {
85     return map(VPointF(x, y));
86 }
87
88 V_END_NAMESPACE
89
90 #endif  // VMATRIX_H