Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qtransform.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | __attribute__((noinline)) | - | ||||||||||||
8 | static void nanWarning(const char *func) | - | ||||||||||||
9 | { | - | ||||||||||||
10 | QMessageLogger(__FILE__, 60, __PRETTY_FUNCTION__).warning("QTransform::%s with NaN called", func); | - | ||||||||||||
11 | } never executed: end of block | 0 | ||||||||||||
12 | QTransform::QTransform() | - | ||||||||||||
13 | : affine(true) | - | ||||||||||||
14 | , m_13(0), m_23(0), m_33(1) | - | ||||||||||||
15 | , m_type(TxNone) | - | ||||||||||||
16 | , m_dirty(TxNone) | - | ||||||||||||
17 | , d(nullptr) | - | ||||||||||||
18 | { | - | ||||||||||||
19 | } | - | ||||||||||||
20 | QTransform::QTransform(qreal h11, qreal h12, qreal h13, | - | ||||||||||||
21 | qreal h21, qreal h22, qreal h23, | - | ||||||||||||
22 | qreal h31, qreal h32, qreal h33) | - | ||||||||||||
23 | : affine(h11, h12, h21, h22, h31, h32, true) | - | ||||||||||||
24 | , m_13(h13), m_23(h23), m_33(h33) | - | ||||||||||||
25 | , m_type(TxNone) | - | ||||||||||||
26 | , m_dirty(TxProject) | - | ||||||||||||
27 | , d(nullptr) | - | ||||||||||||
28 | { | - | ||||||||||||
29 | } | - | ||||||||||||
30 | QTransform::QTransform(qreal h11, qreal h12, qreal h21, | - | ||||||||||||
31 | qreal h22, qreal dx, qreal dy) | - | ||||||||||||
32 | : affine(h11, h12, h21, h22, dx, dy, true) | - | ||||||||||||
33 | , m_13(0), m_23(0), m_33(1) | - | ||||||||||||
34 | , m_type(TxNone) | - | ||||||||||||
35 | , m_dirty(TxShear) | - | ||||||||||||
36 | , d(nullptr) | - | ||||||||||||
37 | { | - | ||||||||||||
38 | } | - | ||||||||||||
39 | QTransform::QTransform(const QMatrix &mtx) | - | ||||||||||||
40 | : affine(mtx._m11, mtx._m12, mtx._m21, mtx._m22, mtx._dx, mtx._dy, true), | - | ||||||||||||
41 | m_13(0), m_23(0), m_33(1) | - | ||||||||||||
42 | , m_type(TxNone) | - | ||||||||||||
43 | , m_dirty(TxShear) | - | ||||||||||||
44 | , d(nullptr) | - | ||||||||||||
45 | { | - | ||||||||||||
46 | } | - | ||||||||||||
47 | - | |||||||||||||
48 | - | |||||||||||||
49 | - | |||||||||||||
50 | - | |||||||||||||
51 | QTransform QTransform::adjoint() const | - | ||||||||||||
52 | { | - | ||||||||||||
53 | qreal h11, h12, h13, | - | ||||||||||||
54 | h21, h22, h23, | - | ||||||||||||
55 | h31, h32, h33; | - | ||||||||||||
56 | h11 = affine._m22*m_33 - m_23*affine._dy; | - | ||||||||||||
57 | h21 = m_23*affine._dx - affine._m21*m_33; | - | ||||||||||||
58 | h31 = affine._m21*affine._dy - affine._m22*affine._dx; | - | ||||||||||||
59 | h12 = m_13*affine._dy - affine._m12*m_33; | - | ||||||||||||
60 | h22 = affine._m11*m_33 - m_13*affine._dx; | - | ||||||||||||
61 | h32 = affine._m12*affine._dx - affine._m11*affine._dy; | - | ||||||||||||
62 | h13 = affine._m12*m_23 - m_13*affine._m22; | - | ||||||||||||
63 | h23 = m_13*affine._m21 - affine._m11*m_23; | - | ||||||||||||
64 | h33 = affine._m11*affine._m22 - affine._m12*affine._m21; | - | ||||||||||||
65 | - | |||||||||||||
66 | return QTransform(h11, h12, h13, | - | ||||||||||||
67 | h21, h22, h23, | - | ||||||||||||
68 | h31, h32, h33, true); | - | ||||||||||||
69 | } | - | ||||||||||||
70 | - | |||||||||||||
71 | - | |||||||||||||
72 | - | |||||||||||||
73 | - | |||||||||||||
74 | QTransform QTransform::transposed() const | - | ||||||||||||
75 | { | - | ||||||||||||
76 | QTransform t(affine._m11, affine._m21, affine._dx, | - | ||||||||||||
77 | affine._m12, affine._m22, affine._dy, | - | ||||||||||||
78 | m_13, m_23, m_33, true); | - | ||||||||||||
79 | t.m_type = m_type; | - | ||||||||||||
80 | t.m_dirty = m_dirty; | - | ||||||||||||
81 | return t; | - | ||||||||||||
82 | } | - | ||||||||||||
83 | QTransform QTransform::inverted(bool *invertible) const | - | ||||||||||||
84 | { | - | ||||||||||||
85 | QTransform invert(true); | - | ||||||||||||
86 | bool inv = true; | - | ||||||||||||
87 | - | |||||||||||||
88 | switch(inline_type()) { | - | ||||||||||||
89 | case TxNone: | - | ||||||||||||
90 | break; | - | ||||||||||||
91 | case TxTranslate: | - | ||||||||||||
92 | invert.affine._dx = -affine._dx; | - | ||||||||||||
93 | invert.affine._dy = -affine._dy; | - | ||||||||||||
94 | break; | - | ||||||||||||
95 | case TxScale: | - | ||||||||||||
96 | inv = !qFuzzyIsNull(affine._m11); | - | ||||||||||||
97 | inv &= !qFuzzyIsNull(affine._m22); | - | ||||||||||||
98 | if (inv) { | - | ||||||||||||
99 | invert.affine._m11 = 1. / affine._m11; | - | ||||||||||||
100 | invert.affine._m22 = 1. / affine._m22; | - | ||||||||||||
101 | invert.affine._dx = -affine._dx * invert.affine._m11; | - | ||||||||||||
102 | invert.affine._dy = -affine._dy * invert.affine._m22; | - | ||||||||||||
103 | } | - | ||||||||||||
104 | break; | - | ||||||||||||
105 | case TxRotate: | - | ||||||||||||
106 | case TxShear: | - | ||||||||||||
107 | invert.affine = affine.inverted(&inv); | - | ||||||||||||
108 | break; | - | ||||||||||||
109 | default: | - | ||||||||||||
110 | - | |||||||||||||
111 | qreal det = determinant(); | - | ||||||||||||
112 | inv = !qFuzzyIsNull(det); | - | ||||||||||||
113 | if (inv) | - | ||||||||||||
114 | invert = adjoint() / det; | - | ||||||||||||
115 | break; | - | ||||||||||||
116 | } | - | ||||||||||||
117 | - | |||||||||||||
118 | if (invertible) | - | ||||||||||||
119 | *invertible = inv; | - | ||||||||||||
120 | - | |||||||||||||
121 | if (inv) { | - | ||||||||||||
122 | - | |||||||||||||
123 | invert.m_type = m_type; | - | ||||||||||||
124 | invert.m_dirty = m_dirty; | - | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | return invert; | - | ||||||||||||
128 | } | - | ||||||||||||
129 | - | |||||||||||||
130 | - | |||||||||||||
131 | - | |||||||||||||
132 | - | |||||||||||||
133 | - | |||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | QTransform &QTransform::translate(qreal dx, qreal dy) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | if (dx == 0
| 0 | ||||||||||||
139 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
140 | - | |||||||||||||
141 | if (qIsNaN(dx) | qIsNaN(dy)
| 0 | ||||||||||||
142 | QMessageLoggernanWarning(__FILE__, 415, __PRETTY_FUNCTION__).warning() << "QTransform::translate with NaN called";"translate"); | - | ||||||||||||
143 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
144 | } | - | ||||||||||||
145 | - | |||||||||||||
146 | - | |||||||||||||
147 | switch(inline_type()) { | - | ||||||||||||
148 | case never executed: TxNone:case TxNone: never executed: case TxNone: | 0 | ||||||||||||
149 | affine._dx = dx; | - | ||||||||||||
150 | affine._dy = dy; | - | ||||||||||||
151 | break; never executed: break; | 0 | ||||||||||||
152 | case never executed: TxTranslate:case TxTranslate: never executed: case TxTranslate: | 0 | ||||||||||||
153 | affine._dx += dx; | - | ||||||||||||
154 | affine._dy += dy; | - | ||||||||||||
155 | break; never executed: break; | 0 | ||||||||||||
156 | case never executed: TxScale:case TxScale: never executed: case TxScale: | 0 | ||||||||||||
157 | affine._dx += dx*affine._m11; | - | ||||||||||||
158 | affine._dy += dy*affine._m22; | - | ||||||||||||
159 | break; never executed: break; | 0 | ||||||||||||
160 | case never executed: TxProject:case TxProject: never executed: case TxProject: | 0 | ||||||||||||
161 | m_33 += dx*m_13 + dy*m_23; | - | ||||||||||||
162 | - | |||||||||||||
163 | case never executed: TxShear:case TxShear: never executed: case TxShear: code before this statement never executed: case TxShear: | 0 | ||||||||||||
164 | case never executed: TxRotate:case TxRotate: never executed: case TxRotate: | 0 | ||||||||||||
165 | affine._dx += dx*affine._m11 + dy*affine._m21; | - | ||||||||||||
166 | affine._dy += dy*affine._m22 + dx*affine._m12; | - | ||||||||||||
167 | break; never executed: break; | 0 | ||||||||||||
168 | } | - | ||||||||||||
169 | if (m_dirty < TxTranslate
| 0 | ||||||||||||
170 | m_dirty = TxTranslate; never executed: m_dirty = TxTranslate; | 0 | ||||||||||||
171 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
172 | } | - | ||||||||||||
173 | QTransform QTransform::fromTranslate(qreal dx, qreal dy) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | - | |||||||||||||
176 | if (qIsNaN(dx) | qIsNaN(dy)
| 0 | ||||||||||||
177 | QMessageLoggernanWarning(__FILE__, 458, __PRETTY_FUNCTION__).warning() << "QTransform::fromTranslate with NaN called";"fromTranslate"); | - | ||||||||||||
178 | return never executed: QTransform();return QTransform(); never executed: return QTransform(); | 0 | ||||||||||||
179 | } | - | ||||||||||||
180 | - | |||||||||||||
181 | QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true); | - | ||||||||||||
182 | if (dx == 0
| 0 | ||||||||||||
183 | transform.m_type = TxNone; never executed: transform.m_type = TxNone; | 0 | ||||||||||||
184 | else | - | ||||||||||||
185 | transform.m_type = TxTranslate; never executed: transform.m_type = TxTranslate; | 0 | ||||||||||||
186 | transform.m_dirty = TxNone; | - | ||||||||||||
187 | return never executed: transform;return transform; never executed: return transform; | 0 | ||||||||||||
188 | } | - | ||||||||||||
189 | - | |||||||||||||
190 | - | |||||||||||||
191 | - | |||||||||||||
192 | - | |||||||||||||
193 | - | |||||||||||||
194 | - | |||||||||||||
195 | - | |||||||||||||
196 | QTransform & QTransform::scale(qreal sx, qreal sy) | - | ||||||||||||
197 | { | - | ||||||||||||
198 | if (sx == 1
| 0 | ||||||||||||
199 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
200 | - | |||||||||||||
201 | if (qIsNaN(sx) | qIsNaN(sy)
| 0 | ||||||||||||
202 | QMessageLoggernanWarning(__FILE__, 483, __PRETTY_FUNCTION__).warning() << "QTransform::scale with NaN called";"scale"); | - | ||||||||||||
203 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
204 | } | - | ||||||||||||
205 | - | |||||||||||||
206 | - | |||||||||||||
207 | switch(inline_type()) { | - | ||||||||||||
208 | case never executed: TxNone:case TxNone: never executed: case TxNone: | 0 | ||||||||||||
209 | case never executed: TxTranslate:case TxTranslate: never executed: case TxTranslate: | 0 | ||||||||||||
210 | affine._m11 = sx; | - | ||||||||||||
211 | affine._m22 = sy; | - | ||||||||||||
212 | break; never executed: break; | 0 | ||||||||||||
213 | case never executed: TxProject:case TxProject: never executed: case TxProject: | 0 | ||||||||||||
214 | m_13 *= sx; | - | ||||||||||||
215 | m_23 *= sy; | - | ||||||||||||
216 | - | |||||||||||||
217 | case never executed: TxRotate:case TxRotate: never executed: case TxRotate: code before this statement never executed: case TxRotate: | 0 | ||||||||||||
218 | case never executed: TxShear:case TxShear: never executed: case TxShear: | 0 | ||||||||||||
219 | affine._m12 *= sx; | - | ||||||||||||
220 | affine._m21 *= sy; | - | ||||||||||||
221 | - | |||||||||||||
222 | case never executed: TxScale:case TxScale: never executed: case TxScale: code before this statement never executed: case TxScale: | 0 | ||||||||||||
223 | affine._m11 *= sx; | - | ||||||||||||
224 | affine._m22 *= sy; | - | ||||||||||||
225 | break; never executed: break; | 0 | ||||||||||||
226 | } | - | ||||||||||||
227 | if (m_dirty < TxScale
| 0 | ||||||||||||
228 | m_dirty = TxScale; never executed: m_dirty = TxScale; | 0 | ||||||||||||
229 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
230 | } | - | ||||||||||||
231 | QTransform QTransform::fromScale(qreal sx, qreal sy) | - | ||||||||||||
232 | { | - | ||||||||||||
233 | - | |||||||||||||
234 | if (qIsNaN(sx) | qIsNaN(sy)
| 0 | ||||||||||||
235 | QMessageLoggernanWarning(__FILE__, 524, __PRETTY_FUNCTION__).warning() << "QTransform::fromScale with NaN called";"fromScale"); | - | ||||||||||||
236 | return never executed: QTransform();return QTransform(); never executed: return QTransform(); | 0 | ||||||||||||
237 | } | - | ||||||||||||
238 | - | |||||||||||||
239 | QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true); | - | ||||||||||||
240 | if (sx == 1.
| 0 | ||||||||||||
241 | transform.m_type = TxNone; never executed: transform.m_type = TxNone; | 0 | ||||||||||||
242 | else | - | ||||||||||||
243 | transform.m_type = TxScale; never executed: transform.m_type = TxScale; | 0 | ||||||||||||
244 | transform.m_dirty = TxNone; | - | ||||||||||||
245 | return never executed: transform;return transform; never executed: return transform; | 0 | ||||||||||||
246 | } | - | ||||||||||||
247 | - | |||||||||||||
248 | - | |||||||||||||
249 | - | |||||||||||||
250 | - | |||||||||||||
251 | - | |||||||||||||
252 | - | |||||||||||||
253 | - | |||||||||||||
254 | QTransform & QTransform::shear(qreal sh, qreal sv) | - | ||||||||||||
255 | { | - | ||||||||||||
256 | if (sh == 0
| 0 | ||||||||||||
257 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
258 | - | |||||||||||||
259 | if (qIsNaN(sh) | qIsNaN(sv)
| 0 | ||||||||||||
260 | QMessageLoggernanWarning(__FILE__, 549, __PRETTY_FUNCTION__).warning() << "QTransform::shear with NaN called";"shear"); | - | ||||||||||||
261 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
262 | } | - | ||||||||||||
263 | - | |||||||||||||
264 | - | |||||||||||||
265 | switch(inline_type()) { | - | ||||||||||||
266 | case never executed: TxNone:case TxNone: never executed: case TxNone: | 0 | ||||||||||||
267 | case never executed: TxTranslate:case TxTranslate: never executed: case TxTranslate: | 0 | ||||||||||||
268 | affine._m12 = sv; | - | ||||||||||||
269 | affine._m21 = sh; | - | ||||||||||||
270 | break; never executed: break; | 0 | ||||||||||||
271 | case never executed: TxScale:case TxScale: never executed: case TxScale: | 0 | ||||||||||||
272 | affine._m12 = sv*affine._m22; | - | ||||||||||||
273 | affine._m21 = sh*affine._m11; | - | ||||||||||||
274 | break; never executed: break; | 0 | ||||||||||||
275 | case never executed: TxProject:case TxProject: never executed: {case TxProject: | 0 | ||||||||||||
276 | qreal tm13 = sv*m_23; | - | ||||||||||||
277 | qreal tm23 = sh*m_13; | - | ||||||||||||
278 | m_13 += tm13; | - | ||||||||||||
279 | m_23 += tm23; | - | ||||||||||||
280 | } | - | ||||||||||||
281 | - | |||||||||||||
282 | case never executed: TxRotate:case TxRotate: never executed: case TxRotate: code before this statement never executed: case TxRotate: | 0 | ||||||||||||
283 | case never executed: TxShear:case TxShear: never executed: {case TxShear: | 0 | ||||||||||||
284 | qreal tm11 = sv*affine._m21; | - | ||||||||||||
285 | qreal tm22 = sh*affine._m12; | - | ||||||||||||
286 | qreal tm12 = sv*affine._m22; | - | ||||||||||||
287 | qreal tm21 = sh*affine._m11; | - | ||||||||||||
288 | affine._m11 += tm11; affine._m12 += tm12; | - | ||||||||||||
289 | affine._m21 += tm21; affine._m22 += tm22; | - | ||||||||||||
290 | break; never executed: break; | 0 | ||||||||||||
291 | } | - | ||||||||||||
292 | } | - | ||||||||||||
293 | if (m_dirty < TxShear
| 0 | ||||||||||||
294 | m_dirty = TxShear; never executed: m_dirty = TxShear; | 0 | ||||||||||||
295 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
296 | } | - | ||||||||||||
297 | - | |||||||||||||
298 | const qreal deg2rad = qreal(0.017453292519943295769); | - | ||||||||||||
299 | const qreal inv_dist_to_plane = 1. / 1024.; | - | ||||||||||||
300 | QTransform & QTransform::rotate(qreal a, Qt::Axis axis) | - | ||||||||||||
301 | { | - | ||||||||||||
302 | if (a == 0
| 0 | ||||||||||||
303 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
304 | - | |||||||||||||
305 | if (qIsNaN(a)
| 0 | ||||||||||||
306 | QMessageLoggernanWarning(__FILE__, 610, __PRETTY_FUNCTION__).warning() << "QTransform::rotate with NaN called";"rotate"); | - | ||||||||||||
307 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
308 | } | - | ||||||||||||
309 | - | |||||||||||||
310 | - | |||||||||||||
311 | qreal sina = 0; | - | ||||||||||||
312 | qreal cosa = 0; | - | ||||||||||||
313 | if (a == 90.
| 0 | ||||||||||||
314 | sina = 1.; never executed: sina = 1.; | 0 | ||||||||||||
315 | else if (a == 270.
| 0 | ||||||||||||
316 | sina = -1.; never executed: sina = -1.; | 0 | ||||||||||||
317 | else if (a == 180.
| 0 | ||||||||||||
318 | cosa = -1.; never executed: cosa = -1.; | 0 | ||||||||||||
319 | else{ | - | ||||||||||||
320 | qreal b = deg2rad*a; | - | ||||||||||||
321 | sina = qSin(b); | - | ||||||||||||
322 | cosa = qCos(b); | - | ||||||||||||
323 | } never executed: end of block | 0 | ||||||||||||
324 | - | |||||||||||||
325 | if (axis == Qt::ZAxis
| 0 | ||||||||||||
326 | switch(inline_type()) { | - | ||||||||||||
327 | case never executed: TxNone:case TxNone: never executed: case TxNone: | 0 | ||||||||||||
328 | case never executed: TxTranslate:case TxTranslate: never executed: case TxTranslate: | 0 | ||||||||||||
329 | affine._m11 = cosa; | - | ||||||||||||
330 | affine._m12 = sina; | - | ||||||||||||
331 | affine._m21 = -sina; | - | ||||||||||||
332 | affine._m22 = cosa; | - | ||||||||||||
333 | break; never executed: break; | 0 | ||||||||||||
334 | case never executed: TxScale:case TxScale: never executed: {case TxScale: | 0 | ||||||||||||
335 | qreal tm11 = cosa*affine._m11; | - | ||||||||||||
336 | qreal tm12 = sina*affine._m22; | - | ||||||||||||
337 | qreal tm21 = -sina*affine._m11; | - | ||||||||||||
338 | qreal tm22 = cosa*affine._m22; | - | ||||||||||||
339 | affine._m11 = tm11; affine._m12 = tm12; | - | ||||||||||||
340 | affine._m21 = tm21; affine._m22 = tm22; | - | ||||||||||||
341 | break; never executed: break; | 0 | ||||||||||||
342 | } | - | ||||||||||||
343 | case never executed: TxProject:case TxProject: never executed: {case TxProject: | 0 | ||||||||||||
344 | qreal tm13 = cosa*m_13 + sina*m_23; | - | ||||||||||||
345 | qreal tm23 = -sina*m_13 + cosa*m_23; | - | ||||||||||||
346 | m_13 = tm13; | - | ||||||||||||
347 | m_23 = tm23; | - | ||||||||||||
348 | - | |||||||||||||
349 | } | - | ||||||||||||
350 | case never executed: TxRotate:case TxRotate: never executed: case TxRotate: code before this statement never executed: case TxRotate: | 0 | ||||||||||||
351 | case never executed: TxShear:case TxShear: never executed: {case TxShear: | 0 | ||||||||||||
352 | qreal tm11 = cosa*affine._m11 + sina*affine._m21; | - | ||||||||||||
353 | qreal tm12 = cosa*affine._m12 + sina*affine._m22; | - | ||||||||||||
354 | qreal tm21 = -sina*affine._m11 + cosa*affine._m21; | - | ||||||||||||
355 | qreal tm22 = -sina*affine._m12 + cosa*affine._m22; | - | ||||||||||||
356 | affine._m11 = tm11; affine._m12 = tm12; | - | ||||||||||||
357 | affine._m21 = tm21; affine._m22 = tm22; | - | ||||||||||||
358 | break; never executed: break; | 0 | ||||||||||||
359 | } | - | ||||||||||||
360 | } | - | ||||||||||||
361 | if (m_dirty < TxRotate
| 0 | ||||||||||||
362 | m_dirty = TxRotate; never executed: m_dirty = TxRotate; | 0 | ||||||||||||
363 | } never executed: else {end of block | 0 | ||||||||||||
364 | QTransform result; | - | ||||||||||||
365 | if (axis == Qt::YAxis
| 0 | ||||||||||||
366 | result.affine._m11 = cosa; | - | ||||||||||||
367 | result.m_13 = -sina * inv_dist_to_plane; | - | ||||||||||||
368 | } never executed: else {end of block | 0 | ||||||||||||
369 | result.affine._m22 = cosa; | - | ||||||||||||
370 | result.m_23 = -sina * inv_dist_to_plane; | - | ||||||||||||
371 | } never executed: end of block | 0 | ||||||||||||
372 | result.m_type = TxProject; | - | ||||||||||||
373 | *this = result * *this; | - | ||||||||||||
374 | } never executed: end of block | 0 | ||||||||||||
375 | - | |||||||||||||
376 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
377 | } | - | ||||||||||||
378 | QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis) | - | ||||||||||||
379 | { | - | ||||||||||||
380 | - | |||||||||||||
381 | if (qIsNaN(a)
| 0 | ||||||||||||
382 | QMessageLoggernanWarning(__FILE__, 701, __PRETTY_FUNCTION__).warning() << "QTransform::rotateRadians with NaN called";"rotateRadians"); | - | ||||||||||||
383 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
384 | } | - | ||||||||||||
385 | - | |||||||||||||
386 | qreal sina = qSin(a); | - | ||||||||||||
387 | qreal cosa = qCos(a); | - | ||||||||||||
388 | - | |||||||||||||
389 | if (axis == Qt::ZAxis
| 0 | ||||||||||||
390 | switch(inline_type()) { | - | ||||||||||||
391 | case never executed: TxNone:case TxNone: never executed: case TxNone: | 0 | ||||||||||||
392 | case never executed: TxTranslate:case TxTranslate: never executed: case TxTranslate: | 0 | ||||||||||||
393 | affine._m11 = cosa; | - | ||||||||||||
394 | affine._m12 = sina; | - | ||||||||||||
395 | affine._m21 = -sina; | - | ||||||||||||
396 | affine._m22 = cosa; | - | ||||||||||||
397 | break; never executed: break; | 0 | ||||||||||||
398 | case never executed: TxScale:case TxScale: never executed: {case TxScale: | 0 | ||||||||||||
399 | qreal tm11 = cosa*affine._m11; | - | ||||||||||||
400 | qreal tm12 = sina*affine._m22; | - | ||||||||||||
401 | qreal tm21 = -sina*affine._m11; | - | ||||||||||||
402 | qreal tm22 = cosa*affine._m22; | - | ||||||||||||
403 | affine._m11 = tm11; affine._m12 = tm12; | - | ||||||||||||
404 | affine._m21 = tm21; affine._m22 = tm22; | - | ||||||||||||
405 | break; never executed: break; | 0 | ||||||||||||
406 | } | - | ||||||||||||
407 | case never executed: TxProject:case TxProject: never executed: {case TxProject: | 0 | ||||||||||||
408 | qreal tm13 = cosa*m_13 + sina*m_23; | - | ||||||||||||
409 | qreal tm23 = -sina*m_13 + cosa*m_23; | - | ||||||||||||
410 | m_13 = tm13; | - | ||||||||||||
411 | m_23 = tm23; | - | ||||||||||||
412 | - | |||||||||||||
413 | } | - | ||||||||||||
414 | case never executed: TxRotate:case TxRotate: never executed: case TxRotate: code before this statement never executed: case TxRotate: | 0 | ||||||||||||
415 | case never executed: TxShear:case TxShear: never executed: {case TxShear: | 0 | ||||||||||||
416 | qreal tm11 = cosa*affine._m11 + sina*affine._m21; | - | ||||||||||||
417 | qreal tm12 = cosa*affine._m12 + sina*affine._m22; | - | ||||||||||||
418 | qreal tm21 = -sina*affine._m11 + cosa*affine._m21; | - | ||||||||||||
419 | qreal tm22 = -sina*affine._m12 + cosa*affine._m22; | - | ||||||||||||
420 | affine._m11 = tm11; affine._m12 = tm12; | - | ||||||||||||
421 | affine._m21 = tm21; affine._m22 = tm22; | - | ||||||||||||
422 | break; never executed: break; | 0 | ||||||||||||
423 | } | - | ||||||||||||
424 | } | - | ||||||||||||
425 | if (m_dirty < TxRotate
| 0 | ||||||||||||
426 | m_dirty = TxRotate; never executed: m_dirty = TxRotate; | 0 | ||||||||||||
427 | } never executed: else {end of block | 0 | ||||||||||||
428 | QTransform result; | - | ||||||||||||
429 | if (axis == Qt::YAxis
| 0 | ||||||||||||
430 | result.affine._m11 = cosa; | - | ||||||||||||
431 | result.m_13 = -sina * inv_dist_to_plane; | - | ||||||||||||
432 | } never executed: else {end of block | 0 | ||||||||||||
433 | result.affine._m22 = cosa; | - | ||||||||||||
434 | result.m_23 = -sina * inv_dist_to_plane; | - | ||||||||||||
435 | } never executed: end of block | 0 | ||||||||||||
436 | result.m_type = TxProject; | - | ||||||||||||
437 | *this = result * *this; | - | ||||||||||||
438 | } never executed: end of block | 0 | ||||||||||||
439 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
440 | } | - | ||||||||||||
441 | - | |||||||||||||
442 | - | |||||||||||||
443 | - | |||||||||||||
444 | - | |||||||||||||
445 | - | |||||||||||||
446 | - | |||||||||||||
447 | bool QTransform::operator==(const QTransform &o) const | - | ||||||||||||
448 | { | - | ||||||||||||
449 | return affine._m11 == o.affine._m11 && | - | ||||||||||||
450 | affine._m12 == o.affine._m12 && | - | ||||||||||||
451 | affine._m21 == o.affine._m21 && | - | ||||||||||||
452 | affine._m22 == o.affine._m22 && | - | ||||||||||||
453 | affine._dx == o.affine._dx && | - | ||||||||||||
454 | affine._dy == o.affine._dy && | - | ||||||||||||
455 | m_13 == o.m_13 && | - | ||||||||||||
456 | m_23 == o.m_23 && | - | ||||||||||||
457 | m_33 == o.m_33; | - | ||||||||||||
458 | } | - | ||||||||||||
459 | uint qHash(const QTransform &key, uint seed) noexcept | - | ||||||||||||
460 | { | - | ||||||||||||
461 | QtPrivate::QHashCombine hash; | - | ||||||||||||
462 | seed = hash(key.m11(), seed); | - | ||||||||||||
463 | seed = hash(key.m12(), seed); | - | ||||||||||||
464 | seed = hash(key.m21(), seed); | - | ||||||||||||
465 | seed = hash(key.m22(), seed); | - | ||||||||||||
466 | seed = hash(key.dx(), seed); | - | ||||||||||||
467 | seed = hash(key.dy(), seed); | - | ||||||||||||
468 | seed = hash(key.m13(), seed); | - | ||||||||||||
469 | seed = hash(key.m23(), seed); | - | ||||||||||||
470 | seed = hash(key.m33(), seed); | - | ||||||||||||
471 | return never executed: seed;return seed; never executed: return seed; | 0 | ||||||||||||
472 | } | - | ||||||||||||
473 | - | |||||||||||||
474 | - | |||||||||||||
475 | - | |||||||||||||
476 | - | |||||||||||||
477 | - | |||||||||||||
478 | - | |||||||||||||
479 | - | |||||||||||||
480 | bool QTransform::operator!=(const QTransform &o) const | - | ||||||||||||
481 | { | - | ||||||||||||
482 | return !operator==(o); | - | ||||||||||||
483 | } | - | ||||||||||||
484 | QTransform & QTransform::operator*=(const QTransform &o) | - | ||||||||||||
485 | { | - | ||||||||||||
486 | const TransformationType otherType = o.inline_type(); | - | ||||||||||||
487 | if (otherType == TxNone) | - | ||||||||||||
488 | return *this; | - | ||||||||||||
489 | - | |||||||||||||
490 | const TransformationType thisType = inline_type(); | - | ||||||||||||
491 | if (thisType == TxNone) | - | ||||||||||||
492 | return operator=(o); | - | ||||||||||||
493 | - | |||||||||||||
494 | TransformationType t = qMax(thisType, otherType); | - | ||||||||||||
495 | switch(t) { | - | ||||||||||||
496 | case TxNone: | - | ||||||||||||
497 | break; | - | ||||||||||||
498 | case TxTranslate: | - | ||||||||||||
499 | affine._dx += o.affine._dx; | - | ||||||||||||
500 | affine._dy += o.affine._dy; | - | ||||||||||||
501 | break; | - | ||||||||||||
502 | case TxScale: | - | ||||||||||||
503 | { | - | ||||||||||||
504 | qreal m11 = affine._m11*o.affine._m11; | - | ||||||||||||
505 | qreal m22 = affine._m22*o.affine._m22; | - | ||||||||||||
506 | - | |||||||||||||
507 | qreal m31 = affine._dx*o.affine._m11 + o.affine._dx; | - | ||||||||||||
508 | qreal m32 = affine._dy*o.affine._m22 + o.affine._dy; | - | ||||||||||||
509 | - | |||||||||||||
510 | affine._m11 = m11; | - | ||||||||||||
511 | affine._m22 = m22; | - | ||||||||||||
512 | affine._dx = m31; affine._dy = m32; | - | ||||||||||||
513 | break; | - | ||||||||||||
514 | } | - | ||||||||||||
515 | case TxRotate: | - | ||||||||||||
516 | case TxShear: | - | ||||||||||||
517 | { | - | ||||||||||||
518 | qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21; | - | ||||||||||||
519 | qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22; | - | ||||||||||||
520 | - | |||||||||||||
521 | qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21; | - | ||||||||||||
522 | qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22; | - | ||||||||||||
523 | - | |||||||||||||
524 | qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + o.affine._dx; | - | ||||||||||||
525 | qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + o.affine._dy; | - | ||||||||||||
526 | - | |||||||||||||
527 | affine._m11 = m11; affine._m12 = m12; | - | ||||||||||||
528 | affine._m21 = m21; affine._m22 = m22; | - | ||||||||||||
529 | affine._dx = m31; affine._dy = m32; | - | ||||||||||||
530 | break; | - | ||||||||||||
531 | } | - | ||||||||||||
532 | case TxProject: | - | ||||||||||||
533 | { | - | ||||||||||||
534 | qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21 + m_13*o.affine._dx; | - | ||||||||||||
535 | qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22 + m_13*o.affine._dy; | - | ||||||||||||
536 | qreal m13 = affine._m11*o.m_13 + affine._m12*o.m_23 + m_13*o.m_33; | - | ||||||||||||
537 | - | |||||||||||||
538 | qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21 + m_23*o.affine._dx; | - | ||||||||||||
539 | qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22 + m_23*o.affine._dy; | - | ||||||||||||
540 | qreal m23 = affine._m21*o.m_13 + affine._m22*o.m_23 + m_23*o.m_33; | - | ||||||||||||
541 | - | |||||||||||||
542 | qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + m_33*o.affine._dx; | - | ||||||||||||
543 | qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + m_33*o.affine._dy; | - | ||||||||||||
544 | qreal m33 = affine._dx*o.m_13 + affine._dy*o.m_23 + m_33*o.m_33; | - | ||||||||||||
545 | - | |||||||||||||
546 | affine._m11 = m11; affine._m12 = m12; m_13 = m13; | - | ||||||||||||
547 | affine._m21 = m21; affine._m22 = m22; m_23 = m23; | - | ||||||||||||
548 | affine._dx = m31; affine._dy = m32; m_33 = m33; | - | ||||||||||||
549 | } | - | ||||||||||||
550 | } | - | ||||||||||||
551 | - | |||||||||||||
552 | m_dirty = t; | - | ||||||||||||
553 | m_type = t; | - | ||||||||||||
554 | - | |||||||||||||
555 | return *this; | - | ||||||||||||
556 | } | - | ||||||||||||
557 | QTransform QTransform::operator*(const QTransform &m) const | - | ||||||||||||
558 | { | - | ||||||||||||
559 | const TransformationType otherType = m.inline_type(); | - | ||||||||||||
560 | if (otherType == TxNone) | - | ||||||||||||
561 | return *this; | - | ||||||||||||
562 | - | |||||||||||||
563 | const TransformationType thisType = inline_type(); | - | ||||||||||||
564 | if (thisType == TxNone) | - | ||||||||||||
565 | return m; | - | ||||||||||||
566 | - | |||||||||||||
567 | QTransform t(true); | - | ||||||||||||
568 | TransformationType type = qMax(thisType, otherType); | - | ||||||||||||
569 | switch(type) { | - | ||||||||||||
570 | case TxNone: | - | ||||||||||||
571 | break; | - | ||||||||||||
572 | case TxTranslate: | - | ||||||||||||
573 | t.affine._dx = affine._dx + m.affine._dx; | - | ||||||||||||
574 | t.affine._dy += affine._dy + m.affine._dy; | - | ||||||||||||
575 | break; | - | ||||||||||||
576 | case TxScale: | - | ||||||||||||
577 | { | - | ||||||||||||
578 | qreal m11 = affine._m11*m.affine._m11; | - | ||||||||||||
579 | qreal m22 = affine._m22*m.affine._m22; | - | ||||||||||||
580 | - | |||||||||||||
581 | qreal m31 = affine._dx*m.affine._m11 + m.affine._dx; | - | ||||||||||||
582 | qreal m32 = affine._dy*m.affine._m22 + m.affine._dy; | - | ||||||||||||
583 | - | |||||||||||||
584 | t.affine._m11 = m11; | - | ||||||||||||
585 | t.affine._m22 = m22; | - | ||||||||||||
586 | t.affine._dx = m31; t.affine._dy = m32; | - | ||||||||||||
587 | break; | - | ||||||||||||
588 | } | - | ||||||||||||
589 | case TxRotate: | - | ||||||||||||
590 | case TxShear: | - | ||||||||||||
591 | { | - | ||||||||||||
592 | qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21; | - | ||||||||||||
593 | qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22; | - | ||||||||||||
594 | - | |||||||||||||
595 | qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21; | - | ||||||||||||
596 | qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22; | - | ||||||||||||
597 | - | |||||||||||||
598 | qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m.affine._dx; | - | ||||||||||||
599 | qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m.affine._dy; | - | ||||||||||||
600 | - | |||||||||||||
601 | t.affine._m11 = m11; t.affine._m12 = m12; | - | ||||||||||||
602 | t.affine._m21 = m21; t.affine._m22 = m22; | - | ||||||||||||
603 | t.affine._dx = m31; t.affine._dy = m32; | - | ||||||||||||
604 | break; | - | ||||||||||||
605 | } | - | ||||||||||||
606 | case TxProject: | - | ||||||||||||
607 | { | - | ||||||||||||
608 | qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21 + m_13*m.affine._dx; | - | ||||||||||||
609 | qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22 + m_13*m.affine._dy; | - | ||||||||||||
610 | qreal m13 = affine._m11*m.m_13 + affine._m12*m.m_23 + m_13*m.m_33; | - | ||||||||||||
611 | - | |||||||||||||
612 | qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21 + m_23*m.affine._dx; | - | ||||||||||||
613 | qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22 + m_23*m.affine._dy; | - | ||||||||||||
614 | qreal m23 = affine._m21*m.m_13 + affine._m22*m.m_23 + m_23*m.m_33; | - | ||||||||||||
615 | - | |||||||||||||
616 | qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m_33*m.affine._dx; | - | ||||||||||||
617 | qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m_33*m.affine._dy; | - | ||||||||||||
618 | qreal m33 = affine._dx*m.m_13 + affine._dy*m.m_23 + m_33*m.m_33; | - | ||||||||||||
619 | - | |||||||||||||
620 | t.affine._m11 = m11; t.affine._m12 = m12; t.m_13 = m13; | - | ||||||||||||
621 | t.affine._m21 = m21; t.affine._m22 = m22; t.m_23 = m23; | - | ||||||||||||
622 | t.affine._dx = m31; t.affine._dy = m32; t.m_33 = m33; | - | ||||||||||||
623 | } | - | ||||||||||||
624 | } | - | ||||||||||||
625 | - | |||||||||||||
626 | t.m_dirty = type; | - | ||||||||||||
627 | t.m_type = type; | - | ||||||||||||
628 | - | |||||||||||||
629 | return t; | - | ||||||||||||
630 | } | - | ||||||||||||
631 | QTransform & QTransform::operator=(const QTransform &matrix) noexcept | - | ||||||||||||
632 | { | - | ||||||||||||
633 | affine._m11 = matrix.affine._m11; | - | ||||||||||||
634 | affine._m12 = matrix.affine._m12; | - | ||||||||||||
635 | affine._m21 = matrix.affine._m21; | - | ||||||||||||
636 | affine._m22 = matrix.affine._m22; | - | ||||||||||||
637 | affine._dx = matrix.affine._dx; | - | ||||||||||||
638 | affine._dy = matrix.affine._dy; | - | ||||||||||||
639 | m_13 = matrix.m_13; | - | ||||||||||||
640 | m_23 = matrix.m_23; | - | ||||||||||||
641 | m_33 = matrix.m_33; | - | ||||||||||||
642 | m_type = matrix.m_type; | - | ||||||||||||
643 | m_dirty = matrix.m_dirty; | - | ||||||||||||
644 | - | |||||||||||||
645 | return never executed: *this;return *this; never executed: return *this; | 0 | ||||||||||||
646 | } | - | ||||||||||||
647 | void QTransform::reset() | - | ||||||||||||
648 | { | - | ||||||||||||
649 | affine._m11 = affine._m22 = m_33 = 1.0; | - | ||||||||||||
650 | affine._m12 = m_13 = affine._m21 = m_23 = affine._dx = affine._dy = 0; | - | ||||||||||||
651 | m_type = TxNone; | - | ||||||||||||
652 | m_dirty = TxNone; | - | ||||||||||||
653 | } | - | ||||||||||||
654 | QDataStream & operator<<(QDataStream &s, const QTransform &m) | - | ||||||||||||
655 | { | - | ||||||||||||
656 | s << double(m.m11()) | - | ||||||||||||
657 | << double(m.m12()) | - | ||||||||||||
658 | << double(m.m13()) | - | ||||||||||||
659 | << double(m.m21()) | - | ||||||||||||
660 | << double(m.m22()) | - | ||||||||||||
661 | << double(m.m23()) | - | ||||||||||||
662 | << double(m.m31()) | - | ||||||||||||
663 | << double(m.m32()) | - | ||||||||||||
664 | << double(m.m33()); | - | ||||||||||||
665 | return s; | - | ||||||||||||
666 | } | - | ||||||||||||
667 | QDataStream & operator>>(QDataStream &s, QTransform &t) | - | ||||||||||||
668 | { | - | ||||||||||||
669 | double m11, m12, m13, | - | ||||||||||||
670 | m21, m22, m23, | - | ||||||||||||
671 | m31, m32, m33; | - | ||||||||||||
672 | - | |||||||||||||
673 | s >> m11; | - | ||||||||||||
674 | s >> m12; | - | ||||||||||||
675 | s >> m13; | - | ||||||||||||
676 | s >> m21; | - | ||||||||||||
677 | s >> m22; | - | ||||||||||||
678 | s >> m23; | - | ||||||||||||
679 | s >> m31; | - | ||||||||||||
680 | s >> m32; | - | ||||||||||||
681 | s >> m33; | - | ||||||||||||
682 | t.setMatrix(m11, m12, m13, | - | ||||||||||||
683 | m21, m22, m23, | - | ||||||||||||
684 | m31, m32, m33); | - | ||||||||||||
685 | return s; | - | ||||||||||||
686 | } | - | ||||||||||||
687 | - | |||||||||||||
688 | - | |||||||||||||
689 | - | |||||||||||||
690 | - | |||||||||||||
691 | QDebug operator<<(QDebug dbg, const QTransform &m) | - | ||||||||||||
692 | { | - | ||||||||||||
693 | static const char *const typeStr[] = | - | ||||||||||||
694 | { | - | ||||||||||||
695 | "TxNone", | - | ||||||||||||
696 | "TxTranslate", | - | ||||||||||||
697 | "TxScale", | - | ||||||||||||
698 | 0, | - | ||||||||||||
699 | "TxRotate", | - | ||||||||||||
700 | 0, 0, 0, | - | ||||||||||||
701 | "TxShear", | - | ||||||||||||
702 | 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||
703 | "TxProject" | - | ||||||||||||
704 | }; | - | ||||||||||||
705 | - | |||||||||||||
706 | QDebugStateSaver saver(dbg); | - | ||||||||||||
707 | dbg.nospace() << "QTransform(type=" << typeStr[m.type()] << ',' | - | ||||||||||||
708 | << " 11=" << m.m11() | - | ||||||||||||
709 | << " 12=" << m.m12() | - | ||||||||||||
710 | << " 13=" << m.m13() | - | ||||||||||||
711 | << " 21=" << m.m21() | - | ||||||||||||
712 | << " 22=" << m.m22() | - | ||||||||||||
713 | << " 23=" << m.m23() | - | ||||||||||||
714 | << " 31=" << m.m31() | - | ||||||||||||
715 | << " 32=" << m.m32() | - | ||||||||||||
716 | << " 33=" << m.m33() | - | ||||||||||||
717 | << ')'; | - | ||||||||||||
718 | - | |||||||||||||
719 | return dbg; | - | ||||||||||||
720 | } | - | ||||||||||||
721 | QPoint QTransform::map(const QPoint &p) const | - | ||||||||||||
722 | { | - | ||||||||||||
723 | qreal fx = p.x(); | - | ||||||||||||
724 | qreal fy = p.y(); | - | ||||||||||||
725 | - | |||||||||||||
726 | qreal x = 0, y = 0; | - | ||||||||||||
727 | - | |||||||||||||
728 | TransformationType t = inline_type(); | - | ||||||||||||
729 | switch(t) { | - | ||||||||||||
730 | case TxNone: | - | ||||||||||||
731 | x = fx; | - | ||||||||||||
732 | y = fy; | - | ||||||||||||
733 | break; | - | ||||||||||||
734 | case TxTranslate: | - | ||||||||||||
735 | x = fx + affine._dx; | - | ||||||||||||
736 | y = fy + affine._dy; | - | ||||||||||||
737 | break; | - | ||||||||||||
738 | case TxScale: | - | ||||||||||||
739 | x = affine._m11 * fx + affine._dx; | - | ||||||||||||
740 | y = affine._m22 * fy + affine._dy; | - | ||||||||||||
741 | break; | - | ||||||||||||
742 | case TxRotate: | - | ||||||||||||
743 | case TxShear: | - | ||||||||||||
744 | case TxProject: | - | ||||||||||||
745 | x = affine._m11 * fx + affine._m21 * fy + affine._dx; | - | ||||||||||||
746 | y = affine._m12 * fx + affine._m22 * fy + affine._dy; | - | ||||||||||||
747 | if (t == TxProject) { | - | ||||||||||||
748 | qreal w = 1./(m_13 * fx + m_23 * fy + m_33); | - | ||||||||||||
749 | x *= w; | - | ||||||||||||
750 | y *= w; | - | ||||||||||||
751 | } | - | ||||||||||||
752 | } | - | ||||||||||||
753 | return QPoint(qRound(x), qRound(y)); | - | ||||||||||||
754 | } | - | ||||||||||||
755 | QPointF QTransform::map(const QPointF &p) const | - | ||||||||||||
756 | { | - | ||||||||||||
757 | qreal fx = p.x(); | - | ||||||||||||
758 | qreal fy = p.y(); | - | ||||||||||||
759 | - | |||||||||||||
760 | qreal x = 0, y = 0; | - | ||||||||||||
761 | - | |||||||||||||
762 | TransformationType t = inline_type(); | - | ||||||||||||
763 | switch(t) { | - | ||||||||||||
764 | case TxNone: | - | ||||||||||||
765 | x = fx; | - | ||||||||||||
766 | y = fy; | - | ||||||||||||
767 | break; | - | ||||||||||||
768 | case TxTranslate: | - | ||||||||||||
769 | x = fx + affine._dx; | - | ||||||||||||
770 | y = fy + affine._dy; | - | ||||||||||||
771 | break; | - | ||||||||||||
772 | case TxScale: | - | ||||||||||||
773 | x = affine._m11 * fx + affine._dx; | - | ||||||||||||
774 | y = affine._m22 * fy + affine._dy; | - | ||||||||||||
775 | break; | - | ||||||||||||
776 | case TxRotate: | - | ||||||||||||
777 | case TxShear: | - | ||||||||||||
778 | case TxProject: | - | ||||||||||||
779 | x = affine._m11 * fx + affine._m21 * fy + affine._dx; | - | ||||||||||||
780 | y = affine._m12 * fx + affine._m22 * fy + affine._dy; | - | ||||||||||||
781 | if (t == TxProject) { | - | ||||||||||||
782 | qreal w = 1./(m_13 * fx + m_23 * fy + m_33); | - | ||||||||||||
783 | x *= w; | - | ||||||||||||
784 | y *= w; | - | ||||||||||||
785 | } | - | ||||||||||||
786 | } | - | ||||||||||||
787 | return QPointF(x, y); | - | ||||||||||||
788 | } | - | ||||||||||||
789 | QLine QTransform::map(const QLine &l) const | - | ||||||||||||
790 | { | - | ||||||||||||
791 | qreal fx1 = l.x1(); | - | ||||||||||||
792 | qreal fy1 = l.y1(); | - | ||||||||||||
793 | qreal fx2 = l.x2(); | - | ||||||||||||
794 | qreal fy2 = l.y2(); | - | ||||||||||||
795 | - | |||||||||||||
796 | qreal x1 = 0, y1 = 0, x2 = 0, y2 = 0; | - | ||||||||||||
797 | - | |||||||||||||
798 | TransformationType t = inline_type(); | - | ||||||||||||
799 | switch(t) { | - | ||||||||||||
800 | case TxNone: | - | ||||||||||||
801 | x1 = fx1; | - | ||||||||||||
802 | y1 = fy1; | - | ||||||||||||
803 | x2 = fx2; | - | ||||||||||||
804 | y2 = fy2; | - | ||||||||||||
805 | break; | - | ||||||||||||
806 | case TxTranslate: | - | ||||||||||||
807 | x1 = fx1 + affine._dx; | - | ||||||||||||
808 | y1 = fy1 + affine._dy; | - | ||||||||||||
809 | x2 = fx2 + affine._dx; | - | ||||||||||||
810 | y2 = fy2 + affine._dy; | - | ||||||||||||
811 | break; | - | ||||||||||||
812 | case TxScale: | - | ||||||||||||
813 | x1 = affine._m11 * fx1 + affine._dx; | - | ||||||||||||
814 | y1 = affine._m22 * fy1 + affine._dy; | - | ||||||||||||
815 | x2 = affine._m11 * fx2 + affine._dx; | - | ||||||||||||
816 | y2 = affine._m22 * fy2 + affine._dy; | - | ||||||||||||
817 | break; | - | ||||||||||||
818 | case TxRotate: | - | ||||||||||||
819 | case TxShear: | - | ||||||||||||
820 | case TxProject: | - | ||||||||||||
821 | x1 = affine._m11 * fx1 + affine._m21 * fy1 + affine._dx; | - | ||||||||||||
822 | y1 = affine._m12 * fx1 + affine._m22 * fy1 + affine._dy; | - | ||||||||||||
823 | x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx; | - | ||||||||||||
824 | y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy; | - | ||||||||||||
825 | if (t == TxProject) { | - | ||||||||||||
826 | qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33); | - | ||||||||||||
827 | x1 *= w; | - | ||||||||||||
828 | y1 *= w; | - | ||||||||||||
829 | w = 1./(m_13 * fx2 + m_23 * fy2 + m_33); | - | ||||||||||||
830 | x2 *= w; | - | ||||||||||||
831 | y2 *= w; | - | ||||||||||||
832 | } | - | ||||||||||||
833 | } | - | ||||||||||||
834 | return QLine(qRound(x1), qRound(y1), qRound(x2), qRound(y2)); | - | ||||||||||||
835 | } | - | ||||||||||||
836 | QLineF QTransform::map(const QLineF &l) const | - | ||||||||||||
837 | { | - | ||||||||||||
838 | qreal fx1 = l.x1(); | - | ||||||||||||
839 | qreal fy1 = l.y1(); | - | ||||||||||||
840 | qreal fx2 = l.x2(); | - | ||||||||||||
841 | qreal fy2 = l.y2(); | - | ||||||||||||
842 | - | |||||||||||||
843 | qreal x1 = 0, y1 = 0, x2 = 0, y2 = 0; | - | ||||||||||||
844 | - | |||||||||||||
845 | TransformationType t = inline_type(); | - | ||||||||||||
846 | switch(t) { | - | ||||||||||||
847 | case TxNone: | - | ||||||||||||
848 | x1 = fx1; | - | ||||||||||||
849 | y1 = fy1; | - | ||||||||||||
850 | x2 = fx2; | - | ||||||||||||
851 | y2 = fy2; | - | ||||||||||||
852 | break; | - | ||||||||||||
853 | case TxTranslate: | - | ||||||||||||
854 | x1 = fx1 + affine._dx; | - | ||||||||||||
855 | y1 = fy1 + affine._dy; | - | ||||||||||||
856 | x2 = fx2 + affine._dx; | - | ||||||||||||
857 | y2 = fy2 + affine._dy; | - | ||||||||||||
858 | break; | - | ||||||||||||
859 | case TxScale: | - | ||||||||||||
860 | x1 = affine._m11 * fx1 + affine._dx; | - | ||||||||||||
861 | y1 = affine._m22 * fy1 + affine._dy; | - | ||||||||||||
862 | x2 = affine._m11 * fx2 + affine._dx; | - | ||||||||||||
863 | y2 = affine._m22 * fy2 + affine._dy; | - | ||||||||||||
864 | break; | - | ||||||||||||
865 | case TxRotate: | - | ||||||||||||
866 | case TxShear: | - | ||||||||||||
867 | case TxProject: | - | ||||||||||||
868 | x1 = affine._m11 * fx1 + affine._m21 * fy1 + affine._dx; | - | ||||||||||||
869 | y1 = affine._m12 * fx1 + affine._m22 * fy1 + affine._dy; | - | ||||||||||||
870 | x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx; | - | ||||||||||||
871 | y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy; | - | ||||||||||||
872 | if (t == TxProject) { | - | ||||||||||||
873 | qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33); | - | ||||||||||||
874 | x1 *= w; | - | ||||||||||||
875 | y1 *= w; | - | ||||||||||||
876 | w = 1./(m_13 * fx2 + m_23 * fy2 + m_33); | - | ||||||||||||
877 | x2 *= w; | - | ||||||||||||
878 | y2 *= w; | - | ||||||||||||
879 | } | - | ||||||||||||
880 | } | - | ||||||||||||
881 | return QLineF(x1, y1, x2, y2); | - | ||||||||||||
882 | } | - | ||||||||||||
883 | - | |||||||||||||
884 | static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &poly) | - | ||||||||||||
885 | { | - | ||||||||||||
886 | if (poly.size() == 0) | - | ||||||||||||
887 | return poly; | - | ||||||||||||
888 | - | |||||||||||||
889 | if (poly.size() == 1) | - | ||||||||||||
890 | return QPolygonF() << transform.map(poly.at(0)); | - | ||||||||||||
891 | - | |||||||||||||
892 | QPainterPath path; | - | ||||||||||||
893 | path.addPolygon(poly); | - | ||||||||||||
894 | - | |||||||||||||
895 | path = transform.map(path); | - | ||||||||||||
896 | - | |||||||||||||
897 | QPolygonF result; | - | ||||||||||||
898 | const int elementCount = path.elementCount(); | - | ||||||||||||
899 | result.reserve(elementCount); | - | ||||||||||||
900 | for (int i = 0; i < elementCount; ++i) | - | ||||||||||||
901 | result << path.elementAt(i); | - | ||||||||||||
902 | return result; | - | ||||||||||||
903 | } | - | ||||||||||||
904 | QPolygonF QTransform::map(const QPolygonF &a) const | - | ||||||||||||
905 | { | - | ||||||||||||
906 | TransformationType t = inline_type(); | - | ||||||||||||
907 | if (t <= TxTranslate) | - | ||||||||||||
908 | return a.translated(affine._dx, affine._dy); | - | ||||||||||||
909 | - | |||||||||||||
910 | if (t >= QTransform::TxProject) | - | ||||||||||||
911 | return mapProjective(*this, a); | - | ||||||||||||
912 | - | |||||||||||||
913 | int size = a.size(); | - | ||||||||||||
914 | int i; | - | ||||||||||||
915 | QPolygonF p(size); | - | ||||||||||||
916 | const QPointF *da = a.constData(); | - | ||||||||||||
917 | QPointF *dp = p.data(); | - | ||||||||||||
918 | - | |||||||||||||
919 | for(i = 0; i < size; ++i) { | - | ||||||||||||
920 | do { qreal FX_ = da[i].xp; qreal FY_ = da[i].yp; switch(t) { case TxNone: dp[i].xp = FX_; dp[i].yp = FY_; break; case TxTranslate: dp[i].xp = FX_ + affine._dx; dp[i].yp = FY_ + affine._dy; break; case TxScale: dp[i].xp = affine._m11 * FX_ + affine._dx; dp[i].yp = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: dp[i].xp = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; dp[i].yp = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; dp[i].xp *= w; dp[i].yp *= w; } } } while (0); | - | ||||||||||||
921 | } | - | ||||||||||||
922 | return p; | - | ||||||||||||
923 | } | - | ||||||||||||
924 | QPolygon QTransform::map(const QPolygon &a) const | - | ||||||||||||
925 | { | - | ||||||||||||
926 | TransformationType t = inline_type(); | - | ||||||||||||
927 | if (t <= TxTranslate) | - | ||||||||||||
928 | return a.translated(qRound(affine._dx), qRound(affine._dy)); | - | ||||||||||||
929 | - | |||||||||||||
930 | if (t >= QTransform::TxProject) | - | ||||||||||||
931 | return mapProjective(*this, QPolygonF(a)).toPolygon(); | - | ||||||||||||
932 | - | |||||||||||||
933 | int size = a.size(); | - | ||||||||||||
934 | int i; | - | ||||||||||||
935 | QPolygon p(size); | - | ||||||||||||
936 | const QPoint *da = a.constData(); | - | ||||||||||||
937 | QPoint *dp = p.data(); | - | ||||||||||||
938 | - | |||||||||||||
939 | for(i = 0; i < size; ++i) { | - | ||||||||||||
940 | qreal nx = 0, ny = 0; | - | ||||||||||||
941 | do { qreal FX_ = da[i].xp; qreal FY_ = da[i].yp; switch(t) { case TxNone: nx = FX_; ny = FY_; break; case TxTranslate: nx = FX_ + affine._dx; ny = FY_ + affine._dy; break; case TxScale: nx = affine._m11 * FX_ + affine._dx; ny = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: nx = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; ny = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; nx *= w; ny *= w; } } } while (0); | - | ||||||||||||
942 | dp[i].xp = qRound(nx); | - | ||||||||||||
943 | dp[i].yp = qRound(ny); | - | ||||||||||||
944 | } | - | ||||||||||||
945 | return p; | - | ||||||||||||
946 | } | - | ||||||||||||
947 | extern QPainterPath qt_regionToPath(const QRegion ®ion); | - | ||||||||||||
948 | QRegion QTransform::map(const QRegion &r) const | - | ||||||||||||
949 | { | - | ||||||||||||
950 | TransformationType t = inline_type(); | - | ||||||||||||
951 | if (t == TxNone) | - | ||||||||||||
952 | return r; | - | ||||||||||||
953 | - | |||||||||||||
954 | if (t == TxTranslate) { | - | ||||||||||||
955 | QRegion copy(r); | - | ||||||||||||
956 | copy.translate(qRound(affine._dx), qRound(affine._dy)); | - | ||||||||||||
957 | return copy; | - | ||||||||||||
958 | } | - | ||||||||||||
959 | - | |||||||||||||
960 | if (t == TxScale && r.rectCount() == 1) | - | ||||||||||||
961 | return QRegion(mapRect(r.boundingRect())); | - | ||||||||||||
962 | - | |||||||||||||
963 | QPainterPath p = map(qt_regionToPath(r)); | - | ||||||||||||
964 | return p.toFillPolygon(QTransform()).toPolygon(); | - | ||||||||||||
965 | } | - | ||||||||||||
966 | - | |||||||||||||
967 | struct QHomogeneousCoordinate | - | ||||||||||||
968 | { | - | ||||||||||||
969 | qreal x; | - | ||||||||||||
970 | qreal y; | - | ||||||||||||
971 | qreal w; | - | ||||||||||||
972 | - | |||||||||||||
973 | QHomogeneousCoordinate() {} | - | ||||||||||||
974 | QHomogeneousCoordinate(qreal x_, qreal y_, qreal w_) : x(x_), y(y_), w(w_) {} | - | ||||||||||||
975 | - | |||||||||||||
976 | const QPointF toPoint() const { | - | ||||||||||||
977 | qreal iw = 1. / w; | - | ||||||||||||
978 | return QPointF(x * iw, y * iw); | - | ||||||||||||
979 | } | - | ||||||||||||
980 | }; | - | ||||||||||||
981 | - | |||||||||||||
982 | static inline QHomogeneousCoordinate mapHomogeneous(const QTransform &transform, const QPointF &p) | - | ||||||||||||
983 | { | - | ||||||||||||
984 | QHomogeneousCoordinate c; | - | ||||||||||||
985 | c.x = transform.m11() * p.x() + transform.m21() * p.y() + transform.m31(); | - | ||||||||||||
986 | c.y = transform.m12() * p.x() + transform.m22() * p.y() + transform.m32(); | - | ||||||||||||
987 | c.w = transform.m13() * p.x() + transform.m23() * p.y() + transform.m33(); | - | ||||||||||||
988 | return c; | - | ||||||||||||
989 | } | - | ||||||||||||
990 | - | |||||||||||||
991 | static inline bool lineTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, | - | ||||||||||||
992 | bool needsMoveTo, bool needsLineTo = true) | - | ||||||||||||
993 | { | - | ||||||||||||
994 | QHomogeneousCoordinate ha = mapHomogeneous(transform, a); | - | ||||||||||||
995 | QHomogeneousCoordinate hb = mapHomogeneous(transform, b); | - | ||||||||||||
996 | - | |||||||||||||
997 | if (ha.w < (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001) && hb.w < (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)) | - | ||||||||||||
998 | return false; | - | ||||||||||||
999 | - | |||||||||||||
1000 | if (hb.w < (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)) { | - | ||||||||||||
1001 | const qreal t = ((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001) - hb.w) / (ha.w - hb.w); | - | ||||||||||||
1002 | - | |||||||||||||
1003 | hb.x += (ha.x - hb.x) * t; | - | ||||||||||||
1004 | hb.y += (ha.y - hb.y) * t; | - | ||||||||||||
1005 | hb.w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); | - | ||||||||||||
1006 | } else if (ha.w < (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)) { | - | ||||||||||||
1007 | const qreal t = ((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001) - ha.w) / (hb.w - ha.w); | - | ||||||||||||
1008 | - | |||||||||||||
1009 | ha.x += (hb.x - ha.x) * t; | - | ||||||||||||
1010 | ha.y += (hb.y - ha.y) * t; | - | ||||||||||||
1011 | ha.w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); | - | ||||||||||||
1012 | - | |||||||||||||
1013 | const QPointF p = ha.toPoint(); | - | ||||||||||||
1014 | if (needsMoveTo) { | - | ||||||||||||
1015 | path.moveTo(p); | - | ||||||||||||
1016 | needsMoveTo = false; | - | ||||||||||||
1017 | } else { | - | ||||||||||||
1018 | path.lineTo(p); | - | ||||||||||||
1019 | } | - | ||||||||||||
1020 | } | - | ||||||||||||
1021 | - | |||||||||||||
1022 | if (needsMoveTo) | - | ||||||||||||
1023 | path.moveTo(ha.toPoint()); | - | ||||||||||||
1024 | - | |||||||||||||
1025 | if (needsLineTo) | - | ||||||||||||
1026 | path.lineTo(hb.toPoint()); | - | ||||||||||||
1027 | - | |||||||||||||
1028 | return true; | - | ||||||||||||
1029 | } | - | ||||||||||||
1030 | __attribute__((visibility("default"))) bool qt_scaleForTransform(const QTransform &transform, qreal *scale); | - | ||||||||||||
1031 | - | |||||||||||||
1032 | static inline bool cubicTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, bool needsMoveTo) | - | ||||||||||||
1033 | { | - | ||||||||||||
1034 | - | |||||||||||||
1035 | - | |||||||||||||
1036 | - | |||||||||||||
1037 | qreal scale; | - | ||||||||||||
1038 | qt_scaleForTransform(transform, &scale); | - | ||||||||||||
1039 | - | |||||||||||||
1040 | qreal curveThreshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale); | - | ||||||||||||
1041 | - | |||||||||||||
1042 | QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon(curveThreshold); | - | ||||||||||||
1043 | - | |||||||||||||
1044 | for (int i = 0; i < segment.size() - 1; ++i) | - | ||||||||||||
1045 | if (lineTo_clipped(path, transform, segment.at(i), segment.at(i+1), needsMoveTo)) | - | ||||||||||||
1046 | needsMoveTo = false; | - | ||||||||||||
1047 | - | |||||||||||||
1048 | return !needsMoveTo; | - | ||||||||||||
1049 | } | - | ||||||||||||
1050 | - | |||||||||||||
1051 | static QPainterPath mapProjective(const QTransform &transform, const QPainterPath &path) | - | ||||||||||||
1052 | { | - | ||||||||||||
1053 | QPainterPath result; | - | ||||||||||||
1054 | - | |||||||||||||
1055 | QPointF last; | - | ||||||||||||
1056 | QPointF lastMoveTo; | - | ||||||||||||
1057 | bool needsMoveTo = true; | - | ||||||||||||
1058 | for (int i = 0; i < path.elementCount(); ++i) { | - | ||||||||||||
1059 | switch (path.elementAt(i).type) { | - | ||||||||||||
1060 | case QPainterPath::MoveToElement: | - | ||||||||||||
1061 | if (i > 0 && lastMoveTo != last) | - | ||||||||||||
1062 | lineTo_clipped(result, transform, last, lastMoveTo, needsMoveTo); | - | ||||||||||||
1063 | - | |||||||||||||
1064 | lastMoveTo = path.elementAt(i); | - | ||||||||||||
1065 | last = path.elementAt(i); | - | ||||||||||||
1066 | needsMoveTo = true; | - | ||||||||||||
1067 | break; | - | ||||||||||||
1068 | case QPainterPath::LineToElement: | - | ||||||||||||
1069 | if (lineTo_clipped(result, transform, last, path.elementAt(i), needsMoveTo)) | - | ||||||||||||
1070 | needsMoveTo = false; | - | ||||||||||||
1071 | last = path.elementAt(i); | - | ||||||||||||
1072 | break; | - | ||||||||||||
1073 | case QPainterPath::CurveToElement: | - | ||||||||||||
1074 | if (cubicTo_clipped(result, transform, last, path.elementAt(i), path.elementAt(i+1), path.elementAt(i+2), needsMoveTo)) | - | ||||||||||||
1075 | needsMoveTo = false; | - | ||||||||||||
1076 | i += 2; | - | ||||||||||||
1077 | last = path.elementAt(i); | - | ||||||||||||
1078 | break; | - | ||||||||||||
1079 | default: | - | ||||||||||||
1080 | ((!(false)) ? qt_assert("false",__FILE__,16261642) : qt_noop()); | - | ||||||||||||
1081 | } | - | ||||||||||||
1082 | } | - | ||||||||||||
1083 | - | |||||||||||||
1084 | if (path.elementCount() > 0 && lastMoveTo != last) | - | ||||||||||||
1085 | lineTo_clipped(result, transform, last, lastMoveTo, needsMoveTo, false); | - | ||||||||||||
1086 | - | |||||||||||||
1087 | result.setFillRule(path.fillRule()); | - | ||||||||||||
1088 | return result; | - | ||||||||||||
1089 | } | - | ||||||||||||
1090 | QPainterPath QTransform::map(const QPainterPath &path) const | - | ||||||||||||
1091 | { | - | ||||||||||||
1092 | TransformationType t = inline_type(); | - | ||||||||||||
1093 | if (t == TxNone || path.elementCount() == 0) | - | ||||||||||||
1094 | return path; | - | ||||||||||||
1095 | - | |||||||||||||
1096 | if (t >= TxProject) | - | ||||||||||||
1097 | return mapProjective(*this, path); | - | ||||||||||||
1098 | - | |||||||||||||
1099 | QPainterPath copy = path; | - | ||||||||||||
1100 | - | |||||||||||||
1101 | if (t == TxTranslate) { | - | ||||||||||||
1102 | copy.translate(affine._dx, affine._dy); | - | ||||||||||||
1103 | } else { | - | ||||||||||||
1104 | copy.detach(); | - | ||||||||||||
1105 | - | |||||||||||||
1106 | for (int i=0; i<path.elementCount(); ++i) { | - | ||||||||||||
1107 | QPainterPath::Element &e = copy.d_ptr->elements[i]; | - | ||||||||||||
1108 | do { qreal FX_ = e.x; qreal FY_ = e.y; switch(t) { case TxNone: e.x = FX_; e.y = FY_; break; case TxTranslate: e.x = FX_ + affine._dx; e.y = FY_ + affine._dy; break; case TxScale: e.x = affine._m11 * FX_ + affine._dx; e.y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: e.x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; e.y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; e.x *= w; e.y *= w; } } } while (0); | - | ||||||||||||
1109 | } | - | ||||||||||||
1110 | } | - | ||||||||||||
1111 | - | |||||||||||||
1112 | return copy; | - | ||||||||||||
1113 | } | - | ||||||||||||
1114 | QPolygon QTransform::mapToPolygon(const QRect &rect) const | - | ||||||||||||
1115 | { | - | ||||||||||||
1116 | TransformationType t = inline_type(); | - | ||||||||||||
1117 | - | |||||||||||||
1118 | QPolygon a(4); | - | ||||||||||||
1119 | qreal x[4] = { 0, 0, 0, 0 }, y[4] = { 0, 0, 0, 0 }; | - | ||||||||||||
1120 | if (t <= TxScale) { | - | ||||||||||||
1121 | x[0] = affine._m11*rect.x() + affine._dx; | - | ||||||||||||
1122 | y[0] = affine._m22*rect.y() + affine._dy; | - | ||||||||||||
1123 | qreal w = affine._m11*rect.width(); | - | ||||||||||||
1124 | qreal h = affine._m22*rect.height(); | - | ||||||||||||
1125 | if (w < 0) { | - | ||||||||||||
1126 | w = -w; | - | ||||||||||||
1127 | x[0] -= w; | - | ||||||||||||
1128 | } | - | ||||||||||||
1129 | if (h < 0) { | - | ||||||||||||
1130 | h = -h; | - | ||||||||||||
1131 | y[0] -= h; | - | ||||||||||||
1132 | } | - | ||||||||||||
1133 | x[1] = x[0]+w; | - | ||||||||||||
1134 | x[2] = x[1]; | - | ||||||||||||
1135 | x[3] = x[0]; | - | ||||||||||||
1136 | y[1] = y[0]; | - | ||||||||||||
1137 | y[2] = y[0]+h; | - | ||||||||||||
1138 | y[3] = y[2]; | - | ||||||||||||
1139 | } else { | - | ||||||||||||
1140 | qreal right = rect.x() + rect.width(); | - | ||||||||||||
1141 | qreal bottom = rect.y() + rect.height(); | - | ||||||||||||
1142 | do { qreal FX_ = rect.x(); qreal FY_ = rect.y(); switch(t) { case TxNone: x[0] = FX_; y[0] = FY_; break; case TxTranslate: x[0] = FX_ + affine._dx; y[0] = FY_ + affine._dy; break; case TxScale: x[0] = affine._m11 * FX_ + affine._dx; y[0] = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x[0] = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y[0] = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x[0] *= w; y[0] *= w; } } } while (0); | - | ||||||||||||
1143 | do { qreal FX_ = right; qreal FY_ = rect.y(); switch(t) { case TxNone: x[1] = FX_; y[1] = FY_; break; case TxTranslate: x[1] = FX_ + affine._dx; y[1] = FY_ + affine._dy; break; case TxScale: x[1] = affine._m11 * FX_ + affine._dx; y[1] = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x[1] = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y[1] = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x[1] *= w; y[1] *= w; } } } while (0); | - | ||||||||||||
1144 | do { qreal FX_ = right; qreal FY_ = bottom; switch(t) { case TxNone: x[2] = FX_; y[2] = FY_; break; case TxTranslate: x[2] = FX_ + affine._dx; y[2] = FY_ + affine._dy; break; case TxScale: x[2] = affine._m11 * FX_ + affine._dx; y[2] = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x[2] = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y[2] = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x[2] *= w; y[2] *= w; } } } while (0); | - | ||||||||||||
1145 | do { qreal FX_ = rect.x(); qreal FY_ = bottom; switch(t) { case TxNone: x[3] = FX_; y[3] = FY_; break; case TxTranslate: x[3] = FX_ + affine._dx; y[3] = FY_ + affine._dy; break; case TxScale: x[3] = affine._m11 * FX_ + affine._dx; y[3] = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x[3] = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y[3] = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x[3] *= w; y[3] *= w; } } } while (0); | - | ||||||||||||
1146 | } | - | ||||||||||||
1147 | - | |||||||||||||
1148 | - | |||||||||||||
1149 | - | |||||||||||||
1150 | a.setPoints(4, qRound(x[0]), qRound(y[0]), | - | ||||||||||||
1151 | qRound(x[1]), qRound(y[1]), | - | ||||||||||||
1152 | qRound(x[2]), qRound(y[2]), | - | ||||||||||||
1153 | qRound(x[3]), qRound(y[3])); | - | ||||||||||||
1154 | return a; | - | ||||||||||||
1155 | } | - | ||||||||||||
1156 | bool QTransform::squareToQuad(const QPolygonF &quad, QTransform &trans) | - | ||||||||||||
1157 | { | - | ||||||||||||
1158 | if (quad.count() != 4) | - | ||||||||||||
1159 | return false; | - | ||||||||||||
1160 | - | |||||||||||||
1161 | qreal dx0 = quad[0].x(); | - | ||||||||||||
1162 | qreal dx1 = quad[1].x(); | - | ||||||||||||
1163 | qreal dx2 = quad[2].x(); | - | ||||||||||||
1164 | qreal dx3 = quad[3].x(); | - | ||||||||||||
1165 | - | |||||||||||||
1166 | qreal dy0 = quad[0].y(); | - | ||||||||||||
1167 | qreal dy1 = quad[1].y(); | - | ||||||||||||
1168 | qreal dy2 = quad[2].y(); | - | ||||||||||||
1169 | qreal dy3 = quad[3].y(); | - | ||||||||||||
1170 | - | |||||||||||||
1171 | double ax = dx0 - dx1 + dx2 - dx3; | - | ||||||||||||
1172 | double ay = dy0 - dy1 + dy2 - dy3; | - | ||||||||||||
1173 | - | |||||||||||||
1174 | if (!ax && !ay) { | - | ||||||||||||
1175 | trans.setMatrix(dx1 - dx0, dy1 - dy0, 0, | - | ||||||||||||
1176 | dx2 - dx1, dy2 - dy1, 0, | - | ||||||||||||
1177 | dx0, dy0, 1); | - | ||||||||||||
1178 | } else { | - | ||||||||||||
1179 | double ax1 = dx1 - dx2; | - | ||||||||||||
1180 | double ax2 = dx3 - dx2; | - | ||||||||||||
1181 | double ay1 = dy1 - dy2; | - | ||||||||||||
1182 | double ay2 = dy3 - dy2; | - | ||||||||||||
1183 | - | |||||||||||||
1184 | - | |||||||||||||
1185 | double gtop = ax * ay2 - ax2 * ay; | - | ||||||||||||
1186 | double htop = ax1 * ay - ax * ay1; | - | ||||||||||||
1187 | double bottom = ax1 * ay2 - ax2 * ay1; | - | ||||||||||||
1188 | - | |||||||||||||
1189 | double a, b, c, d, e, f, g, h; | - | ||||||||||||
1190 | - | |||||||||||||
1191 | if (!bottom) | - | ||||||||||||
1192 | return false; | - | ||||||||||||
1193 | - | |||||||||||||
1194 | g = gtop/bottom; | - | ||||||||||||
1195 | h = htop/bottom; | - | ||||||||||||
1196 | - | |||||||||||||
1197 | a = dx1 - dx0 + g * dx1; | - | ||||||||||||
1198 | b = dx3 - dx0 + h * dx3; | - | ||||||||||||
1199 | c = dx0; | - | ||||||||||||
1200 | d = dy1 - dy0 + g * dy1; | - | ||||||||||||
1201 | e = dy3 - dy0 + h * dy3; | - | ||||||||||||
1202 | f = dy0; | - | ||||||||||||
1203 | - | |||||||||||||
1204 | trans.setMatrix(a, d, g, | - | ||||||||||||
1205 | b, e, h, | - | ||||||||||||
1206 | c, f, 1.0); | - | ||||||||||||
1207 | } | - | ||||||||||||
1208 | - | |||||||||||||
1209 | return true; | - | ||||||||||||
1210 | } | - | ||||||||||||
1211 | bool QTransform::quadToSquare(const QPolygonF &quad, QTransform &trans) | - | ||||||||||||
1212 | { | - | ||||||||||||
1213 | if (!squareToQuad(quad, trans)) | - | ||||||||||||
1214 | return false; | - | ||||||||||||
1215 | - | |||||||||||||
1216 | bool invertible = false; | - | ||||||||||||
1217 | trans = trans.inverted(&invertible); | - | ||||||||||||
1218 | - | |||||||||||||
1219 | return invertible; | - | ||||||||||||
1220 | } | - | ||||||||||||
1221 | bool QTransform::quadToQuad(const QPolygonF &one, | - | ||||||||||||
1222 | const QPolygonF &two, | - | ||||||||||||
1223 | QTransform &trans) | - | ||||||||||||
1224 | { | - | ||||||||||||
1225 | QTransform stq; | - | ||||||||||||
1226 | if (!quadToSquare(one, trans)) | - | ||||||||||||
1227 | return false; | - | ||||||||||||
1228 | if (!squareToQuad(two, stq)) | - | ||||||||||||
1229 | return false; | - | ||||||||||||
1230 | trans *= stq; | - | ||||||||||||
1231 | - | |||||||||||||
1232 | return true; | - | ||||||||||||
1233 | } | - | ||||||||||||
1234 | void QTransform::setMatrix(qreal m11, qreal m12, qreal m13, | - | ||||||||||||
1235 | qreal m21, qreal m22, qreal m23, | - | ||||||||||||
1236 | qreal m31, qreal m32, qreal m33) | - | ||||||||||||
1237 | { | - | ||||||||||||
1238 | affine._m11 = m11; affine._m12 = m12; m_13 = m13; | - | ||||||||||||
1239 | affine._m21 = m21; affine._m22 = m22; m_23 = m23; | - | ||||||||||||
1240 | affine._dx = m31; affine._dy = m32; m_33 = m33; | - | ||||||||||||
1241 | m_type = TxNone; | - | ||||||||||||
1242 | m_dirty = TxProject; | - | ||||||||||||
1243 | } | - | ||||||||||||
1244 | - | |||||||||||||
1245 | static inline bool needsPerspectiveClipping(const QRectF &rect, const QTransform &transform) | - | ||||||||||||
1246 | { | - | ||||||||||||
1247 | const qreal wx = qMin(transform.m13() * rect.left(), transform.m13() * rect.right()); | - | ||||||||||||
1248 | const qreal wy = qMin(transform.m23() * rect.top(), transform.m23() * rect.bottom()); | - | ||||||||||||
1249 | - | |||||||||||||
1250 | return wx + wy + transform.m33() < (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001); | - | ||||||||||||
1251 | } | - | ||||||||||||
1252 | - | |||||||||||||
1253 | QRect QTransform::mapRect(const QRect &rect) const | - | ||||||||||||
1254 | { | - | ||||||||||||
1255 | TransformationType t = inline_type(); | - | ||||||||||||
1256 | if (t <= TxTranslate) | - | ||||||||||||
1257 | return rect.translated(qRound(affine._dx), qRound(affine._dy)); | - | ||||||||||||
1258 | - | |||||||||||||
1259 | if (t <= TxScale) { | - | ||||||||||||
1260 | int x = qRound(affine._m11*rect.x() + affine._dx); | - | ||||||||||||
1261 | int y = qRound(affine._m22*rect.y() + affine._dy); | - | ||||||||||||
1262 | int w = qRound(affine._m11*rect.width()); | - | ||||||||||||
1263 | int h = qRound(affine._m22*rect.height()); | - | ||||||||||||
1264 | if (w < 0) { | - | ||||||||||||
1265 | w = -w; | - | ||||||||||||
1266 | x -= w; | - | ||||||||||||
1267 | } | - | ||||||||||||
1268 | if (h < 0) { | - | ||||||||||||
1269 | h = -h; | - | ||||||||||||
1270 | y -= h; | - | ||||||||||||
1271 | } | - | ||||||||||||
1272 | return QRect(x, y, w, h); | - | ||||||||||||
1273 | } else if (t < TxProject || !needsPerspectiveClipping(rect, *this)) { | - | ||||||||||||
1274 | - | |||||||||||||
1275 | qreal x = 0, y = 0; | - | ||||||||||||
1276 | do { qreal FX_ = rect.left(); qreal FY_ = rect.top(); switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1277 | qreal xmin = x; | - | ||||||||||||
1278 | qreal ymin = y; | - | ||||||||||||
1279 | qreal xmax = x; | - | ||||||||||||
1280 | qreal ymax = y; | - | ||||||||||||
1281 | do { qreal FX_ = rect.right() + 1; qreal FY_ = rect.top(); switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1282 | xmin = qMin(xmin, x); | - | ||||||||||||
1283 | ymin = qMin(ymin, y); | - | ||||||||||||
1284 | xmax = qMax(xmax, x); | - | ||||||||||||
1285 | ymax = qMax(ymax, y); | - | ||||||||||||
1286 | do { qreal FX_ = rect.right() + 1; qreal FY_ = rect.bottom() + 1; switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1287 | xmin = qMin(xmin, x); | - | ||||||||||||
1288 | ymin = qMin(ymin, y); | - | ||||||||||||
1289 | xmax = qMax(xmax, x); | - | ||||||||||||
1290 | ymax = qMax(ymax, y); | - | ||||||||||||
1291 | do { qreal FX_ = rect.left(); qreal FY_ = rect.bottom() + 1; switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1292 | xmin = qMin(xmin, x); | - | ||||||||||||
1293 | ymin = qMin(ymin, y); | - | ||||||||||||
1294 | xmax = qMax(xmax, x); | - | ||||||||||||
1295 | ymax = qMax(ymax, y); | - | ||||||||||||
1296 | return QRect(qRound(xmin), qRound(ymin), qRound(xmax)-qRound(xmin), qRound(ymax)-qRound(ymin)); | - | ||||||||||||
1297 | } else { | - | ||||||||||||
1298 | QPainterPath path; | - | ||||||||||||
1299 | path.addRect(rect); | - | ||||||||||||
1300 | return map(path).boundingRect().toRect(); | - | ||||||||||||
1301 | } | - | ||||||||||||
1302 | } | - | ||||||||||||
1303 | QRectF QTransform::mapRect(const QRectF &rect) const | - | ||||||||||||
1304 | { | - | ||||||||||||
1305 | TransformationType t = inline_type(); | - | ||||||||||||
1306 | if (t <= TxTranslate) | - | ||||||||||||
1307 | return rect.translated(affine._dx, affine._dy); | - | ||||||||||||
1308 | - | |||||||||||||
1309 | if (t <= TxScale) { | - | ||||||||||||
1310 | qreal x = affine._m11*rect.x() + affine._dx; | - | ||||||||||||
1311 | qreal y = affine._m22*rect.y() + affine._dy; | - | ||||||||||||
1312 | qreal w = affine._m11*rect.width(); | - | ||||||||||||
1313 | qreal h = affine._m22*rect.height(); | - | ||||||||||||
1314 | if (w < 0) { | - | ||||||||||||
1315 | w = -w; | - | ||||||||||||
1316 | x -= w; | - | ||||||||||||
1317 | } | - | ||||||||||||
1318 | if (h < 0) { | - | ||||||||||||
1319 | h = -h; | - | ||||||||||||
1320 | y -= h; | - | ||||||||||||
1321 | } | - | ||||||||||||
1322 | return QRectF(x, y, w, h); | - | ||||||||||||
1323 | } else if (t < TxProject || !needsPerspectiveClipping(rect, *this)) { | - | ||||||||||||
1324 | qreal x = 0, y = 0; | - | ||||||||||||
1325 | do { qreal FX_ = rect.x(); qreal FY_ = rect.y(); switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1326 | qreal xmin = x; | - | ||||||||||||
1327 | qreal ymin = y; | - | ||||||||||||
1328 | qreal xmax = x; | - | ||||||||||||
1329 | qreal ymax = y; | - | ||||||||||||
1330 | do { qreal FX_ = rect.x() + rect.width(); qreal FY_ = rect.y(); switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1331 | xmin = qMin(xmin, x); | - | ||||||||||||
1332 | ymin = qMin(ymin, y); | - | ||||||||||||
1333 | xmax = qMax(xmax, x); | - | ||||||||||||
1334 | ymax = qMax(ymax, y); | - | ||||||||||||
1335 | do { qreal FX_ = rect.x() + rect.width(); qreal FY_ = rect.y() + rect.height(); switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1336 | xmin = qMin(xmin, x); | - | ||||||||||||
1337 | ymin = qMin(ymin, y); | - | ||||||||||||
1338 | xmax = qMax(xmax, x); | - | ||||||||||||
1339 | ymax = qMax(ymax, y); | - | ||||||||||||
1340 | do { qreal FX_ = rect.x(); qreal FY_ = rect.y() + rect.height(); switch(t) { case TxNone: x = FX_; y = FY_; break; case TxTranslate: x = FX_ + affine._dx; y = FY_ + affine._dy; break; case TxScale: x = affine._m11 * FX_ + affine._dx; y = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: x = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; y = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; x *= w; y *= w; } } } while (0); | - | ||||||||||||
1341 | xmin = qMin(xmin, x); | - | ||||||||||||
1342 | ymin = qMin(ymin, y); | - | ||||||||||||
1343 | xmax = qMax(xmax, x); | - | ||||||||||||
1344 | ymax = qMax(ymax, y); | - | ||||||||||||
1345 | return QRectF(xmin, ymin, xmax-xmin, ymax - ymin); | - | ||||||||||||
1346 | } else { | - | ||||||||||||
1347 | QPainterPath path; | - | ||||||||||||
1348 | path.addRect(rect); | - | ||||||||||||
1349 | return map(path).boundingRect(); | - | ||||||||||||
1350 | } | - | ||||||||||||
1351 | } | - | ||||||||||||
1352 | void QTransform::map(qreal x, qreal y, qreal *tx, qreal *ty) const | - | ||||||||||||
1353 | { | - | ||||||||||||
1354 | TransformationType t = inline_type(); | - | ||||||||||||
1355 | do { qreal FX_ = x; qreal FY_ = y; switch(t) { case TxNone: *tx = FX_; *ty = FY_; break; case TxTranslate: *tx = FX_ + affine._dx; *ty = FY_ + affine._dy; break; case TxScale: *tx = affine._m11 * FX_ + affine._dx; *ty = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: *tx = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; *ty = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; *tx *= w; *ty *= w; } } } while (0); | - | ||||||||||||
1356 | } | - | ||||||||||||
1357 | void QTransform::map(int x, int y, int *tx, int *ty) const | - | ||||||||||||
1358 | { | - | ||||||||||||
1359 | TransformationType t = inline_type(); | - | ||||||||||||
1360 | qreal fx = 0, fy = 0; | - | ||||||||||||
1361 | do { qreal FX_ = x; qreal FY_ = y; switch(t) { case TxNone: fx = FX_; fy = FY_; break; case TxTranslate: fx = FX_ + affine._dx; fy = FY_ + affine._dy; break; case TxScale: fx = affine._m11 * FX_ + affine._dx; fy = affine._m22 * FY_ + affine._dy; break; case TxRotate: case TxShear: case TxProject: fx = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; fy = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; if (t == TxProject) { qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); if (w < qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001))) w = qreal((sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)); w = 1./w; fx *= w; fy *= w; } } } while (0); | - | ||||||||||||
1362 | *tx = qRound(fx); | - | ||||||||||||
1363 | *ty = qRound(fy); | - | ||||||||||||
1364 | } | - | ||||||||||||
1365 | - | |||||||||||||
1366 | - | |||||||||||||
1367 | - | |||||||||||||
1368 | - | |||||||||||||
1369 | - | |||||||||||||
1370 | - | |||||||||||||
1371 | - | |||||||||||||
1372 | const QMatrix &QTransform::toAffine() const | - | ||||||||||||
1373 | { | - | ||||||||||||
1374 | return affine; | - | ||||||||||||
1375 | } | - | ||||||||||||
1376 | QTransform::TransformationType QTransform::type() const | - | ||||||||||||
1377 | { | - | ||||||||||||
1378 | if(m_dirty == TxNone || m_dirty < m_type) | - | ||||||||||||
1379 | return static_cast<TransformationType>(m_type); | - | ||||||||||||
1380 | - | |||||||||||||
1381 | switch (static_cast<TransformationType>(m_dirty)) { | - | ||||||||||||
1382 | case TxProject: | - | ||||||||||||
1383 | if (!qFuzzyIsNull(m_13) || !qFuzzyIsNull(m_23) || !qFuzzyIsNull(m_33 - 1)) { | - | ||||||||||||
1384 | m_type = TxProject; | - | ||||||||||||
1385 | break; | - | ||||||||||||
1386 | } | - | ||||||||||||
1387 | case TxShear: | - | ||||||||||||
1388 | case TxRotate: | - | ||||||||||||
1389 | if (!qFuzzyIsNull(affine._m12) || !qFuzzyIsNull(affine._m21)) { | - | ||||||||||||
1390 | const qreal dot = affine._m11 * affine._m12 + affine._m21 * affine._m22; | - | ||||||||||||
1391 | if (qFuzzyIsNull(dot)) | - | ||||||||||||
1392 | m_type = TxRotate; | - | ||||||||||||
1393 | else | - | ||||||||||||
1394 | m_type = TxShear; | - | ||||||||||||
1395 | break; | - | ||||||||||||
1396 | } | - | ||||||||||||
1397 | case TxScale: | - | ||||||||||||
1398 | if (!qFuzzyIsNull(affine._m11 - 1) || !qFuzzyIsNull(affine._m22 - 1)) { | - | ||||||||||||
1399 | m_type = TxScale; | - | ||||||||||||
1400 | break; | - | ||||||||||||
1401 | } | - | ||||||||||||
1402 | case TxTranslate: | - | ||||||||||||
1403 | if (!qFuzzyIsNull(affine._dx) || !qFuzzyIsNull(affine._dy)) { | - | ||||||||||||
1404 | m_type = TxTranslate; | - | ||||||||||||
1405 | break; | - | ||||||||||||
1406 | } | - | ||||||||||||
1407 | case TxNone: | - | ||||||||||||
1408 | m_type = TxNone; | - | ||||||||||||
1409 | break; | - | ||||||||||||
1410 | } | - | ||||||||||||
1411 | - | |||||||||||||
1412 | m_dirty = TxNone; | - | ||||||||||||
1413 | return static_cast<TransformationType>(m_type); | - | ||||||||||||
1414 | } | - | ||||||||||||
1415 | - | |||||||||||||
1416 | - | |||||||||||||
1417 | - | |||||||||||||
1418 | - | |||||||||||||
1419 | - | |||||||||||||
1420 | QTransform::operator QVariant() const | - | ||||||||||||
1421 | { | - | ||||||||||||
1422 | return QVariant(QVariant::Transform, this); | - | ||||||||||||
1423 | } | - | ||||||||||||
1424 | __attribute__((visibility("default"))) | - | ||||||||||||
1425 | bool qt_scaleForTransform(const QTransform &transform, qreal *scale) | - | ||||||||||||
1426 | { | - | ||||||||||||
1427 | const QTransform::TransformationType type = transform.type(); | - | ||||||||||||
1428 | if (type <= QTransform::TxTranslate) { | - | ||||||||||||
1429 | if (scale) | - | ||||||||||||
1430 | *scale = 1; | - | ||||||||||||
1431 | return true; | - | ||||||||||||
1432 | } else if (type == QTransform::TxScale) { | - | ||||||||||||
1433 | const qreal xScale = qAbs(transform.m11()); | - | ||||||||||||
1434 | const qreal yScale = qAbs(transform.m22()); | - | ||||||||||||
1435 | if (scale) | - | ||||||||||||
1436 | *scale = qMax(xScale, yScale); | - | ||||||||||||
1437 | return qFuzzyCompare(xScale, yScale); | - | ||||||||||||
1438 | } | - | ||||||||||||
1439 | - | |||||||||||||
1440 | - | |||||||||||||
1441 | const qreal xScale1 = transform.m11() * transform.m11() | - | ||||||||||||
1442 | + transform.m21() * transform.m21(); | - | ||||||||||||
1443 | const qreal yScale1 = transform.m12() * transform.m12() | - | ||||||||||||
1444 | + transform.m22() * transform.m22(); | - | ||||||||||||
1445 | - | |||||||||||||
1446 | - | |||||||||||||
1447 | const qreal xScale2 = transform.m11() * transform.m11() | - | ||||||||||||
1448 | + transform.m12() * transform.m12(); | - | ||||||||||||
1449 | const qreal yScale2 = transform.m21() * transform.m21() | - | ||||||||||||
1450 | + transform.m22() * transform.m22(); | - | ||||||||||||
1451 | - | |||||||||||||
1452 | - | |||||||||||||
1453 | if (qAbs(xScale1 - yScale1) > qAbs(xScale2 - yScale2)) { | - | ||||||||||||
1454 | if (scale) | - | ||||||||||||
1455 | *scale = qSqrt(qMax(xScale1, yScale1)); | - | ||||||||||||
1456 | - | |||||||||||||
1457 | return type == QTransform::TxRotate && qFuzzyCompare(xScale1, yScale1); | - | ||||||||||||
1458 | } else { | - | ||||||||||||
1459 | if (scale) | - | ||||||||||||
1460 | *scale = qSqrt(qMax(xScale2, yScale2)); | - | ||||||||||||
1461 | - | |||||||||||||
1462 | return type == QTransform::TxRotate && qFuzzyCompare(xScale2, yScale2); | - | ||||||||||||
1463 | } | - | ||||||||||||
1464 | } | - | ||||||||||||
1465 | - | |||||||||||||
1466 | - | |||||||||||||
Switch to Source code | Preprocessed file |