Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: cc/math_util.cc

Issue 11293194: ui: Prefer +/- operators to apply offsets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: floats Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/math_util.h" 7 #include "cc/math_util.h"
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 numVerticesInClippedQuad++; 103 numVerticesInClippedQuad++;
104 } 104 }
105 105
106 gfx::Rect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, con st gfx::Rect& srcRect) 106 gfx::Rect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, con st gfx::Rect& srcRect)
107 { 107 {
108 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect))); 108 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect)));
109 } 109 }
110 110
111 gfx::RectF MathUtil::mapClippedRect(const WebTransformationMatrix& transform, co nst gfx::RectF& srcRect) 111 gfx::RectF MathUtil::mapClippedRect(const WebTransformationMatrix& transform, co nst gfx::RectF& srcRect)
112 { 112 {
113 if (transform.isIdentityOrTranslation()) { 113 if (transform.isIdentityOrTranslation())
114 gfx::RectF mappedRect(srcRect); 114 return srcRect + gfx::Vector2dF(static_cast<float>(transform.m41()), sta tic_cast<float>(transform.m42()));
115 mappedRect.Offset(static_cast<float>(transform.m41()), static_cast<float >(transform.m42()));
116 return mappedRect;
117 }
118 115
119 // Apply the transform, but retain the result in homogeneous coordinates. 116 // Apply the transform, but retain the result in homogeneous coordinates.
120 gfx::QuadF q = gfx::QuadF(srcRect); 117 gfx::QuadF q = gfx::QuadF(srcRect);
121 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1( ))); 118 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1( )));
122 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2( ))); 119 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2( )));
123 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3( ))); 120 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3( )));
124 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4( ))); 121 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4( )));
125 122
126 return computeEnclosingClippedRect(h1, h2, h3, h4); 123 return computeEnclosingClippedRect(h1, h2, h3, h4);
127 } 124 }
128 125
129 gfx::RectF MathUtil::projectClippedRect(const WebTransformationMatrix& transform , const gfx::RectF& srcRect) 126 gfx::RectF MathUtil::projectClippedRect(const WebTransformationMatrix& transform , const gfx::RectF& srcRect)
130 { 127 {
131 if (transform.isIdentityOrTranslation()) { 128 if (transform.isIdentityOrTranslation())
132 gfx::RectF projectedRect(srcRect); 129 return srcRect + gfx::Vector2dF(static_cast<float>(transform.m41()), sta tic_cast<float>(transform.m42()));
133 projectedRect.Offset(static_cast<float>(transform.m41()), static_cast<fl oat>(transform.m42()));
134 return projectedRect;
135 }
136 130
137 // Perform the projection, but retain the result in homogeneous coordinates. 131 // Perform the projection, but retain the result in homogeneous coordinates.
138 gfx::QuadF q = gfx::QuadF(srcRect); 132 gfx::QuadF q = gfx::QuadF(srcRect);
139 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); 133 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1());
140 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2()); 134 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2());
141 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3()); 135 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3());
142 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4()); 136 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4());
143 137
144 return computeEnclosingClippedRect(h1, h2, h3, h4); 138 return computeEnclosingClippedRect(h1, h2, h3, h4);
145 } 139 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return static_cast<float>(Rad2Deg(std::acos(dotProduct))); 391 return static_cast<float>(Rad2Deg(std::acos(dotProduct)));
398 } 392 }
399 393
400 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des tination) 394 gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF des tination)
401 { 395 {
402 float projectedLength = gfx::DotProduct(source, destination) / destination.L engthSquared(); 396 float projectedLength = gfx::DotProduct(source, destination) / destination.L engthSquared();
403 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d estination.y()); 397 return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * d estination.y());
404 } 398 }
405 399
406 } // namespace cc 400 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698