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(); |
danakj
2012/12/07 18:26:34
nit: one statement per line
reed1
2012/12/07 19:12:27
Done.
| |
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(); |
danakj
2012/12/07 18:26:34
Does the ordering here end up producing a twisted
reed1
2012/12/07 19:12:27
Done.
| |
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 HomogeneousCoordinate hc0(result[0], result[1], result[2], result[3]); | |
danakj
2012/12/07 18:26:34
nit: one space between each.
we don't line things
reed1
2012/12/07 19:12:27
Done.
| |
125 HomogeneousCoordinate hc1(result[4], result[5], result[6], result[7]); | |
126 HomogeneousCoordinate hc2(result[8], result[9], result[10], result[11]); | |
127 HomogeneousCoordinate hc3(result[12], result[13], result[14], result[15]); | |
128 return computeEnclosingClippedRect(hc0, hc1, hc2, hc3); | |
121 } | 129 } |
122 | 130 |
123 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) | 131 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) |
124 { | 132 { |
125 if (transform.IsIdentityOrTranslation()) | 133 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))); | 134 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); |
127 | 135 |
128 // Perform the projection, but retain the result in homogeneous coordinates. | 136 // Perform the projection, but retain the result in homogeneous coordinates. |
129 gfx::QuadF q = gfx::QuadF(srcRect); | 137 gfx::QuadF q = gfx::QuadF(srcRect); |
130 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); | 138 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); | 490 matrix.setDouble(1, 0, b); |
483 matrix.setDouble(0, 1, c); | 491 matrix.setDouble(0, 1, c); |
484 matrix.setDouble(1, 1, d); | 492 matrix.setDouble(1, 1, d); |
485 matrix.setDouble(0, 3, e); | 493 matrix.setDouble(0, 3, e); |
486 matrix.setDouble(1, 3, f); | 494 matrix.setDouble(1, 3, f); |
487 | 495 |
488 return result; | 496 return result; |
489 } | 497 } |
490 | 498 |
491 } // namespace cc | 499 } // namespace cc |
OLD | NEW |