Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/math_util.h" | 5 #include "cc/math_util.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "ui/gfx/quad_f.h" | 10 #include "ui/gfx/quad_f.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 102 |
| 103 gfx::Rect MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx::R ect& srcRect) | 103 gfx::Rect MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx::R ect& srcRect) |
| 104 { | 104 { |
| 105 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect))); | 105 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect))); |
| 106 } | 106 } |
| 107 | 107 |
| 108 gfx::RectF MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx:: RectF& srcRect) | 108 gfx::RectF MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx:: RectF& srcRect) |
| 109 { | 109 { |
| 110 if (transform.IsIdentityOrTranslation()) | 110 if (transform.IsIdentityOrTranslation()) |
| 111 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); | 111 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); |
| 112 | |
| 113 // Apply the transform, but retain the result in homogeneous coordinates. | |
| 112 | 114 |
| 113 // Apply the transform, but retain the result in homogeneous coordinates. | 115 double quad[4 * 2]; // input: 4 x 2D points |
| 114 gfx::QuadF q = gfx::QuadF(srcRect); | 116 quad[0] = srcRect.x(); quad[1] = srcRect.y(); |
| 115 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1( ))); | 117 quad[2] = srcRect.right(); quad[3] = srcRect.y(); |
| 116 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2( ))); | 118 quad[4] = srcRect.x(); quad[5] = srcRect.bottom(); |
| 117 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3( ))); | 119 quad[6] = srcRect.right(); quad[7] = srcRect.bottom(); |
| 118 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4( ))); | |
| 119 | 120 |
| 120 return computeEnclosingClippedRect(h1, h2, h3, h4); | 121 double result[4 * 4]; // output: 4 x 4D homogeneous points |
| 122 transform.matrix().map2(quad, 4, result); | |
| 123 | |
| 124 return computeEnclosingClippedRect(*(const HomogeneousCoordinate*)&result[0] , | |
|
jamesr
2012/12/07 04:30:39
chromium code never uses c-style casts. I'd sugge
| |
| 125 *(const HomogeneousCoordinate*)&result[4] , | |
| 126 *(const HomogeneousCoordinate*)&result[8] , | |
| 127 *(const HomogeneousCoordinate*)&result[12 ]); | |
| 121 } | 128 } |
| 122 | 129 |
| 123 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) | 130 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) |
| 124 { | 131 { |
| 125 if (transform.IsIdentityOrTranslation()) | 132 if (transform.IsIdentityOrTranslation()) |
| 126 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); | 133 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); |
| 127 | 134 |
| 128 // Perform the projection, but retain the result in homogeneous coordinates. | 135 // Perform the projection, but retain the result in homogeneous coordinates. |
| 129 gfx::QuadF q = gfx::QuadF(srcRect); | 136 gfx::QuadF q = gfx::QuadF(srcRect); |
| 130 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); | 137 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 matrix.setDouble(1, 0, b); | 489 matrix.setDouble(1, 0, b); |
| 483 matrix.setDouble(0, 1, c); | 490 matrix.setDouble(0, 1, c); |
| 484 matrix.setDouble(1, 1, d); | 491 matrix.setDouble(1, 1, d); |
| 485 matrix.setDouble(0, 3, e); | 492 matrix.setDouble(0, 3, e); |
| 486 matrix.setDouble(1, 3, f); | 493 matrix.setDouble(1, 3, f); |
| 487 | 494 |
| 488 return result; | 495 return result; |
| 489 } | 496 } |
| 490 | 497 |
| 491 } // namespace cc | 498 } // namespace cc |
| OLD | NEW |