Transform.h
1/* Copyright (C) 2017 Marc Boris Duerner
2 Copyright (C) 2017 Aloysius Indrayanto
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 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 MA 02110-1301 USA
28*/
29
30#ifndef PT_GFX_TRANSFORM_H
31#define PT_GFX_TRANSFORM_H
32
33#include <Pt/Gfx/Point.h>
34#include <Pt/Gfx/Size.h>
35
36namespace Pt {
37
38namespace Gfx {
39
53class PT_GFX_API Transform
54{
55 public:
59
62 Transform(double m11, double m12,
63 double m21, double m22,
64 double dx, double dy);
65
69
72 bool isIdentity() const;
73
76 bool isAffine() const;
77
80 bool isSimple() const;
81
84 double m11() const;
85
88 double m12() const;
89
92 double m21() const;
93
96 double m22() const;
97
100 double dx() const;
101
104 double dy() const;
105
108 void reset();
109
112 void set(double m11, double m12,
113 double m21, double m22,
114 double dx, double dy);
115
118 void translate(double x, double y);
119
122 void scale(double x, double y);
123
126 void rotateDeg(double angle);
127
130 void rotateRad(double angle);
131
134 void shear(double sh, double sv);
135
138 void shearX(double sh);
139
142 void shearY(double sh);
143
146 bool operator==(const Transform& t) const;
147
150 bool operator!=(const Transform& t) const;
151
155
159
162 PointF operator*(const PointF& p) const;
163
166 SizeF operator*(const SizeF& p) const;
167
170 double determinant() const;
171
174 bool isInvertible() const;
175
179
180 private:
181 typedef double MatrixData[2][3];
182
183 void concat(const MatrixData& m);
184
185 void updateIdentity();
186
187 private:
188 MatrixData _mdata;
189 bool _isIdentity;
190};
191
192} // namespace
193
194} // namespace
195
196#endif
bool isSimple() const
Returns true if the matrix is only translating and scaling.
void shear(double sh, double sv)
Appends horizontal and vertical shearing.
void shearY(double sh)
Appends vertical shearing.
double dy() const
Returns the vertical translation.
Transform operator*(const Transform &t) const
Returns the composition of two transforms.
void shearX(double sh)
Appends horizontal shearing.
bool isAffine() const
Returns true if the transform is affine.
double m21() const
Returns the second row, first column coefficient.
void rotateRad(double angle)
Appends a rotation specified in radians.
double determinant() const
Returns the matrix determinant.
void rotateDeg(double angle)
Appends a rotation specified in degrees.
double dx() const
Returns the horizontal translation.
double m12() const
Returns the first row, second column coefficient.
void scale(double x, double y)
Appends a scaling.
Transform & operator*=(const Transform &t)
Appends another transform in place.
~Transform()
Destroys the transform.
Transform(double m11, double m12, double m21, double m22, double dx, double dy)
Constructs a transform from explicit matrix components.
bool operator!=(const Transform &t) const
Returns true if both transforms are different.
bool isInvertible() const
Returns true if the transform can be inverted.
Transform()
Constructs the identity transform.
SizeF operator*(const SizeF &p) const
Transforms a size.
double m11() const
Returns the first row, first column coefficient.
PointF operator*(const PointF &p) const
Transforms a point.
bool isIdentity() const
Returns true if the transform is the identity matrix.
Transform inverted() const
Returns the inverse transform.
void reset()
Resets the transform to identity.
double m22() const
Returns the second row, second column coefficient.
void translate(double x, double y)
Appends a translation.
void set(double m11, double m12, double m21, double m22, double dx, double dy)
Replaces the matrix coefficients.
bool operator==(const Transform &t) const
Returns true if both transforms are equal.
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33