| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 460 |
| 461 RectF scaled = ScaleRect(r1, tests[i].scale); | 461 RectF scaled = ScaleRect(r1, tests[i].scale); |
| 462 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); | 462 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x()); |
| 463 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); | 463 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y()); |
| 464 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); | 464 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width()); |
| 465 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height()); | 465 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height()); |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 | 468 |
| 469 TEST(RectTest, ToEnclosedRect) { | 469 TEST(RectTest, ToEnclosedRect) { |
| 470 static const int max_int = std::numeric_limits<int>::max(); |
| 471 static const int min_int = std::numeric_limits<int>::min(); |
| 472 static const float max_float = std::numeric_limits<float>::max(); |
| 470 static const struct Test { | 473 static const struct Test { |
| 471 float x1; // source | 474 float x1; // source |
| 472 float y1; | 475 float y1; |
| 473 float w1; | 476 float w1; |
| 474 float h1; | 477 float h1; |
| 475 int x2; // target | 478 int x2; // target |
| 476 int y2; | 479 int y2; |
| 477 int w2; | 480 int w2; |
| 478 int h2; | 481 int h2; |
| 479 } tests [] = { | 482 } tests[] = {{0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, |
| 480 { 0.0f, 0.0f, 0.0f, 0.0f, | 483 {-1.5f, -1.5f, 3.0f, 3.0f, -1, -1, 2, 2}, |
| 481 0, 0, 0, 0 }, | 484 {-1.5f, -1.5f, 3.5f, 3.5f, -1, -1, 3, 3}, |
| 482 { -1.5f, -1.5f, 3.0f, 3.0f, | 485 {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0}, |
| 483 -1, -1, 2, 2 }, | 486 {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int}, |
| 484 { -1.5f, -1.5f, 3.5f, 3.5f, | 487 {20000.5f, 20000.5f, 0.5f, 0.5f, 20001, 20001, 0, 0}, |
| 485 -1, -1, 3, 3 }, | 488 {min_int, min_int, max_int * 2.f, max_int * 2.f, min_int, |
| 486 { std::numeric_limits<float>::max(), | 489 min_int, max_int, max_int}, |
| 487 std::numeric_limits<float>::max(), | 490 {max_int, max_int, max_int, max_int, max_int, max_int, 0, 0}}; |
| 488 2.0f, 2.0f, | |
| 489 std::numeric_limits<int>::max(), | |
| 490 std::numeric_limits<int>::max(), | |
| 491 0, 0 }, | |
| 492 { 0.0f, 0.0f, | |
| 493 std::numeric_limits<float>::max(), | |
| 494 std::numeric_limits<float>::max(), | |
| 495 0, 0, | |
| 496 std::numeric_limits<int>::max(), | |
| 497 std::numeric_limits<int>::max() }, | |
| 498 { 20000.5f, 20000.5f, 0.5f, 0.5f, | |
| 499 20001, 20001, 0, 0 }, | |
| 500 }; | |
| 501 | 491 |
| 502 for (size_t i = 0; i < arraysize(tests); ++i) { | 492 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 503 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 493 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 504 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 494 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 505 | 495 |
| 506 Rect enclosed = ToEnclosedRect(r1); | 496 Rect enclosed = ToEnclosedRect(r1); |
| 507 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); | 497 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); |
| 508 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 498 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); |
| 509 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 499 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); |
| 510 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 500 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); |
| 511 } | 501 } |
| 512 } | 502 } |
| 513 | 503 |
| 514 TEST(RectTest, ToEnclosingRect) { | 504 TEST(RectTest, ToEnclosingRect) { |
| 505 static const int max_int = std::numeric_limits<int>::max(); |
| 506 static const int min_int = std::numeric_limits<int>::min(); |
| 507 static const float max_float = std::numeric_limits<float>::max(); |
| 515 static const struct Test { | 508 static const struct Test { |
| 516 float x1; // source | 509 float x1; // source |
| 517 float y1; | 510 float y1; |
| 518 float w1; | 511 float w1; |
| 519 float h1; | 512 float h1; |
| 520 int x2; // target | 513 int x2; // target |
| 521 int y2; | 514 int y2; |
| 522 int w2; | 515 int w2; |
| 523 int h2; | 516 int h2; |
| 524 } tests [] = { | 517 } tests[] = {{0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, |
| 525 { 0.0f, 0.0f, 0.0f, 0.0f, | 518 {5.5f, 5.5f, 0.0f, 0.0f, 5, 5, 0, 0}, |
| 526 0, 0, 0, 0 }, | 519 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 4, 4}, |
| 527 { 5.5f, 5.5f, 0.0f, 0.0f, | 520 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 4, 4}, |
| 528 5, 5, 0, 0 }, | 521 {max_float, max_float, 2.0f, 2.0f, max_int, max_int, 0, 0}, |
| 529 { -1.5f, -1.5f, 3.0f, 3.0f, | 522 {0.0f, 0.0f, max_float, max_float, 0, 0, max_int, max_int}, |
| 530 -2, -2, 4, 4 }, | 523 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 1, 1}, |
| 531 { -1.5f, -1.5f, 3.5f, 3.5f, | 524 {min_int, min_int, max_int * 2.f, max_int * 2.f, min_int, |
| 532 -2, -2, 4, 4 }, | 525 min_int, max_int, max_int}, |
| 533 { std::numeric_limits<float>::max(), | 526 {max_int, max_int, max_int, max_int, max_int, max_int, 0, 0}}; |
| 534 std::numeric_limits<float>::max(), | |
| 535 2.0f, 2.0f, | |
| 536 std::numeric_limits<int>::max(), | |
| 537 std::numeric_limits<int>::max(), | |
| 538 0, 0 }, | |
| 539 { 0.0f, 0.0f, | |
| 540 std::numeric_limits<float>::max(), | |
| 541 std::numeric_limits<float>::max(), | |
| 542 0, 0, | |
| 543 std::numeric_limits<int>::max(), | |
| 544 std::numeric_limits<int>::max() }, | |
| 545 { 20000.5f, 20000.5f, 0.5f, 0.5f, | |
| 546 20000, 20000, 1, 1 }, | |
| 547 }; | |
| 548 | 527 |
| 549 for (size_t i = 0; i < arraysize(tests); ++i) { | 528 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 550 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); | 529 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); |
| 551 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); | 530 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); |
| 552 | 531 |
| 553 Rect enclosed = ToEnclosingRect(r1); | 532 Rect enclosed = ToEnclosingRect(r1); |
| 554 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); | 533 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); |
| 555 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 534 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); |
| 556 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 535 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); |
| 557 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 536 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); | 883 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); |
| 905 EXPECT_FLOAT_EQ( | 884 EXPECT_FLOAT_EQ( |
| 906 0.1f + kEpsilon, | 885 0.1f + kEpsilon, |
| 907 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); | 886 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); |
| 908 EXPECT_FLOAT_EQ( | 887 EXPECT_FLOAT_EQ( |
| 909 kEpsilon, | 888 kEpsilon, |
| 910 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); | 889 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); |
| 911 } | 890 } |
| 912 | 891 |
| 913 } // namespace gfx | 892 } // namespace gfx |
| OLD | NEW |