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 
36 namespace Pt {
37 
38 namespace Gfx {
39 
48 class PT_GFX_API Transform
49 {
50  public:
54 
57  Transform(double m11, double m12,
58  double m21, double m22,
59  double dx, double dy);
60 
64 
67  bool isIdentity() const;
68 
71  bool isAffine() const;
72 
75  bool isSimple() const;
76 
79  double m11() const;
80 
83  double m12() const;
84 
87  double m21() const;
88 
91  double m22() const;
92 
95  double dx() const;
96 
99  double dy() const;
100 
103  void reset();
104 
107  void set(double m11, double m12,
108  double m21, double m22,
109  double dx, double dy);
110 
113  void translate(double x, double y);
114 
117  void scale(double x, double y);
118 
121  void rotateDeg(double angle);
122 
125  void rotateRad(double angle);
126 
129  void shear(double sh, double sv);
130 
133  void shearX(double sh);
134 
137  void shearY(double sh);
138 
141  bool operator==(const Transform& t) const;
142 
145  bool operator!=(const Transform& t) const;
146 
150 
153  Transform operator*(const Transform& t) const;
154 
157  PointF operator*(const PointF& p) const;
158 
161  SizeF operator*(const SizeF& p) const;
162 
165  double determinant() const;
166 
169  bool isInvertible() const;
170 
174 
175  private:
176  typedef double MatrixData[2][3];
177 
178  void concat(const MatrixData& m);
179 
180  void updateIdentity();
181 
182  private:
183  MatrixData _mdata;
184  bool _isIdentity;
185 };
186 
187 } // namespace
188 
189 } // namespace
190 
191 #endif
Core module.
Definition: pt-gfx-images.dox:14
bool isIdentity() const
Returns true if the transform is the identity matrix.
Transform inverted() const
Returns the inverse transform.
double dx() const
Returns the horizontal translation.
void rotateDeg(double angle)
Appends a rotation specified in degrees.
void shearX(double sh)
Appends horizontal shearing.
PointF operator*(const PointF &p) const
Transforms a point.
void shear(double sh, double sv)
Appends horizontal and vertical shearing.
void shearY(double sh)
Appends vertical shearing.
void rotateRad(double angle)
Appends a rotation specified in radians.
Transform()
Constructs the identity transform.
Transform & operator*=(const Transform &t)
Appends another transform in place.
Size with floating-point width and height.
Definition: Size.h:45
Point with floating-point X and Y coordinates.
Definition: Point.h:45
Transform operator*(const Transform &t) const
Returns the composition of two transforms.
~Transform()
Destroys the transform.
Affine transform for drawing coordinates.
Definition: Transform.h:49
double m21() const
Returns the second row, first column coefficient.
bool operator!=(const Transform &t) const
Returns true if both transforms are different.
double m12() const
Returns the first row, second column coefficient.
SizeF operator*(const SizeF &p) const
Transforms a size.
void scale(double x, double y)
Appends a scaling.
void set(double m11, double m12, double m21, double m22, double dx, double dy)
Replaces the matrix coefficients.
double m11() const
Returns the first row, first column coefficient.
double determinant() const
Returns the matrix determinant.
Transform(double m11, double m12, double m21, double m22, double dx, double dy)
Constructs a transform from explicit matrix components.
bool isAffine() const
Returns true if the transform is affine.
bool operator==(const Transform &t) const
Returns true if both transforms are equal.
double m22() const
Returns the second row, second column coefficient.
bool isInvertible() const
Returns true if the transform can be inverted.
bool isSimple() const
Returns true if the matrix is only translating and scaling.
void reset()
Resets the transform to identity.
double dy() const
Returns the vertical translation.
void translate(double x, double y)
Appends a translation.