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

Side by Side Diff: cc/math_util.h

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/layer_unittest.cc ('k') | cc/math_util.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 #ifndef CCMathUtil_h 5 #ifndef CCMathUtil_h
6 #define CCMathUtil_h 6 #define CCMathUtil_h
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "FloatPoint.h" 9 #include "ui/gfx/point_f.h"
10 #include "FloatPoint3D.h" 10 #include "FloatPoint3D.h"
11 11
12 namespace WebKit { 12 namespace WebKit {
13 class WebTransformationMatrix; 13 class WebTransformationMatrix;
14 } 14 }
15 15
16 namespace gfx {
17 class Rect;
18 class RectF;
19 }
20
16 namespace cc { 21 namespace cc {
17 22
18 class IntRect;
19 class FloatRect;
20 class FloatQuad; 23 class FloatQuad;
24 class FloatSize;
21 25
22 struct HomogeneousCoordinate { 26 struct HomogeneousCoordinate {
23 HomogeneousCoordinate(double newX, double newY, double newZ, double newW) 27 HomogeneousCoordinate(double newX, double newY, double newZ, double newW)
24 : x(newX) 28 : x(newX)
25 , y(newY) 29 , y(newY)
26 , z(newZ) 30 , z(newZ)
27 , w(newW) 31 , w(newW)
28 { 32 {
29 } 33 }
30 34
31 bool shouldBeClipped() const 35 bool shouldBeClipped() const
32 { 36 {
33 return w <= 0; 37 return w <= 0;
34 } 38 }
35 39
36 FloatPoint cartesianPoint2d() const 40 gfx::PointF cartesianPoint2d() const
37 { 41 {
38 if (w == 1) 42 if (w == 1)
39 return FloatPoint(x, y); 43 return gfx::PointF(x, y);
40 44
41 // For now, because this code is used privately only by MathUtil, it sho uld never be called when w == 0, and we do not yet need to handle that case. 45 // For now, because this code is used privately only by MathUtil, it sho uld never be called when w == 0, and we do not yet need to handle that case.
42 DCHECK(w); 46 DCHECK(w);
43 double invW = 1.0 / w; 47 double invW = 1.0 / w;
44 return FloatPoint(x * invW, y * invW); 48 return gfx::PointF(x * invW, y * invW);
45 } 49 }
46 50
47 FloatPoint3D cartesianPoint3d() const 51 FloatPoint3D cartesianPoint3d() const
48 { 52 {
49 if (w == 1) 53 if (w == 1)
50 return FloatPoint3D(x, y, z); 54 return FloatPoint3D(x, y, z);
51 55
52 // For now, because this code is used privately only by MathUtil, it sho uld never be called when w == 0, and we do not yet need to handle that case. 56 // For now, because this code is used privately only by MathUtil, it sho uld never be called when w == 0, and we do not yet need to handle that case.
53 DCHECK(w); 57 DCHECK(w);
54 double invW = 1.0 / w; 58 double invW = 1.0 / w;
(...skipping 10 matching lines...) Expand all
65 public: 69 public:
66 70
67 // Background: WebTransformationMatrix code in WebCore does not do the right thing in 71 // Background: WebTransformationMatrix code in WebCore does not do the right thing in
68 // mapRect / mapQuad / projectQuad when there is a perspective projection th at causes 72 // mapRect / mapQuad / projectQuad when there is a perspective projection th at causes
69 // one of the transformed vertices to go to w < 0. In those cases, it is nec essary to 73 // one of the transformed vertices to go to w < 0. In those cases, it is nec essary to
70 // perform clipping in homogeneous coordinates, after applying the transform , before 74 // perform clipping in homogeneous coordinates, after applying the transform , before
71 // dividing-by-w to convert to cartesian coordinates. 75 // dividing-by-w to convert to cartesian coordinates.
72 // 76 //
73 // These functions return the axis-aligned rect that encloses the correctly clipped, 77 // These functions return the axis-aligned rect that encloses the correctly clipped,
74 // transformed polygon. 78 // transformed polygon.
75 static IntRect mapClippedRect(const WebKit::WebTransformationMatrix&, const IntRect&); 79 static gfx::Rect mapClippedRect(const WebKit::WebTransformationMatrix&, cons t gfx::Rect&);
76 static FloatRect mapClippedRect(const WebKit::WebTransformationMatrix&, cons t FloatRect&); 80 static gfx::RectF mapClippedRect(const WebKit::WebTransformationMatrix&, con st gfx::RectF&);
77 static FloatRect projectClippedRect(const WebKit::WebTransformationMatrix&, const FloatRect&); 81 static gfx::RectF projectClippedRect(const WebKit::WebTransformationMatrix&, const gfx::RectF&);
78 82
79 // Returns an array of vertices that represent the clipped polygon. After re turning, indexes from 83 // Returns an array of vertices that represent the clipped polygon. After re turning, indexes from
80 // 0 to numVerticesInClippedQuad are valid in the clippedQuad array. Note th at 84 // 0 to numVerticesInClippedQuad are valid in the clippedQuad array. Note th at
81 // numVerticesInClippedQuad may be zero, which means the entire quad was cli pped, and 85 // numVerticesInClippedQuad may be zero, which means the entire quad was cli pped, and
82 // none of the vertices in the array are valid. 86 // none of the vertices in the array are valid.
83 static void mapClippedQuad(const WebKit::WebTransformationMatrix&, const Flo atQuad& srcQuad, FloatPoint clippedQuad[8], int& numVerticesInClippedQuad); 87 static void mapClippedQuad(const WebKit::WebTransformationMatrix&, const Flo atQuad& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad);
84 88
85 static FloatRect computeEnclosingRectOfVertices(FloatPoint vertices[], int n umVertices); 89 static gfx::RectF computeEnclosingRectOfVertices(gfx::PointF vertices[], int numVertices);
86 static FloatRect computeEnclosingClippedRect(const HomogeneousCoordinate& h1 , const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homoge neousCoordinate& h4); 90 static gfx::RectF computeEnclosingClippedRect(const HomogeneousCoordinate& h 1, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homog eneousCoordinate& h4);
87 91
88 // NOTE: These functions do not do correct clipping against w = 0 plane, but they 92 // NOTE: These functions do not do correct clipping against w = 0 plane, but they
89 // correctly detect the clipped condition via the boolean clipped. 93 // correctly detect the clipped condition via the boolean clipped.
90 static FloatQuad mapQuad(const WebKit::WebTransformationMatrix&, const Float Quad&, bool& clipped); 94 static FloatQuad mapQuad(const WebKit::WebTransformationMatrix&, const Float Quad&, bool& clipped);
91 static FloatPoint mapPoint(const WebKit::WebTransformationMatrix&, const Flo atPoint&, bool& clipped); 95 static gfx::PointF mapPoint(const WebKit::WebTransformationMatrix&, const gf x::PointF&, bool& clipped);
92 static FloatPoint3D mapPoint(const WebKit::WebTransformationMatrix&, const F loatPoint3D&, bool& clipped); 96 static FloatPoint3D mapPoint(const WebKit::WebTransformationMatrix&, const F loatPoint3D&, bool& clipped);
93 static FloatQuad projectQuad(const WebKit::WebTransformationMatrix&, const F loatQuad&, bool& clipped); 97 static FloatQuad projectQuad(const WebKit::WebTransformationMatrix&, const F loatQuad&, bool& clipped);
94 static FloatPoint projectPoint(const WebKit::WebTransformationMatrix&, const FloatPoint&, bool& clipped); 98 static gfx::PointF projectPoint(const WebKit::WebTransformationMatrix&, cons t gfx::PointF&, bool& clipped);
95 99
96 static void flattenTransformTo2d(WebKit::WebTransformationMatrix&); 100 static void flattenTransformTo2d(WebKit::WebTransformationMatrix&);
97 101
98 static FloatPoint computeTransform2dScaleComponents(const WebKit::WebTransfo rmationMatrix&); 102 static gfx::Vector2dF computeTransform2dScaleComponents(const WebKit::WebTra nsformationMatrix&);
99 103
100 // Returns the smallest angle between the given two vectors in degrees. Neit her vector is 104 // Returns the smallest angle between the given two vectors in degrees. Neit her vector is
101 // assumed to be normalized. 105 // assumed to be normalized.
102 static float smallestAngleBetweenVectors(const FloatSize&, const FloatSize&) ; 106 static float smallestAngleBetweenVectors(const FloatSize&, const FloatSize&) ;
103 107
104 // Projects the |source| vector onto |destination|. Neither vector is assume d to be normalized. 108 // Projects the |source| vector onto |destination|. Neither vector is assume d to be normalized.
105 static FloatSize projectVector(const FloatSize& source, const FloatSize& des tination); 109 static FloatSize projectVector(const FloatSize& source, const FloatSize& des tination);
106 }; 110 };
107 111
108 } // namespace cc 112 } // namespace cc
109 113
110 #endif // #define CCMathUtil_h 114 #endif // #define CCMathUtil_h
OLDNEW
« no previous file with comments | « cc/layer_unittest.cc ('k') | cc/math_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698