Chromium Code Reviews| 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 #ifdef __SSE__ | 10 #ifdef __SSE__ |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 return IsNearlyTheSame(lhs.x(), rhs.x()) && IsNearlyTheSame(lhs.y(), rhs.y()); | 171 return IsNearlyTheSame(lhs.x(), rhs.x()) && IsNearlyTheSame(lhs.y(), rhs.y()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 static inline bool IsNearlyTheSame(const gfx::Point3F& lhs, | 174 static inline bool IsNearlyTheSame(const gfx::Point3F& lhs, |
| 175 const gfx::Point3F& rhs) { | 175 const gfx::Point3F& rhs) { |
| 176 return IsNearlyTheSame(lhs.x(), rhs.x()) && | 176 return IsNearlyTheSame(lhs.x(), rhs.x()) && |
| 177 IsNearlyTheSame(lhs.y(), rhs.y()) && IsNearlyTheSame(lhs.z(), rhs.z()); | 177 IsNearlyTheSame(lhs.y(), rhs.y()) && IsNearlyTheSame(lhs.z(), rhs.z()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, | 180 static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, |
| 181 gfx::Point3F clipped_quad[8], | 181 gfx::Point3F clipped_quad[6], |
| 182 int* num_vertices_in_clipped_quad) { | 182 int* num_vertices_in_clipped_quad) { |
| 183 if (*num_vertices_in_clipped_quad > 0 && | 183 if (*num_vertices_in_clipped_quad > 0 && |
| 184 IsNearlyTheSame(clipped_quad[*num_vertices_in_clipped_quad - 1], | 184 IsNearlyTheSame(clipped_quad[*num_vertices_in_clipped_quad - 1], |
| 185 new_vertex)) | 185 new_vertex)) |
| 186 return; | 186 return; |
| 187 | 187 |
| 188 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; | 188 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
| 189 (*num_vertices_in_clipped_quad)++; | 189 (*num_vertices_in_clipped_quad)++; |
| 190 } | 190 } |
| 191 | 191 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 DCHECK(!hc0.ShouldBeClipped()); | 302 DCHECK(!hc0.ShouldBeClipped()); |
| 303 DCHECK(!hc1.ShouldBeClipped()); | 303 DCHECK(!hc1.ShouldBeClipped()); |
| 304 | 304 |
| 305 gfx::PointF top_left(hc0.CartesianPoint2d()); | 305 gfx::PointF top_left(hc0.CartesianPoint2d()); |
| 306 gfx::PointF bottom_right(hc1.CartesianPoint2d()); | 306 gfx::PointF bottom_right(hc1.CartesianPoint2d()); |
| 307 return gfx::ToEnclosedRect(gfx::BoundingRect(top_left, bottom_right)); | 307 return gfx::ToEnclosedRect(gfx::BoundingRect(top_left, bottom_right)); |
| 308 } | 308 } |
| 309 | 309 |
| 310 bool MathUtil::MapClippedQuad3d(const gfx::Transform& transform, | 310 bool MathUtil::MapClippedQuad3d(const gfx::Transform& transform, |
| 311 const gfx::QuadF& src_quad, | 311 const gfx::QuadF& src_quad, |
| 312 gfx::Point3F clipped_quad[8], | 312 gfx::Point3F clipped_quad[6], |
| 313 int* num_vertices_in_clipped_quad) { | 313 int* num_vertices_in_clipped_quad) { |
| 314 HomogeneousCoordinate h1 = | 314 HomogeneousCoordinate h1 = |
| 315 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p1())); | 315 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p1())); |
| 316 HomogeneousCoordinate h2 = | 316 HomogeneousCoordinate h2 = |
| 317 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p2())); | 317 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p2())); |
| 318 HomogeneousCoordinate h3 = | 318 HomogeneousCoordinate h3 = |
| 319 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p3())); | 319 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p3())); |
| 320 HomogeneousCoordinate h4 = | 320 HomogeneousCoordinate h4 = |
| 321 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p4())); | 321 MapHomogeneousPoint(transform, gfx::Point3F(src_quad.p4())); |
| 322 | 322 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 if (h4.ShouldBeClipped() ^ h1.ShouldBeClipped()) { | 363 if (h4.ShouldBeClipped() ^ h1.ShouldBeClipped()) { |
| 364 AddVertexToClippedQuad3d(ComputeClippedCartesianPoint3dForEdge(h4, h1), | 364 AddVertexToClippedQuad3d(ComputeClippedCartesianPoint3dForEdge(h4, h1), |
| 365 clipped_quad, num_vertices_in_clipped_quad); | 365 clipped_quad, num_vertices_in_clipped_quad); |
| 366 } | 366 } |
| 367 | 367 |
| 368 if (*num_vertices_in_clipped_quad > 2 && | 368 if (*num_vertices_in_clipped_quad > 2 && |
| 369 IsNearlyTheSame(clipped_quad[0], | 369 IsNearlyTheSame(clipped_quad[0], |
| 370 clipped_quad[*num_vertices_in_clipped_quad - 1])) | 370 clipped_quad[*num_vertices_in_clipped_quad - 1])) |
| 371 *num_vertices_in_clipped_quad -= 1; | 371 *num_vertices_in_clipped_quad -= 1; |
| 372 | 372 |
| 373 DCHECK_LE(*num_vertices_in_clipped_quad, 8); | 373 DCHECK_LE(*num_vertices_in_clipped_quad, 6); |
|
flackr
2017/01/12 16:59:11
I'm concerned with the DCHECK that if we got this
danakj
2017/01/12 17:01:19
Can we not just find a provably correct number?
| |
| 374 return (*num_vertices_in_clipped_quad >= 4); | 374 return (*num_vertices_in_clipped_quad >= 4); |
| 375 } | 375 } |
| 376 | 376 |
| 377 gfx::RectF MathUtil::ComputeEnclosingRectOfVertices( | 377 gfx::RectF MathUtil::ComputeEnclosingRectOfVertices( |
| 378 const gfx::PointF vertices[], | 378 const gfx::PointF vertices[], |
| 379 int num_vertices) { | 379 int num_vertices) { |
| 380 if (num_vertices < 2) | 380 if (num_vertices < 2) |
| 381 return gfx::RectF(); | 381 return gfx::RectF(); |
| 382 | 382 |
| 383 float xmin = std::numeric_limits<float>::max(); | 383 float xmin = std::numeric_limits<float>::max(); |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 const gfx::PointF& right) { | 907 const gfx::PointF& right) { |
| 908 return IsNearlyTheSame(left, right); | 908 return IsNearlyTheSame(left, right); |
| 909 } | 909 } |
| 910 | 910 |
| 911 bool MathUtil::IsNearlyTheSameForTesting(const gfx::Point3F& left, | 911 bool MathUtil::IsNearlyTheSameForTesting(const gfx::Point3F& left, |
| 912 const gfx::Point3F& right) { | 912 const gfx::Point3F& right) { |
| 913 return IsNearlyTheSame(left, right); | 913 return IsNearlyTheSame(left, right); |
| 914 } | 914 } |
| 915 | 915 |
| 916 } // namespace cc | 916 } // namespace cc |
| OLD | NEW |