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

Side by Side Diff: cc/math_util.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScaleAsVector 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
« no previous file with comments | « cc/math_util.h ('k') | cc/math_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "FloatPoint.h"
10 #include "FloatQuad.h" 9 #include "FloatQuad.h"
11 #include "IntRect.h" 10 #include "FloatSize.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/rect_conversions.h"
13 #include "ui/gfx/rect_f.h"
12 #include <cmath> 14 #include <cmath>
13 #include <public/WebTransformationMatrix.h> 15 #include <public/WebTransformationMatrix.h>
14 16
15 using WebKit::WebTransformationMatrix; 17 using WebKit::WebTransformationMatrix;
16 18
17 namespace cc { 19 namespace cc {
18 20
19 static HomogeneousCoordinate projectHomogeneousPoint(const WebTransformationMatr ix& transform, const FloatPoint& p) 21 static HomogeneousCoordinate projectHomogeneousPoint(const WebTransformationMatr ix& transform, const gfx::PointF& p)
20 { 22 {
21 // In this case, the layer we are trying to project onto is perpendicular to ray 23 // In this case, the layer we are trying to project onto is perpendicular to ray
22 // (point p and z-axis direction) that we are trying to project. This happen s when the 24 // (point p and z-axis direction) that we are trying to project. This happen s when the
23 // layer is rotated so that it is infinitesimally thin, or when it is co-pla nar with 25 // layer is rotated so that it is infinitesimally thin, or when it is co-pla nar with
24 // the camera origin -- i.e. when the layer is invisible anyway. 26 // the camera origin -- i.e. when the layer is invisible anyway.
25 if (!transform.m33()) 27 if (!transform.m33())
26 return HomogeneousCoordinate(0, 0, 0, 1); 28 return HomogeneousCoordinate(0, 0, 0, 1);
27 29
28 double x = p.x(); 30 double x = p.x();
29 double y = p.y(); 31 double y = p.y();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 77
76 double t = (w - h1.w) / (h2.w - h1.w); 78 double t = (w - h1.w) / (h2.w - h1.w);
77 79
78 double x = (1-t) * h1.x + t * h2.x; 80 double x = (1-t) * h1.x + t * h2.x;
79 double y = (1-t) * h1.y + t * h2.y; 81 double y = (1-t) * h1.y + t * h2.y;
80 double z = (1-t) * h1.z + t * h2.z; 82 double z = (1-t) * h1.z + t * h2.z;
81 83
82 return HomogeneousCoordinate(x, y, z, w); 84 return HomogeneousCoordinate(x, y, z, w);
83 } 85 }
84 86
85 static inline void expandBoundsToIncludePoint(float& xmin, float& xmax, float& y min, float& ymax, const FloatPoint& p) 87 static inline void expandBoundsToIncludePoint(float& xmin, float& xmax, float& y min, float& ymax, const gfx::PointF& p)
86 { 88 {
87 xmin = std::min(p.x(), xmin); 89 xmin = std::min(p.x(), xmin);
88 xmax = std::max(p.x(), xmax); 90 xmax = std::max(p.x(), xmax);
89 ymin = std::min(p.y(), ymin); 91 ymin = std::min(p.y(), ymin);
90 ymax = std::max(p.y(), ymax); 92 ymax = std::max(p.y(), ymax);
91 } 93 }
92 94
93 static inline void addVertexToClippedQuad(const FloatPoint& newVertex, FloatPoin t clippedQuad[8], int& numVerticesInClippedQuad) 95 static inline void addVertexToClippedQuad(const gfx::PointF& newVertex, gfx::Poi ntF clippedQuad[8], int& numVerticesInClippedQuad)
94 { 96 {
95 clippedQuad[numVerticesInClippedQuad] = newVertex; 97 clippedQuad[numVerticesInClippedQuad] = newVertex;
96 numVerticesInClippedQuad++; 98 numVerticesInClippedQuad++;
97 } 99 }
98 100
99 IntRect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, const IntRect& srcRect) 101 gfx::Rect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, con st gfx::Rect& srcRect)
100 { 102 {
101 return enclosingIntRect(mapClippedRect(transform, FloatRect(srcRect))); 103 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect)));
102 } 104 }
103 105
104 FloatRect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, con st FloatRect& srcRect) 106 gfx::RectF MathUtil::mapClippedRect(const WebTransformationMatrix& transform, co nst gfx::RectF& srcRect)
105 { 107 {
106 if (transform.isIdentityOrTranslation()) { 108 if (transform.isIdentityOrTranslation()) {
107 FloatRect mappedRect(srcRect); 109 gfx::RectF mappedRect(srcRect);
108 mappedRect.move(static_cast<float>(transform.m41()), static_cast<float>( transform.m42())); 110 mappedRect.Offset(static_cast<float>(transform.m41()), static_cast<float >(transform.m42()));
109 return mappedRect; 111 return mappedRect;
110 } 112 }
111 113
112 // Apply the transform, but retain the result in homogeneous coordinates. 114 // Apply the transform, but retain the result in homogeneous coordinates.
113 FloatQuad q = FloatQuad(FloatRect(srcRect)); 115 FloatQuad q = FloatQuad(gfx::RectF(srcRect));
114 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); 116 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1());
115 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); 117 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2());
116 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); 118 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3());
117 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4()); 119 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4());
118 120
119 return computeEnclosingClippedRect(h1, h2, h3, h4); 121 return computeEnclosingClippedRect(h1, h2, h3, h4);
120 } 122 }
121 123
122 FloatRect MathUtil::projectClippedRect(const WebTransformationMatrix& transform, const FloatRect& srcRect) 124 gfx::RectF MathUtil::projectClippedRect(const WebTransformationMatrix& transform , const gfx::RectF& srcRect)
123 { 125 {
124 // Perform the projection, but retain the result in homogeneous coordinates. 126 // Perform the projection, but retain the result in homogeneous coordinates.
125 FloatQuad q = FloatQuad(FloatRect(srcRect)); 127 FloatQuad q = FloatQuad(gfx::RectF(srcRect));
126 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); 128 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1());
127 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2()); 129 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2());
128 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3()); 130 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3());
129 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4()); 131 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4());
130 132
131 return computeEnclosingClippedRect(h1, h2, h3, h4); 133 return computeEnclosingClippedRect(h1, h2, h3, h4);
132 } 134 }
133 135
134 void MathUtil::mapClippedQuad(const WebTransformationMatrix& transform, const Fl oatQuad& srcQuad, FloatPoint clippedQuad[8], int& numVerticesInClippedQuad) 136 void MathUtil::mapClippedQuad(const WebTransformationMatrix& transform, const Fl oatQuad& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad)
135 { 137 {
136 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, srcQuad.p1()); 138 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, srcQuad.p1());
137 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, srcQuad.p2()); 139 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, srcQuad.p2());
138 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, srcQuad.p3()); 140 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, srcQuad.p3());
139 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, srcQuad.p4()); 141 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, srcQuad.p4());
140 142
141 // The order of adding the vertices to the array is chosen so that clockwise / counter-clockwise orientation is retained. 143 // The order of adding the vertices to the array is chosen so that clockwise / counter-clockwise orientation is retained.
142 144
143 numVerticesInClippedQuad = 0; 145 numVerticesInClippedQuad = 0;
144 146
(...skipping 17 matching lines...) Expand all
162 164
163 if (!h4.shouldBeClipped()) 165 if (!h4.shouldBeClipped())
164 addVertexToClippedQuad(h4.cartesianPoint2d(), clippedQuad, numVerticesIn ClippedQuad); 166 addVertexToClippedQuad(h4.cartesianPoint2d(), clippedQuad, numVerticesIn ClippedQuad);
165 167
166 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) 168 if (h4.shouldBeClipped() ^ h1.shouldBeClipped())
167 addVertexToClippedQuad(computeClippedPointForEdge(h4, h1).cartesianPoint 2d(), clippedQuad, numVerticesInClippedQuad); 169 addVertexToClippedQuad(computeClippedPointForEdge(h4, h1).cartesianPoint 2d(), clippedQuad, numVerticesInClippedQuad);
168 170
169 DCHECK(numVerticesInClippedQuad <= 8); 171 DCHECK(numVerticesInClippedQuad <= 8);
170 } 172 }
171 173
172 FloatRect MathUtil::computeEnclosingRectOfVertices(FloatPoint vertices[], int nu mVertices) 174 gfx::RectF MathUtil::computeEnclosingRectOfVertices(gfx::PointF vertices[], int numVertices)
173 { 175 {
174 if (numVertices < 2) 176 if (numVertices < 2)
175 return FloatRect(); 177 return gfx::RectF();
176 178
177 float xmin = std::numeric_limits<float>::max(); 179 float xmin = std::numeric_limits<float>::max();
178 float xmax = -std::numeric_limits<float>::max(); 180 float xmax = -std::numeric_limits<float>::max();
179 float ymin = std::numeric_limits<float>::max(); 181 float ymin = std::numeric_limits<float>::max();
180 float ymax = -std::numeric_limits<float>::max(); 182 float ymax = -std::numeric_limits<float>::max();
181 183
182 for (int i = 0; i < numVertices; ++i) 184 for (int i = 0; i < numVertices; ++i)
183 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, vertices[i]); 185 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, vertices[i]);
184 186
185 return FloatRect(FloatPoint(xmin, ymin), FloatSize(xmax - xmin, ymax - ymin) ); 187 return gfx::RectF(gfx::PointF(xmin, ymin), gfx::SizeF(xmax - xmin, ymax - ym in));
186 } 188 }
187 189
188 FloatRect MathUtil::computeEnclosingClippedRect(const HomogeneousCoordinate& h1, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homogen eousCoordinate& h4) 190 gfx::RectF MathUtil::computeEnclosingClippedRect(const HomogeneousCoordinate& h1 , const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homoge neousCoordinate& h4)
189 { 191 {
190 // This function performs clipping as necessary and computes the enclosing 2 d 192 // This function performs clipping as necessary and computes the enclosing 2 d
191 // FloatRect of the vertices. Doing these two steps simultaneously allows us to avoid 193 // gfx::RectF of the vertices. Doing these two steps simultaneously allows u s to avoid
192 // the overhead of storing an unknown number of clipped vertices. 194 // the overhead of storing an unknown number of clipped vertices.
193 195
194 // If no vertices on the quad are clipped, then we can simply return the enc losing rect directly. 196 // If no vertices on the quad are clipped, then we can simply return the enc losing rect directly.
195 bool somethingClipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.s houldBeClipped() || h4.shouldBeClipped(); 197 bool somethingClipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.s houldBeClipped() || h4.shouldBeClipped();
196 if (!somethingClipped) { 198 if (!somethingClipped) {
197 FloatQuad mappedQuad = FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoin t2d(), h3.cartesianPoint2d(), h4.cartesianPoint2d()); 199 FloatQuad mappedQuad = FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoin t2d(), h3.cartesianPoint2d(), h4.cartesianPoint2d());
198 return cc::FloatRect(mappedQuad.boundingBox()); 200 return cc::FloatRect(mappedQuad.boundingBox());
199 } 201 }
200 202
201 bool everythingClipped = h1.shouldBeClipped() && h2.shouldBeClipped() && h3. shouldBeClipped() && h4.shouldBeClipped(); 203 bool everythingClipped = h1.shouldBeClipped() && h2.shouldBeClipped() && h3. shouldBeClipped() && h4.shouldBeClipped();
202 if (everythingClipped) 204 if (everythingClipped)
203 return FloatRect(); 205 return gfx::RectF();
204 206
205 207
206 float xmin = std::numeric_limits<float>::max(); 208 float xmin = std::numeric_limits<float>::max();
207 float xmax = -std::numeric_limits<float>::max(); 209 float xmax = -std::numeric_limits<float>::max();
208 float ymin = std::numeric_limits<float>::max(); 210 float ymin = std::numeric_limits<float>::max();
209 float ymax = -std::numeric_limits<float>::max(); 211 float ymax = -std::numeric_limits<float>::max();
210 212
211 if (!h1.shouldBeClipped()) 213 if (!h1.shouldBeClipped())
212 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h1.cartesianPoint2d() ); 214 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h1.cartesianPoint2d() );
213 215
(...skipping 11 matching lines...) Expand all
225 227
226 if (h3.shouldBeClipped() ^ h4.shouldBeClipped()) 228 if (h3.shouldBeClipped() ^ h4.shouldBeClipped())
227 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo rEdge(h3, h4).cartesianPoint2d()); 229 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo rEdge(h3, h4).cartesianPoint2d());
228 230
229 if (!h4.shouldBeClipped()) 231 if (!h4.shouldBeClipped())
230 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h4.cartesianPoint2d() ); 232 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h4.cartesianPoint2d() );
231 233
232 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) 234 if (h4.shouldBeClipped() ^ h1.shouldBeClipped())
233 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo rEdge(h4, h1).cartesianPoint2d()); 235 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo rEdge(h4, h1).cartesianPoint2d());
234 236
235 return FloatRect(FloatPoint(xmin, ymin), FloatSize(xmax - xmin, ymax - ymin) ); 237 return gfx::RectF(gfx::PointF(xmin, ymin), gfx::SizeF(xmax - xmin, ymax - ym in));
236 } 238 }
237 239
238 FloatQuad MathUtil::mapQuad(const WebTransformationMatrix& transform, const Floa tQuad& q, bool& clipped) 240 FloatQuad MathUtil::mapQuad(const WebTransformationMatrix& transform, const Floa tQuad& q, bool& clipped)
239 { 241 {
240 if (transform.isIdentityOrTranslation()) { 242 if (transform.isIdentityOrTranslation()) {
241 FloatQuad mappedQuad(q); 243 FloatQuad mappedQuad(q);
242 mappedQuad.move(static_cast<float>(transform.m41()), static_cast<float>( transform.m42())); 244 mappedQuad.move(static_cast<float>(transform.m41()), static_cast<float>( transform.m42()));
243 clipped = false; 245 clipped = false;
244 return mappedQuad; 246 return mappedQuad;
245 } 247 }
246 248
247 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); 249 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1());
248 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); 250 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2());
249 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); 251 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3());
250 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4()); 252 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4());
251 253
252 clipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.shouldBeClipped () || h4.shouldBeClipped(); 254 clipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.shouldBeClipped () || h4.shouldBeClipped();
253 255
254 // Result will be invalid if clipped == true. But, compute it anyway just in case, to emulate existing behavior. 256 // Result will be invalid if clipped == true. But, compute it anyway just in case, to emulate existing behavior.
255 return FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesianP oint2d(), h4.cartesianPoint2d()); 257 return FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesianP oint2d(), h4.cartesianPoint2d());
256 } 258 }
257 259
258 FloatPoint MathUtil::mapPoint(const WebTransformationMatrix& transform, const Fl oatPoint& p, bool& clipped) 260 gfx::PointF MathUtil::mapPoint(const WebTransformationMatrix& transform, const g fx::PointF& p, bool& clipped)
259 { 261 {
260 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); 262 HomogeneousCoordinate h = mapHomogeneousPoint(transform, cc::FloatPoint(p));
261 263
262 if (h.w > 0) { 264 if (h.w > 0) {
263 clipped = false; 265 clipped = false;
264 return h.cartesianPoint2d(); 266 return h.cartesianPoint2d();
265 } 267 }
266 268
267 // The cartesian coordinates will be invalid after dividing by w. 269 // The cartesian coordinates will be invalid after dividing by w.
268 clipped = true; 270 clipped = true;
269 271
270 // Avoid dividing by w if w == 0. 272 // Avoid dividing by w if w == 0.
271 if (!h.w) 273 if (!h.w)
272 return FloatPoint(); 274 return gfx::PointF();
273 275
274 // This return value will be invalid because clipped == true, but (1) users of this 276 // This return value will be invalid because clipped == true, but (1) users of this
275 // code should be ignoring the return value when clipped == true anyway, and (2) this 277 // code should be ignoring the return value when clipped == true anyway, and (2) this
276 // behavior is more consistent with existing behavior of WebKit transforms i f the user 278 // behavior is more consistent with existing behavior of WebKit transforms i f the user
277 // really does not ignore the return value. 279 // really does not ignore the return value.
278 return h.cartesianPoint2d(); 280 return h.cartesianPoint2d();
279 } 281 }
280 282
281 FloatPoint3D MathUtil::mapPoint(const WebTransformationMatrix& transform, const FloatPoint3D& p, bool& clipped) 283 FloatPoint3D MathUtil::mapPoint(const WebTransformationMatrix& transform, const FloatPoint3D& p, bool& clipped)
282 { 284 {
(...skipping 27 matching lines...) Expand all
310 projectedQuad.setP2(projectPoint(transform, q.p2(), clippedPoint)); 312 projectedQuad.setP2(projectPoint(transform, q.p2(), clippedPoint));
311 clipped |= clippedPoint; 313 clipped |= clippedPoint;
312 projectedQuad.setP3(projectPoint(transform, q.p3(), clippedPoint)); 314 projectedQuad.setP3(projectPoint(transform, q.p3(), clippedPoint));
313 clipped |= clippedPoint; 315 clipped |= clippedPoint;
314 projectedQuad.setP4(projectPoint(transform, q.p4(), clippedPoint)); 316 projectedQuad.setP4(projectPoint(transform, q.p4(), clippedPoint));
315 clipped |= clippedPoint; 317 clipped |= clippedPoint;
316 318
317 return projectedQuad; 319 return projectedQuad;
318 } 320 }
319 321
320 FloatPoint MathUtil::projectPoint(const WebTransformationMatrix& transform, cons t FloatPoint& p, bool& clipped) 322 gfx::PointF MathUtil::projectPoint(const WebTransformationMatrix& transform, con st gfx::PointF& p, bool& clipped)
321 { 323 {
322 HomogeneousCoordinate h = projectHomogeneousPoint(transform, p); 324 HomogeneousCoordinate h = projectHomogeneousPoint(transform, p);
323 325
324 if (h.w > 0) { 326 if (h.w > 0) {
325 // The cartesian coordinates will be valid in this case. 327 // The cartesian coordinates will be valid in this case.
326 clipped = false; 328 clipped = false;
327 return h.cartesianPoint2d(); 329 return h.cartesianPoint2d();
328 } 330 }
329 331
330 // The cartesian coordinates will be invalid after dividing by w. 332 // The cartesian coordinates will be invalid after dividing by w.
331 clipped = true; 333 clipped = true;
332 334
333 // Avoid dividing by w if w == 0. 335 // Avoid dividing by w if w == 0.
334 if (!h.w) 336 if (!h.w)
335 return FloatPoint(); 337 return gfx::PointF();
336 338
337 // This return value will be invalid because clipped == true, but (1) users of this 339 // This return value will be invalid because clipped == true, but (1) users of this
338 // code should be ignoring the return value when clipped == true anyway, and (2) this 340 // code should be ignoring the return value when clipped == true anyway, and (2) this
339 // behavior is more consistent with existing behavior of WebKit transforms i f the user 341 // behavior is more consistent with existing behavior of WebKit transforms i f the user
340 // really does not ignore the return value. 342 // really does not ignore the return value.
341 return h.cartesianPoint2d(); 343 return h.cartesianPoint2d();
342 } 344 }
343 345
344 void MathUtil::flattenTransformTo2d(WebTransformationMatrix& transform) 346 void MathUtil::flattenTransformTo2d(WebTransformationMatrix& transform)
345 { 347 {
(...skipping 14 matching lines...) Expand all
360 transform.setM33(1); 362 transform.setM33(1);
361 transform.setM34(0); 363 transform.setM34(0);
362 transform.setM43(0); 364 transform.setM43(0);
363 } 365 }
364 366
365 static inline float scaleOnAxis(double a, double b, double c) 367 static inline float scaleOnAxis(double a, double b, double c)
366 { 368 {
367 return std::sqrt(a * a + b * b + c * c); 369 return std::sqrt(a * a + b * b + c * c);
368 } 370 }
369 371
370 FloatPoint MathUtil::computeTransform2dScaleComponents(const WebTransformationMa trix& transform) 372 gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const WebTransformati onMatrix& transform)
371 { 373 {
372 if (transform.hasPerspective()) 374 if (transform.hasPerspective())
373 return FloatPoint(1, 1); 375 return gfx::Vector2dF(1, 1);
374 float xScale = scaleOnAxis(transform.m11(), transform.m12(), transform.m13() ); 376 float xScale = scaleOnAxis(transform.m11(), transform.m12(), transform.m13() );
375 float yScale = scaleOnAxis(transform.m21(), transform.m22(), transform.m23() ); 377 float yScale = scaleOnAxis(transform.m21(), transform.m22(), transform.m23() );
376 return FloatPoint(xScale, yScale); 378 return gfx::Vector2dF(xScale, yScale);
377 } 379 }
378 380
379 float MathUtil::smallestAngleBetweenVectors(const FloatSize& v1, const FloatSize & v2) 381 float MathUtil::smallestAngleBetweenVectors(const FloatSize& v1, const FloatSize & v2)
380 { 382 {
381 float dotProduct = (v1.width() * v2.width() + v1.height() * v2.height()) / ( v1.diagonalLength() * v2.diagonalLength()); 383 float dotProduct = (v1.width() * v2.width() + v1.height() * v2.height()) / ( v1.diagonalLength() * v2.diagonalLength());
382 // Clamp to compensate for rounding errors. 384 // Clamp to compensate for rounding errors.
383 dotProduct = std::max(-1.f, std::min(1.f, dotProduct)); 385 dotProduct = std::max(-1.f, std::min(1.f, dotProduct));
384 return rad2deg(acosf(dotProduct)); 386 return rad2deg(acosf(dotProduct));
385 } 387 }
386 388
387 FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& dest ination) 389 FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& dest ination)
388 { 390 {
389 float sourceDotDestination = source.width() * destination.width() + source.h eight() * destination.height(); 391 float sourceDotDestination = source.width() * destination.width() + source.h eight() * destination.height();
390 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu ared(); 392 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu ared();
391 return FloatSize(projectedLength * destination.width(), projectedLength * de stination.height()); 393 return FloatSize(projectedLength * destination.width(), projectedLength * de stination.height());
392 } 394 }
393 395
394 } // namespace cc 396 } // namespace cc
OLDNEW
« no previous file with comments | « cc/math_util.h ('k') | cc/math_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698