| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 static const float max_float = std::numeric_limits<float>::max(); | 523 static const float max_float = std::numeric_limits<float>::max(); |
| 524 static const struct Test { | 524 static const struct Test { |
| 525 float x1; // source | 525 float x1; // source |
| 526 float y1; | 526 float y1; |
| 527 float w1; | 527 float w1; |
| 528 float h1; | 528 float h1; |
| 529 int x2; // target | 529 int x2; // target |
| 530 int y2; | 530 int y2; |
| 531 int w2; | 531 int w2; |
| 532 int h2; | 532 int h2; |
| 533 } tests[] = {{0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, | 533 } tests[] = { |
| 534 {5.5f, 5.5f, 0.0f, 0.0f, 5, 5, 0, 0}, | 534 {0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, |
| 535 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 4, 4}, | 535 {5.5f, 5.5f, 0.0f, 0.0f, 5, 5, 0, 0}, |
| 536 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 4, 4}, | 536 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 4, 4}, |
| 537 {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0}, | 537 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 4, 4}, |
| 538 {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int}, | 538 {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0}, |
| 539 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 1, 1}, | 539 {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int}, |
| 540 {static_cast<float>(min_int), | 540 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 1, 1}, |
| 541 static_cast<float>(min_int), | 541 {static_cast<float>(min_int), static_cast<float>(min_int), max_int * 2.f, |
| 542 max_int * 2.f, | 542 max_int * 2.f, min_int, min_int, max_int, max_int}, |
| 543 max_int * 2.f, | 543 {static_cast<float>(max_int), static_cast<float>(max_int), |
| 544 min_int, | 544 static_cast<float>(max_int), static_cast<float>(max_int), max_int, |
| 545 min_int, | 545 max_int, 0, 0}, |
| 546 max_int, | 546 {-0.5f, -0.5f, 22777712.f, 1.f, -1, -1, 22777713, 2}}; |
| 547 max_int}, | |
| 548 {static_cast<float>(max_int), | |
| 549 static_cast<float>(max_int), | |
| 550 static_cast<float>(max_int), | |
| 551 static_cast<float>(max_int), | |
| 552 max_int, | |
| 553 max_int, | |
| 554 0, | |
| 555 0}}; | |
| 556 | 547 |
| 557 for (size_t i = 0; i < arraysize(tests); ++i) { | 548 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 558 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 549 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 559 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 550 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 560 | 551 |
| 561 Rect enclosed = ToEnclosingRect(r1); | 552 Rect enclosed = ToEnclosingRect(r1); |
| 562 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); | 553 EXPECT_EQ(r2.x(), enclosed.x()); |
| 563 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 554 EXPECT_EQ(r2.y(), enclosed.y()); |
| 564 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 555 EXPECT_EQ(r2.width(), enclosed.width()); |
| 565 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 556 EXPECT_EQ(r2.height(), enclosed.height()); |
| 566 } | 557 } |
| 567 } | 558 } |
| 568 | 559 |
| 569 TEST(RectTest, ToNearestRect) { | 560 TEST(RectTest, ToNearestRect) { |
| 570 Rect rect; | 561 Rect rect; |
| 571 EXPECT_EQ(rect, ToNearestRect(RectF(rect))); | 562 EXPECT_EQ(rect, ToNearestRect(RectF(rect))); |
| 572 | 563 |
| 573 rect = Rect(-1, -1, 3, 3); | 564 rect = Rect(-1, -1, 3, 3); |
| 574 EXPECT_EQ(rect, ToNearestRect(RectF(rect))); | 565 EXPECT_EQ(rect, ToNearestRect(RectF(rect))); |
| 575 | 566 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 EXPECT_EQ(large_offset, offset_overflow.origin()); | 977 EXPECT_EQ(large_offset, offset_overflow.origin()); |
| 987 EXPECT_EQ(expected_size, offset_overflow.size()); | 978 EXPECT_EQ(expected_size, offset_overflow.size()); |
| 988 | 979 |
| 989 Rect operator_overflow(0, 0, 100, 100); | 980 Rect operator_overflow(0, 0, 100, 100); |
| 990 operator_overflow += Vector2d(large_number, large_number); | 981 operator_overflow += Vector2d(large_number, large_number); |
| 991 EXPECT_EQ(large_offset, operator_overflow.origin()); | 982 EXPECT_EQ(large_offset, operator_overflow.origin()); |
| 992 EXPECT_EQ(expected_size, operator_overflow.size()); | 983 EXPECT_EQ(expected_size, operator_overflow.size()); |
| 993 } | 984 } |
| 994 | 985 |
| 995 } // namespace gfx | 986 } // namespace gfx |
| OLD | NEW |