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 #ifndef CC_MATH_UTIL_H_ | 5 #ifndef CC_MATH_UTIL_H_ |
6 #define CC_MATH_UTIL_H_ | 6 #define CC_MATH_UTIL_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "cc/cc_export.h" | 9 #include "cc/cc_export.h" |
10 #include "ui/gfx/point_f.h" | 10 #include "ui/gfx/point_f.h" |
11 #include "ui/gfx/point3_f.h" | 11 #include "ui/gfx/point3_f.h" |
| 12 #include "ui/gfx/transform.h" |
12 | 13 |
13 namespace WebKit { | 14 namespace WebKit { |
14 class WebTransformationMatrix; | 15 class WebTransformationMatrix; |
15 } | 16 } |
16 | 17 |
17 namespace gfx { | 18 namespace gfx { |
18 class QuadF; | 19 class QuadF; |
19 class Rect; | 20 class Rect; |
20 class RectF; | 21 class RectF; |
21 class Vector2dF; | 22 class Vector2dF; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 double x; | 63 double x; |
63 double y; | 64 double y; |
64 double z; | 65 double z; |
65 double w; | 66 double w; |
66 }; | 67 }; |
67 | 68 |
68 class CC_EXPORT MathUtil { | 69 class CC_EXPORT MathUtil { |
69 public: | 70 public: |
70 static const double PI_DOUBLE; | 71 static const double PI_DOUBLE; |
71 static const float PI_FLOAT; | 72 static const float PI_FLOAT; |
| 73 static const double EPSILON; |
72 | 74 |
73 static double Deg2Rad(double deg) { return deg * PI_DOUBLE / 180; } | 75 static double Deg2Rad(double deg) { return deg * PI_DOUBLE / 180; } |
74 static double Rad2Deg(double rad) { return rad * 180 / PI_DOUBLE; } | 76 static double Rad2Deg(double rad) { return rad * 180 / PI_DOUBLE; } |
75 | 77 |
76 static float Deg2Rad(float deg) { return deg * PI_FLOAT / 180; } | 78 static float Deg2Rad(float deg) { return deg * PI_FLOAT / 180; } |
77 static float Rad2Deg(float rad) { return rad * 180 / PI_FLOAT; } | 79 static float Rad2Deg(float rad) { return rad * 180 / PI_FLOAT; } |
78 | 80 |
79 // Background: WebTransformationMatrix code in WebCore does not do the right
thing in | 81 // Background: WebTransformationMatrix code in WebCore does not do the right
thing in |
80 // mapRect / mapQuad / projectQuad when there is a perspective projection th
at causes | 82 // mapRect / mapQuad / projectQuad when there is a perspective projection th
at causes |
81 // one of the transformed vertices to go to w < 0. In those cases, it is nec
essary to | 83 // one of the transformed vertices to go to w < 0. In those cases, it is nec
essary to |
(...skipping 26 matching lines...) Expand all Loading... |
108 static void flattenTransformTo2d(WebKit::WebTransformationMatrix&); | 110 static void flattenTransformTo2d(WebKit::WebTransformationMatrix&); |
109 | 111 |
110 static gfx::Vector2dF computeTransform2dScaleComponents(const WebKit::WebTra
nsformationMatrix&); | 112 static gfx::Vector2dF computeTransform2dScaleComponents(const WebKit::WebTra
nsformationMatrix&); |
111 | 113 |
112 // Returns the smallest angle between the given two vectors in degrees. Neit
her vector is | 114 // Returns the smallest angle between the given two vectors in degrees. Neit
her vector is |
113 // assumed to be normalized. | 115 // assumed to be normalized. |
114 static float smallestAngleBetweenVectors(gfx::Vector2dF, gfx::Vector2dF); | 116 static float smallestAngleBetweenVectors(gfx::Vector2dF, gfx::Vector2dF); |
115 | 117 |
116 // Projects the |source| vector onto |destination|. Neither vector is assume
d to be normalized. | 118 // Projects the |source| vector onto |destination|. Neither vector is assume
d to be normalized. |
117 static gfx::Vector2dF projectVector(gfx::Vector2dF source, gfx::Vector2dF de
stination); | 119 static gfx::Vector2dF projectVector(gfx::Vector2dF source, gfx::Vector2dF de
stination); |
| 120 |
| 121 // Temporary API to ease migration from WebKit::WebTransformationMatrix |
| 122 // to gfx::Transform. |
| 123 // |
| 124 // TODO(shawnsingh, vollick) we should phase out as much as possible of |
| 125 // these temporary functions, putting functionality into gfx::Transform. |
| 126 static bool isInvertible(const gfx::Transform&); |
| 127 static bool isBackFaceVisible(const gfx::Transform&); |
| 128 static bool isIdentity(const gfx::Transform&); |
| 129 static bool isIdentityOrTranslation(const gfx::Transform&); |
| 130 static bool hasPerspective(const gfx::Transform&); |
| 131 static void makeIdentity(gfx::Transform*); |
| 132 static void rotateEulerAngles(gfx::Transform*, double eulerX, double eulerY,
double eulerZ); |
| 133 static void rotateAxisAngle(gfx::Transform*, double i, double j, double k, d
ouble degrees); |
| 134 static gfx::Transform inverse(const gfx::Transform&); |
| 135 static gfx::Transform to2dTransform(const gfx::Transform&); |
| 136 // Note carefully: the args here are labeled as per Webcore indexing convent
ions. |
| 137 static gfx::Transform createGfxTransform(double m11, double m12, double m13,
double m14, |
| 138 double m21, double m22, double m23,
double m24, |
| 139 double m31, double m32, double m33,
double m34, |
| 140 double m41, double m42, double m43,
double m44); |
| 141 |
| 142 static gfx::Transform createGfxTransform(double a, double b, double c, |
| 143 double d, double e, double f); |
118 }; | 144 }; |
119 | 145 |
| 146 // TODO(shawnsingh, vollick) this is a temporary home, should eventually |
| 147 // be phased out in favor of gfx::Transform API. |
| 148 gfx::Transform CC_EXPORT operator*(const gfx::Transform&, const gfx::Transform&)
; |
| 149 |
120 } // namespace cc | 150 } // namespace cc |
121 | 151 |
122 #endif // CC_MATH_UTIL_H_ | 152 #endif // CC_MATH_UTIL_H_ |
OLD | NEW |