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 #include "cc/base/math_util.h" | 5 #include "cc/base/math_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 float* ymax, | 128 float* ymax, |
129 gfx::PointF p) { | 129 gfx::PointF p) { |
130 *xmin = std::min(p.x(), *xmin); | 130 *xmin = std::min(p.x(), *xmin); |
131 *xmax = std::max(p.x(), *xmax); | 131 *xmax = std::max(p.x(), *xmax); |
132 *ymin = std::min(p.y(), *ymin); | 132 *ymin = std::min(p.y(), *ymin); |
133 *ymax = std::max(p.y(), *ymax); | 133 *ymax = std::max(p.y(), *ymax); |
134 } | 134 } |
135 | 135 |
136 static inline void AddVertexToClippedQuad(gfx::PointF new_vertex, | 136 static inline void AddVertexToClippedQuad(gfx::PointF new_vertex, |
137 gfx::PointF clipped_quad[8], | 137 gfx::PointF clipped_quad[8], |
138 int& num_vertices_in_clipped_quad) { | 138 int* num_vertices_in_clipped_quad) { |
139 clipped_quad[num_vertices_in_clipped_quad] = new_vertex; | 139 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
140 num_vertices_in_clipped_quad++; | 140 (*num_vertices_in_clipped_quad)++; |
141 } | 141 } |
142 | 142 |
143 gfx::Rect MathUtil::MapClippedRect(const gfx::Transform& transform, | 143 gfx::Rect MathUtil::MapClippedRect(const gfx::Transform& transform, |
144 gfx::Rect src_rect) { | 144 gfx::Rect src_rect) { |
145 return gfx::ToEnclosingRect(MapClippedRect(transform, gfx::RectF(src_rect))); | 145 return gfx::ToEnclosingRect(MapClippedRect(transform, gfx::RectF(src_rect))); |
146 } | 146 } |
147 | 147 |
148 gfx::RectF MathUtil::MapClippedRect(const gfx::Transform& transform, | 148 gfx::RectF MathUtil::MapClippedRect(const gfx::Transform& transform, |
149 const gfx::RectF& src_rect) { | 149 const gfx::RectF& src_rect) { |
150 if (transform.IsIdentityOrTranslation()) | 150 if (transform.IsIdentityOrTranslation()) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 HomogeneousCoordinate h2 = ProjectHomogeneousPoint(transform, q.p2()); | 190 HomogeneousCoordinate h2 = ProjectHomogeneousPoint(transform, q.p2()); |
191 HomogeneousCoordinate h3 = ProjectHomogeneousPoint(transform, q.p3()); | 191 HomogeneousCoordinate h3 = ProjectHomogeneousPoint(transform, q.p3()); |
192 HomogeneousCoordinate h4 = ProjectHomogeneousPoint(transform, q.p4()); | 192 HomogeneousCoordinate h4 = ProjectHomogeneousPoint(transform, q.p4()); |
193 | 193 |
194 return ComputeEnclosingClippedRect(h1, h2, h3, h4); | 194 return ComputeEnclosingClippedRect(h1, h2, h3, h4); |
195 } | 195 } |
196 | 196 |
197 void MathUtil::MapClippedQuad(const gfx::Transform& transform, | 197 void MathUtil::MapClippedQuad(const gfx::Transform& transform, |
198 const gfx::QuadF& src_quad, | 198 const gfx::QuadF& src_quad, |
199 gfx::PointF clipped_quad[8], | 199 gfx::PointF clipped_quad[8], |
200 int& num_vertices_in_clipped_quad) { | 200 int* num_vertices_in_clipped_quad) { |
201 HomogeneousCoordinate h1 = | 201 HomogeneousCoordinate h1 = |
202 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p1())); | 202 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p1())); |
203 HomogeneousCoordinate h2 = | 203 HomogeneousCoordinate h2 = |
204 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p2())); | 204 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p2())); |
205 HomogeneousCoordinate h3 = | 205 HomogeneousCoordinate h3 = |
206 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p3())); | 206 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p3())); |
207 HomogeneousCoordinate h4 = | 207 HomogeneousCoordinate h4 = |
208 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p4())); | 208 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p4())); |
209 | 209 |
210 // The order of adding the vertices to the array is chosen so that | 210 // The order of adding the vertices to the array is chosen so that |
211 // clockwise / counter-clockwise orientation is retained. | 211 // clockwise / counter-clockwise orientation is retained. |
212 | 212 |
213 num_vertices_in_clipped_quad = 0; | 213 *num_vertices_in_clipped_quad = 0; |
214 | 214 |
215 if (!h1.ShouldBeClipped()) { | 215 if (!h1.ShouldBeClipped()) { |
216 AddVertexToClippedQuad( | 216 AddVertexToClippedQuad( |
217 h1.CartesianPoint2d(), clipped_quad, num_vertices_in_clipped_quad); | 217 h1.CartesianPoint2d(), clipped_quad, num_vertices_in_clipped_quad); |
218 } | 218 } |
219 | 219 |
220 if (h1.ShouldBeClipped() ^ h2.ShouldBeClipped()) { | 220 if (h1.ShouldBeClipped() ^ h2.ShouldBeClipped()) { |
221 AddVertexToClippedQuad( | 221 AddVertexToClippedQuad( |
222 ComputeClippedPointForEdge(h1, h2).CartesianPoint2d(), | 222 ComputeClippedPointForEdge(h1, h2).CartesianPoint2d(), |
223 clipped_quad, | 223 clipped_quad, |
(...skipping 29 matching lines...) Expand all Loading... |
253 h4.CartesianPoint2d(), clipped_quad, num_vertices_in_clipped_quad); | 253 h4.CartesianPoint2d(), clipped_quad, num_vertices_in_clipped_quad); |
254 } | 254 } |
255 | 255 |
256 if (h4.ShouldBeClipped() ^ h1.ShouldBeClipped()) { | 256 if (h4.ShouldBeClipped() ^ h1.ShouldBeClipped()) { |
257 AddVertexToClippedQuad( | 257 AddVertexToClippedQuad( |
258 ComputeClippedPointForEdge(h4, h1).CartesianPoint2d(), | 258 ComputeClippedPointForEdge(h4, h1).CartesianPoint2d(), |
259 clipped_quad, | 259 clipped_quad, |
260 num_vertices_in_clipped_quad); | 260 num_vertices_in_clipped_quad); |
261 } | 261 } |
262 | 262 |
263 DCHECK_LE(num_vertices_in_clipped_quad, 8); | 263 DCHECK_LE(*num_vertices_in_clipped_quad, 8); |
264 } | 264 } |
265 | 265 |
266 gfx::RectF MathUtil::ComputeEnclosingRectOfVertices(gfx::PointF vertices[], | 266 gfx::RectF MathUtil::ComputeEnclosingRectOfVertices(gfx::PointF vertices[], |
267 int num_vertices) { | 267 int num_vertices) { |
268 if (num_vertices < 2) | 268 if (num_vertices < 2) |
269 return gfx::RectF(); | 269 return gfx::RectF(); |
270 | 270 |
271 float xmin = std::numeric_limits<float>::max(); | 271 float xmin = std::numeric_limits<float>::max(); |
272 float xmax = -std::numeric_limits<float>::max(); | 272 float xmax = -std::numeric_limits<float>::max(); |
273 float ymin = std::numeric_limits<float>::max(); | 273 float ymin = std::numeric_limits<float>::max(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 546 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
547 std::min(value, std::numeric_limits<double>::max()))); | 547 std::min(value, std::numeric_limits<double>::max()))); |
548 } | 548 } |
549 | 549 |
550 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { | 550 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { |
551 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( | 551 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( |
552 std::min(value, std::numeric_limits<float>::max()))); | 552 std::min(value, std::numeric_limits<float>::max()))); |
553 } | 553 } |
554 | 554 |
555 } // namespace cc | 555 } // namespace cc |
OLD | NEW |