| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 gfx::Transform transform; | 568 gfx::Transform transform; |
| 569 transform.MakeIdentity(); | 569 transform.MakeIdentity(); |
| 570 transform.ApplyPerspectiveDepth(50.0); | 570 transform.ApplyPerspectiveDepth(50.0); |
| 571 transform.RotateAboutYAxis(89.0); | 571 transform.RotateAboutYAxis(89.0); |
| 572 // We are amost looking along the X-Y plane from (-50, almost 0) | 572 // We are amost looking along the X-Y plane from (-50, almost 0) |
| 573 | 573 |
| 574 gfx::QuadF src_quad(gfx::PointF(0.0f, 100.0f), gfx::PointF(0.0f, -100.0f), | 574 gfx::QuadF src_quad(gfx::PointF(0.0f, 100.0f), gfx::PointF(0.0f, -100.0f), |
| 575 gfx::PointF(-99.0f, -300.0f), | 575 gfx::PointF(-99.0f, -300.0f), |
| 576 gfx::PointF(-99.0f, -100.0f)); | 576 gfx::PointF(-99.0f, -100.0f)); |
| 577 | 577 |
| 578 gfx::PointF clipped_quad[8]; | 578 gfx::Point3F clipped_quad[8]; |
| 579 int num_vertices_in_clipped_quad; | 579 int num_vertices_in_clipped_quad; |
| 580 | 580 |
| 581 MathUtil::MapClippedQuad(transform, src_quad, clipped_quad, | 581 MathUtil::MapClippedQuad3d(transform, src_quad, clipped_quad, |
| 582 &num_vertices_in_clipped_quad); | 582 &num_vertices_in_clipped_quad); |
| 583 | 583 |
| 584 EXPECT_EQ(num_vertices_in_clipped_quad, 3); | 584 EXPECT_EQ(num_vertices_in_clipped_quad, 3); |
| 585 } | 585 } |
| 586 | 586 |
| 587 // This takes a quad for which two points, (at x = -99) are behind and below | 587 // This takes a quad for which two points, (at x = -99) are behind and below |
| 588 // the eyepoint and checks to make sure we build a triangle. We used to build | 588 // the eyepoint and checks to make sure we build a triangle. We used to build |
| 589 // a degenerate quad. The quirk here is that the two shared points are first | 589 // a degenerate quad. The quirk here is that the two shared points are first |
| 590 // and last, not sequential. | 590 // and last, not sequential. |
| 591 TEST(MathUtilTest, MapClippedQuadDuplicateTriangleWrapped) { | 591 TEST(MathUtilTest, MapClippedQuadDuplicateTriangleWrapped) { |
| 592 gfx::Transform transform; | 592 gfx::Transform transform; |
| 593 transform.MakeIdentity(); | 593 transform.MakeIdentity(); |
| 594 transform.ApplyPerspectiveDepth(50.0); | 594 transform.ApplyPerspectiveDepth(50.0); |
| 595 transform.RotateAboutYAxis(89.0); | 595 transform.RotateAboutYAxis(89.0); |
| 596 | 596 |
| 597 gfx::QuadF src_quad(gfx::PointF(-99.0f, -100.0f), gfx::PointF(0.0f, 100.0f), | 597 gfx::QuadF src_quad(gfx::PointF(-99.0f, -100.0f), gfx::PointF(0.0f, 100.0f), |
| 598 gfx::PointF(0.0f, -100.0f), gfx::PointF(-99.0f, -300.0f)); | 598 gfx::PointF(0.0f, -100.0f), gfx::PointF(-99.0f, -300.0f)); |
| 599 | 599 |
| 600 gfx::PointF clipped_quad[8]; | 600 gfx::Point3F clipped_quad[8]; |
| 601 int num_vertices_in_clipped_quad; | 601 int num_vertices_in_clipped_quad; |
| 602 | 602 |
| 603 MathUtil::MapClippedQuad(transform, src_quad, clipped_quad, | 603 MathUtil::MapClippedQuad3d(transform, src_quad, clipped_quad, |
| 604 &num_vertices_in_clipped_quad); | 604 &num_vertices_in_clipped_quad); |
| 605 | 605 |
| 606 EXPECT_EQ(num_vertices_in_clipped_quad, 3); | 606 EXPECT_EQ(num_vertices_in_clipped_quad, 3); |
| 607 } | 607 } |
| 608 | 608 |
| 609 // Here we map and clip a quad with only one point that disappears to infinity | 609 // Here we map and clip a quad with only one point that disappears to infinity |
| 610 // behind us. We don't want two vertices at infinity crossing in and out | 610 // behind us. We don't want two vertices at infinity crossing in and out |
| 611 // of w < 0 space. | 611 // of w < 0 space. |
| 612 TEST(MathUtilTest, MapClippedQuadDuplicateQuad) { | 612 TEST(MathUtilTest, MapClippedQuadDuplicateQuad) { |
| 613 gfx::Transform transform; | 613 gfx::Transform transform; |
| 614 transform.MakeIdentity(); | 614 transform.MakeIdentity(); |
| 615 transform.ApplyPerspectiveDepth(50.0); | 615 transform.ApplyPerspectiveDepth(50.0); |
| 616 transform.RotateAboutYAxis(89.0); | 616 transform.RotateAboutYAxis(89.0); |
| 617 | 617 |
| 618 gfx::QuadF src_quad(gfx::PointF(0.0f, 100.0f), gfx::PointF(400.0f, 0.0f), | 618 gfx::QuadF src_quad(gfx::PointF(0.0f, 100.0f), gfx::PointF(400.0f, 0.0f), |
| 619 gfx::PointF(0.0f, -100.0f), gfx::PointF(-99.0f, -300.0f)); | 619 gfx::PointF(0.0f, -100.0f), gfx::PointF(-99.0f, -300.0f)); |
| 620 | 620 |
| 621 gfx::PointF clipped_quad[8]; | 621 gfx::Point3F clipped_quad[8]; |
| 622 int num_vertices_in_clipped_quad; | 622 int num_vertices_in_clipped_quad; |
| 623 | 623 |
| 624 MathUtil::MapClippedQuad(transform, src_quad, clipped_quad, | 624 MathUtil::MapClippedQuad3d(transform, src_quad, clipped_quad, |
| 625 &num_vertices_in_clipped_quad); | 625 &num_vertices_in_clipped_quad); |
| 626 | 626 |
| 627 EXPECT_EQ(num_vertices_in_clipped_quad, 4); | 627 EXPECT_EQ(num_vertices_in_clipped_quad, 4); |
| 628 } | 628 } |
| 629 | 629 |
| 630 } // namespace | 630 } // namespace |
| 631 } // namespace cc | 631 } // namespace cc |
| OLD | NEW |