Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: ui/gfx/geometry/rect_unittest.cc

Issue 1164063005: Replace gfx::ClampToInt with base::saturated_cast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clamp: . Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/geometry/safe_integer_conversions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 std::numeric_limits<int>::max(), 490 std::numeric_limits<int>::max(),
491 0, 0 }, 491 0, 0 },
492 { 0.0f, 0.0f, 492 { 0.0f, 0.0f,
493 std::numeric_limits<float>::max(), 493 std::numeric_limits<float>::max(),
494 std::numeric_limits<float>::max(), 494 std::numeric_limits<float>::max(),
495 0, 0, 495 0, 0,
496 std::numeric_limits<int>::max(), 496 std::numeric_limits<int>::max(),
497 std::numeric_limits<int>::max() }, 497 std::numeric_limits<int>::max() },
498 { 20000.5f, 20000.5f, 0.5f, 0.5f, 498 { 20000.5f, 20000.5f, 0.5f, 0.5f,
499 20001, 20001, 0, 0 }, 499 20001, 20001, 0, 0 },
500 { std::numeric_limits<float>::quiet_NaN(),
501 std::numeric_limits<float>::quiet_NaN(),
502 std::numeric_limits<float>::quiet_NaN(),
503 std::numeric_limits<float>::quiet_NaN(),
504 0, 0, 0, 0 }
505 }; 500 };
506 501
507 for (size_t i = 0; i < arraysize(tests); ++i) { 502 for (size_t i = 0; i < arraysize(tests); ++i) {
508 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); 503 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
509 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); 504 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
510 505
511 Rect enclosed = ToEnclosedRect(r1); 506 Rect enclosed = ToEnclosedRect(r1);
512 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); 507 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x());
513 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); 508 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y());
514 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); 509 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width());
(...skipping 27 matching lines...) Expand all
542 std::numeric_limits<int>::max(), 537 std::numeric_limits<int>::max(),
543 0, 0 }, 538 0, 0 },
544 { 0.0f, 0.0f, 539 { 0.0f, 0.0f,
545 std::numeric_limits<float>::max(), 540 std::numeric_limits<float>::max(),
546 std::numeric_limits<float>::max(), 541 std::numeric_limits<float>::max(),
547 0, 0, 542 0, 0,
548 std::numeric_limits<int>::max(), 543 std::numeric_limits<int>::max(),
549 std::numeric_limits<int>::max() }, 544 std::numeric_limits<int>::max() },
550 { 20000.5f, 20000.5f, 0.5f, 0.5f, 545 { 20000.5f, 20000.5f, 0.5f, 0.5f,
551 20000, 20000, 1, 1 }, 546 20000, 20000, 1, 1 },
552 { std::numeric_limits<float>::quiet_NaN(),
553 std::numeric_limits<float>::quiet_NaN(),
554 std::numeric_limits<float>::quiet_NaN(),
555 std::numeric_limits<float>::quiet_NaN(),
556 0, 0, 0, 0 }
557 }; 547 };
558 548
559 for (size_t i = 0; i < arraysize(tests); ++i) { 549 for (size_t i = 0; i < arraysize(tests); ++i) {
560 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); 550 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
561 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); 551 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
562 552
563 Rect enclosed = ToEnclosingRect(r1); 553 Rect enclosed = ToEnclosingRect(r1);
564 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); 554 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x());
565 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); 555 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y());
566 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); 556 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width());
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); 904 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f)));
915 EXPECT_FLOAT_EQ( 905 EXPECT_FLOAT_EQ(
916 0.1f + kEpsilon, 906 0.1f + kEpsilon,
917 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); 907 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f)));
918 EXPECT_FLOAT_EQ( 908 EXPECT_FLOAT_EQ(
919 kEpsilon, 909 kEpsilon,
920 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); 910 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f)));
921 } 911 }
922 912
923 } // namespace gfx 913 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/geometry/safe_integer_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698