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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| 11 #include "cc/test/geometry_test_utils.h" | 11 #include "cc/test/geometry_test_utils.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/geometry/quad_f.h" | |
| 14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/geometry/rect_f.h" | 16 #include "ui/gfx/geometry/rect_f.h" |
| 16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 TEST(MathUtilTest, ProjectionOfPerpendicularPlane) { | 22 TEST(MathUtilTest, ProjectionOfPerpendicularPlane) { |
| 22 // In this case, the m33() element of the transform becomes zero, which could | 23 // In this case, the m33() element of the transform becomes zero, which could |
| 23 // cause a divide-by-zero when projecting points/quads. | 24 // cause a divide-by-zero when projecting points/quads. |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 } | 449 } |
| 449 } | 450 } |
| 450 | 451 |
| 451 TEST(MathUtilTest, RoundDownUnderflow) { | 452 TEST(MathUtilTest, RoundDownUnderflow) { |
| 452 // Rounding down -123 by 50 is -150, which underflows int8_t, but fits in | 453 // Rounding down -123 by 50 is -150, which underflows int8_t, but fits in |
| 453 // int16_t. | 454 // int16_t. |
| 454 EXPECT_FALSE(MathUtil::VerifyRoundDown<int8_t>(-123, 50)); | 455 EXPECT_FALSE(MathUtil::VerifyRoundDown<int8_t>(-123, 50)); |
| 455 EXPECT_TRUE(MathUtil::VerifyRoundDown<int16_t>(-123, 50)); | 456 EXPECT_TRUE(MathUtil::VerifyRoundDown<int16_t>(-123, 50)); |
| 456 } | 457 } |
| 457 | 458 |
| 459 TEST(MathUtilTest, MapClippedQuadDuplicate) { | |
| 460 gfx::Transform transform; | |
| 461 transform.MakeIdentity(); | |
| 462 transform.ApplyPerspectiveDepth(50.0); | |
| 463 transform.RotateAboutYAxis(89.0); | |
| 464 | |
| 465 gfx::QuadF src_quad(gfx::PointF(0.0f, 100.0f), gfx::PointF(0.0f, -100.0f), | |
|
flackr
2016/12/08 20:24:01
It might be worth explicitly pointing out the two
Peter Mayo
2016/12/08 20:29:09
Actually a comment about the whole scenario may be
| |
| 466 gfx::PointF(-99.0f, -300.0f), | |
| 467 gfx::PointF(-99.0f, -100.0f)); | |
| 468 | |
| 469 gfx::PointF clipped_quad[8]; | |
| 470 int num_vertices_in_clipped_quad; | |
| 471 | |
| 472 MathUtil::MapClippedQuad(transform, src_quad, clipped_quad, | |
| 473 &num_vertices_in_clipped_quad); | |
| 474 | |
| 475 printf("transformed quad is ["); | |
| 476 for (int i = 0; i < num_vertices_in_clipped_quad; i++) { | |
| 477 if (i > 0) | |
| 478 printf(", "); | |
| 479 printf("(%.5f, %.5f)", clipped_quad[i].x(), clipped_quad[i].y()); | |
| 480 } | |
| 481 printf("]\n"); | |
|
flackr
2016/12/08 20:24:01
debugging code?
Peter Mayo
2016/12/08 20:29:09
Yup, hence 'First ...
Definitely more to come, an
| |
| 482 | |
| 483 EXPECT_EQ(num_vertices_in_clipped_quad, 3); | |
| 484 } | |
| 485 | |
| 458 } // namespace | 486 } // namespace |
| 459 } // namespace cc | 487 } // namespace cc |
| OLD | NEW |