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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 514 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); |
515 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 515 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); |
516 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 516 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); |
517 } | 517 } |
518 } | 518 } |
519 | 519 |
520 TEST(RectTest, ToEnclosingRect) { | 520 TEST(RectTest, ToEnclosingRect) { |
521 static const int max_int = std::numeric_limits<int>::max(); | 521 static const int max_int = std::numeric_limits<int>::max(); |
522 static const int min_int = std::numeric_limits<int>::min(); | 522 static const int min_int = std::numeric_limits<int>::min(); |
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 float epsilon_float = std::numeric_limits<float>::epsilon(); |
524 static const struct Test { | 525 static const struct Test { |
525 float x1; // source | 526 float x1; // source |
526 float y1; | 527 float y1; |
527 float w1; | 528 float w1; |
528 float h1; | 529 float h1; |
529 int x2; // target | 530 int x2; // target |
530 int y2; | 531 int y2; |
531 int w2; | 532 int w2; |
532 int h2; | 533 int h2; |
533 } tests[] = { | 534 } tests[] = { |
534 {0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, | 535 {0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, |
535 {5.5f, 5.5f, 0.0f, 0.0f, 5, 5, 0, 0}, | 536 {5.5f, 5.5f, 0.0f, 0.0f, 5, 5, 0, 0}, |
| 537 {3.5f, 2.5f, epsilon_float, -0.0f, 3, 2, 0, 0}, |
536 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 4, 4}, | 538 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 4, 4}, |
537 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 4, 4}, | 539 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 4, 4}, |
538 {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0}, | 540 {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0}, |
539 {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int}, | 541 {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int}, |
540 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 1, 1}, | 542 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 1, 1}, |
541 {static_cast<float>(min_int), static_cast<float>(min_int), max_int * 2.f, | 543 {static_cast<float>(min_int), static_cast<float>(min_int), max_int * 2.f, |
542 max_int * 2.f, min_int, min_int, max_int, max_int}, | 544 max_int * 2.f, min_int, min_int, max_int, max_int}, |
543 {static_cast<float>(max_int), static_cast<float>(max_int), | 545 {static_cast<float>(max_int), static_cast<float>(max_int), |
544 static_cast<float>(max_int), static_cast<float>(max_int), max_int, | 546 static_cast<float>(max_int), static_cast<float>(max_int), max_int, |
545 max_int, 0, 0}, | 547 max_int, 0, 0}, |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 | 1092 |
1091 Rect min_rect(min_int, min_int, max_int, max_int); | 1093 Rect min_rect(min_int, min_int, max_int, max_int); |
1092 // Min rect can't be scaled up any further in any dimension. | 1094 // Min rect can't be scaled up any further in any dimension. |
1093 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, 2, 3.5), min_rect); | 1095 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, 2, 3.5), min_rect); |
1094 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, max_int, max_int), min_rect); | 1096 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, max_int, max_int), min_rect); |
1095 // Min rect scaled by min is an empty rect at (max, max) | 1097 // Min rect scaled by min is an empty rect at (max, max) |
1096 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, min_int, min_int), max_rect); | 1098 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, min_int, min_int), max_rect); |
1097 } | 1099 } |
1098 | 1100 |
1099 } // namespace gfx | 1101 } // namespace gfx |
OLD | NEW |