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_BASE_MATH_UTIL_H_ | 5 #ifndef CC_BASE_MATH_UTIL_H_ |
6 #define CC_BASE_MATH_UTIL_H_ | 6 #define CC_BASE_MATH_UTIL_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <vector> | 10 #include <vector> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 // Background: Existing transform code does not do the right thing in | 101 // Background: Existing transform code does not do the right thing in |
102 // MapRect / MapQuad / ProjectQuad when there is a perspective projection that | 102 // MapRect / MapQuad / ProjectQuad when there is a perspective projection that |
103 // causes one of the transformed vertices to go to w < 0. In those cases, it | 103 // causes one of the transformed vertices to go to w < 0. In those cases, it |
104 // is necessary to perform clipping in homogeneous coordinates, after applying | 104 // is necessary to perform clipping in homogeneous coordinates, after applying |
105 // the transform, before dividing-by-w to convert to cartesian coordinates. | 105 // the transform, before dividing-by-w to convert to cartesian coordinates. |
106 // | 106 // |
107 // These functions return the axis-aligned rect that encloses the correctly | 107 // These functions return the axis-aligned rect that encloses the correctly |
108 // clipped, transformed polygon. | 108 // clipped, transformed polygon. |
109 static gfx::Rect MapEnclosingClippedRect(const gfx::Transform& transform, | 109 static gfx::Rect MapEnclosingClippedRect(const gfx::Transform& transform, |
110 const gfx::Rect& rect); | 110 const gfx::Rect& rect); |
111 static gfx::Rect MapEnclosedClippedRect(const gfx::Transform& transform, | |
112 const gfx::Rect& rect); | |
111 static gfx::RectF MapClippedRect(const gfx::Transform& transform, | 113 static gfx::RectF MapClippedRect(const gfx::Transform& transform, |
112 const gfx::RectF& rect); | 114 const gfx::RectF& rect); |
113 static gfx::Rect ProjectEnclosingClippedRect(const gfx::Transform& transform, | 115 static gfx::Rect ProjectEnclosingClippedRect(const gfx::Transform& transform, |
114 const gfx::Rect& rect); | 116 const gfx::Rect& rect); |
117 static gfx::Rect ProjectEnclosedClippedRect(const gfx::Transform& transform, | |
118 const gfx::Rect& rect); | |
115 static gfx::RectF ProjectClippedRect(const gfx::Transform& transform, | 119 static gfx::RectF ProjectClippedRect(const gfx::Transform& transform, |
116 const gfx::RectF& rect); | 120 const gfx::RectF& rect); |
117 | 121 |
122 // These functions are only valid to call for inputs where it is known they | |
123 // will not require clipping in homogeneous coordinates. | |
124 static gfx::Rect MapEnclosedNonClippedRect(const gfx::Transform& transform, | |
enne (OOO)
2014/08/21 17:54:05
Is it worth having unit tests for these functions?
danakj
2014/08/21 17:58:08
Ya I will write tests but I am not happy with the
| |
125 const gfx::Rect& rect); | |
126 static gfx::Rect ProjectEnclosedNonClippedRect( | |
127 const gfx::Transform& transform, | |
128 const gfx::Rect& rect); | |
129 | |
118 // Returns an array of vertices that represent the clipped polygon. After | 130 // Returns an array of vertices that represent the clipped polygon. After |
119 // returning, indexes from 0 to num_vertices_in_clipped_quad are valid in the | 131 // returning, indexes from 0 to num_vertices_in_clipped_quad are valid in the |
120 // clipped_quad array. Note that num_vertices_in_clipped_quad may be zero, | 132 // clipped_quad array. Note that num_vertices_in_clipped_quad may be zero, |
121 // which means the entire quad was clipped, and none of the vertices in the | 133 // which means the entire quad was clipped, and none of the vertices in the |
122 // array are valid. | 134 // array are valid. |
123 static void MapClippedQuad(const gfx::Transform& transform, | 135 static void MapClippedQuad(const gfx::Transform& transform, |
124 const gfx::QuadF& src_quad, | 136 const gfx::QuadF& src_quad, |
125 gfx::PointF clipped_quad[8], | 137 gfx::PointF clipped_quad[8], |
126 int* num_vertices_in_clipped_quad); | 138 int* num_vertices_in_clipped_quad); |
127 static bool MapClippedQuad3d(const gfx::Transform& transform, | 139 static bool MapClippedQuad3d(const gfx::Transform& transform, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 229 |
218 // Returns a base::Value representation of the floating point value. | 230 // Returns a base::Value representation of the floating point value. |
219 // If the value is inf, returns max double/float representation. | 231 // If the value is inf, returns max double/float representation. |
220 static double AsDoubleSafely(double value); | 232 static double AsDoubleSafely(double value); |
221 static float AsFloatSafely(float value); | 233 static float AsFloatSafely(float value); |
222 }; | 234 }; |
223 | 235 |
224 } // namespace cc | 236 } // namespace cc |
225 | 237 |
226 #endif // CC_BASE_MATH_UTIL_H_ | 238 #endif // CC_BASE_MATH_UTIL_H_ |
OLD | NEW |