OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
3 * 2010 Dirk Schulze <krit@webkit.org> | 3 * 2010 Dirk Schulze <krit@webkit.org> |
4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
14 * | 14 * |
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "platform/transforms/AffineTransform.h" | 28 #include "platform/transforms/AffineTransform.h" |
29 | 29 |
30 #include "platform/FloatConversion.h" | |
31 #include "platform/geometry/FloatQuad.h" | 30 #include "platform/geometry/FloatQuad.h" |
32 #include "platform/geometry/FloatRect.h" | 31 #include "platform/geometry/FloatRect.h" |
33 #include "platform/geometry/IntRect.h" | 32 #include "platform/geometry/IntRect.h" |
34 #include "wtf/MathExtras.h" | 33 #include "wtf/MathExtras.h" |
35 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
36 | 35 |
37 namespace blink { | 36 namespace blink { |
38 | 37 |
39 AffineTransform::AffineTransform() | 38 AffineTransform::AffineTransform() |
40 { | 39 { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 275 |
277 // Round the point. | 276 // Round the point. |
278 return IntPoint(lround(x2), lround(y2)); | 277 return IntPoint(lround(x2), lround(y2)); |
279 } | 278 } |
280 | 279 |
281 FloatPoint AffineTransform::mapPoint(const FloatPoint& point) const | 280 FloatPoint AffineTransform::mapPoint(const FloatPoint& point) const |
282 { | 281 { |
283 double x2, y2; | 282 double x2, y2; |
284 map(point.x(), point.y(), x2, y2); | 283 map(point.x(), point.y(), x2, y2); |
285 | 284 |
286 return FloatPoint(narrowPrecisionToFloat(x2), narrowPrecisionToFloat(y2)); | 285 return FloatPoint(clampTo<float>(x2), clampTo<float>(y2)); |
287 } | 286 } |
288 | 287 |
289 IntSize AffineTransform::mapSize(const IntSize& size) const | 288 IntSize AffineTransform::mapSize(const IntSize& size) const |
290 { | 289 { |
291 double width2 = size.width() * xScale(); | 290 double width2 = size.width() * xScale(); |
292 double height2 = size.height() * yScale(); | 291 double height2 = size.height() * yScale(); |
293 | 292 |
294 return IntSize(lround(width2), lround(height2)); | 293 return IntSize(lround(width2), lround(height2)); |
295 } | 294 } |
296 | 295 |
297 FloatSize AffineTransform::mapSize(const FloatSize& size) const | 296 FloatSize AffineTransform::mapSize(const FloatSize& size) const |
298 { | 297 { |
299 double width2 = size.width() * xScale(); | 298 double width2 = size.width() * xScale(); |
300 double height2 = size.height() * yScale(); | 299 double height2 = size.height() * yScale(); |
301 | 300 |
302 return FloatSize(narrowPrecisionToFloat(width2), narrowPrecisionToFloat(heig
ht2)); | 301 return FloatSize(clampTo<float>(width2), clampTo<float>(height2)); |
303 } | 302 } |
304 | 303 |
305 IntRect AffineTransform::mapRect(const IntRect &rect) const | 304 IntRect AffineTransform::mapRect(const IntRect &rect) const |
306 { | 305 { |
307 return enclosingIntRect(mapRect(FloatRect(rect))); | 306 return enclosingIntRect(mapRect(FloatRect(rect))); |
308 } | 307 } |
309 | 308 |
310 FloatRect AffineTransform::mapRect(const FloatRect& rect) const | 309 FloatRect AffineTransform::mapRect(const FloatRect& rect) const |
311 { | 310 { |
312 if (isIdentityOrTranslation()) { | 311 if (isIdentityOrTranslation()) { |
313 if (!m_transform[4] && !m_transform[5]) | 312 if (!m_transform[4] && !m_transform[5]) |
314 return rect; | 313 return rect; |
315 | 314 |
316 FloatRect mappedRect(rect); | 315 FloatRect mappedRect(rect); |
317 mappedRect.move(narrowPrecisionToFloat(m_transform[4]), narrowPrecisionT
oFloat(m_transform[5])); | 316 mappedRect.move(clampTo<float>(m_transform[4]), clampTo<float>(m_transfo
rm[5])); |
318 return mappedRect; | 317 return mappedRect; |
319 } | 318 } |
320 | 319 |
321 FloatQuad result; | 320 FloatQuad result; |
322 result.setP1(mapPoint(rect.location())); | 321 result.setP1(mapPoint(rect.location())); |
323 result.setP2(mapPoint(FloatPoint(rect.maxX(), rect.y()))); | 322 result.setP2(mapPoint(FloatPoint(rect.maxX(), rect.y()))); |
324 result.setP3(mapPoint(FloatPoint(rect.maxX(), rect.maxY()))); | 323 result.setP3(mapPoint(FloatPoint(rect.maxX(), rect.maxY()))); |
325 result.setP4(mapPoint(FloatPoint(rect.x(), rect.maxY()))); | 324 result.setP4(mapPoint(FloatPoint(rect.x(), rect.maxY()))); |
326 return result.boundingBox(); | 325 return result.boundingBox(); |
327 } | 326 } |
328 | 327 |
329 FloatQuad AffineTransform::mapQuad(const FloatQuad& q) const | 328 FloatQuad AffineTransform::mapQuad(const FloatQuad& q) const |
330 { | 329 { |
331 if (isIdentityOrTranslation()) { | 330 if (isIdentityOrTranslation()) { |
332 FloatQuad mappedQuad(q); | 331 FloatQuad mappedQuad(q); |
333 mappedQuad.move(narrowPrecisionToFloat(m_transform[4]), narrowPrecisionT
oFloat(m_transform[5])); | 332 mappedQuad.move(clampTo<float>(m_transform[4]), clampTo<float>(m_transfo
rm[5])); |
334 return mappedQuad; | 333 return mappedQuad; |
335 } | 334 } |
336 | 335 |
337 FloatQuad result; | 336 FloatQuad result; |
338 result.setP1(mapPoint(q.p1())); | 337 result.setP1(mapPoint(q.p1())); |
339 result.setP2(mapPoint(q.p2())); | 338 result.setP2(mapPoint(q.p2())); |
340 result.setP3(mapPoint(q.p3())); | 339 result.setP3(mapPoint(q.p3())); |
341 result.setP4(mapPoint(q.p4())); | 340 result.setP4(mapPoint(q.p4())); |
342 return result; | 341 return result; |
343 } | 342 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 decomposition.scaleX, | 424 decomposition.scaleX, |
426 decomposition.scaleY, | 425 decomposition.scaleY, |
427 rad2deg(decomposition.angle), | 426 rad2deg(decomposition.angle), |
428 decomposition.remainderA, | 427 decomposition.remainderA, |
429 decomposition.remainderB, | 428 decomposition.remainderB, |
430 decomposition.remainderC, | 429 decomposition.remainderC, |
431 decomposition.remainderD); | 430 decomposition.remainderD); |
432 } | 431 } |
433 | 432 |
434 } // namespace blink | 433 } // namespace blink |
OLD | NEW |