1 /*
2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "wtf/Platform.h"
27 #include "AffineTransform.h"
28 
29 #include "IntRect.h"
30 #include "FloatRect.h"
31 
32 namespace WebCore
33 {
34 
AffineTransform()35 AffineTransform::AffineTransform()
36     : m_transform()
37 {
38 }
39 
AffineTransform(double a,double b,double c,double d,double tx,double ty)40 AffineTransform::AffineTransform(double a, double b, double c, double d, double tx, double ty)
41     : m_transform(a, b, c, d, tx, ty)
42 {
43 }
44 
AffineTransform(const QMatrix & matrix)45 AffineTransform::AffineTransform(const QMatrix &matrix)
46     : m_transform(matrix)
47 {
48 }
49 
setMatrix(double a,double b,double c,double d,double tx,double ty)50 void AffineTransform::setMatrix(double a, double b, double c, double d, double tx, double ty)
51 {
52     m_transform.setMatrix(a, b, c, d, tx, ty);
53 }
54 
map(double x,double y,double * x2,double * y2) const55 void AffineTransform::map(double x, double y, double *x2, double *y2) const
56 {
57     qreal tx2, ty2;
58     m_transform.map(qreal(x), qreal(y), &tx2, &ty2);
59     *x2 = tx2;
60     *y2 = ty2;
61 }
62 
mapRect(const IntRect & rect) const63 IntRect AffineTransform::mapRect(const IntRect &rect) const
64 {
65     return m_transform.mapRect(rect);
66 }
67 
mapRect(const FloatRect & rect) const68 FloatRect AffineTransform::mapRect(const FloatRect &rect) const
69 {
70     return m_transform.mapRect(rect);
71 }
72 
isIdentity() const73 bool AffineTransform::isIdentity() const
74 {
75     return m_transform.isIdentity();
76 }
77 
a() const78 double AffineTransform::a() const
79 {
80     return m_transform.m11();
81 }
82 
setA(double a)83 void AffineTransform::setA(double a)
84 {
85     m_transform.setMatrix(a, b(), c(), d(), e(), f());
86 }
87 
b() const88 double AffineTransform::b() const
89 {
90     return m_transform.m12();
91 }
92 
setB(double b)93 void AffineTransform::setB(double b)
94 {
95     m_transform.setMatrix(a(), b, c(), d(), e(), f());
96 }
97 
c() const98 double AffineTransform::c() const
99 {
100     return m_transform.m21();
101 }
102 
setC(double c)103 void AffineTransform::setC(double c)
104 {
105     m_transform.setMatrix(a(), b(), c, d(), e(), f());
106 }
107 
d() const108 double AffineTransform::d() const
109 {
110     return m_transform.m22();
111 }
112 
setD(double d)113 void AffineTransform::setD(double d)
114 {
115     m_transform.setMatrix(a(), b(), c(), d, e(), f());
116 }
117 
e() const118 double AffineTransform::e() const
119 {
120     return m_transform.dx();
121 }
122 
setE(double e)123 void AffineTransform::setE(double e)
124 {
125     m_transform.setMatrix(a(), b(), c(), d(), e, f());
126 }
127 
f() const128 double AffineTransform::f() const
129 {
130     return m_transform.dy();
131 }
132 
setF(double f)133 void AffineTransform::setF(double f)
134 {
135     m_transform.setMatrix(a(), b(), c(), d(), e(), f);
136 }
137 
reset()138 void AffineTransform::reset()
139 {
140     m_transform.reset();
141 }
142 
scale(double sx,double sy)143 AffineTransform &AffineTransform::scale(double sx, double sy)
144 {
145     m_transform.scale(sx, sy);
146     return *this;
147 }
148 
rotate(double d)149 AffineTransform &AffineTransform::rotate(double d)
150 {
151     m_transform.rotate(d);
152     return *this;
153 }
154 
translate(double tx,double ty)155 AffineTransform &AffineTransform::translate(double tx, double ty)
156 {
157     m_transform.translate(tx, ty);
158     return *this;
159 }
160 
shear(double sx,double sy)161 AffineTransform &AffineTransform::shear(double sx, double sy)
162 {
163     m_transform.shear(sx, sy);
164     return *this;
165 }
166 
det() const167 double AffineTransform::det() const
168 {
169     return m_transform.determinant();
170 }
171 
inverse() const172 AffineTransform AffineTransform::inverse() const
173 {
174     if (!isInvertible()) {
175         return AffineTransform();
176     }
177 
178     return m_transform.inverted();
179 }
180 
operator QMatrix() const181 AffineTransform::operator QMatrix() const
182 {
183     return m_transform;
184 }
185 
operator ==(const AffineTransform & other) const186 bool AffineTransform::operator==(const AffineTransform &other) const
187 {
188     return m_transform == other.m_transform;
189 }
190 
operator *=(const AffineTransform & other)191 AffineTransform &AffineTransform::operator*=(const AffineTransform &other)
192 {
193     m_transform *= other.m_transform;
194     return *this;
195 }
196 
operator *(const AffineTransform & other)197 AffineTransform AffineTransform::operator*(const AffineTransform &other)
198 {
199     return m_transform * other.m_transform;
200 }
201 
202 }
203 
204