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" |
| 11 #include "ui/gfx/test/gfx_util.h" |
11 | 12 |
12 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
13 #include <windows.h> | 14 #include <windows.h> |
14 #endif | 15 #endif |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 | 18 |
18 TEST(RectTest, Contains) { | 19 TEST(RectTest, Contains) { |
19 static const struct ContainsCase { | 20 static const struct ContainsCase { |
20 int rect_x; | 21 int rect_x; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 EXPECT_EQ(r3.height(), u.height()); | 222 EXPECT_EQ(r3.height(), u.height()); |
222 } | 223 } |
223 } | 224 } |
224 | 225 |
225 TEST(RectTest, Subtract) { | 226 TEST(RectTest, Subtract) { |
226 Rect result; | 227 Rect result; |
227 | 228 |
228 // Matching | 229 // Matching |
229 result = Rect(10, 10, 20, 20); | 230 result = Rect(10, 10, 20, 20); |
230 result.Subtract(Rect(10, 10, 20, 20)); | 231 result.Subtract(Rect(10, 10, 20, 20)); |
231 EXPECT_EQ(Rect(0, 0, 0, 0).ToString(), result.ToString()); | 232 EXPECT_EQ(Rect(0, 0, 0, 0), result); |
232 | 233 |
233 // Contains | 234 // Contains |
234 result = Rect(10, 10, 20, 20); | 235 result = Rect(10, 10, 20, 20); |
235 result.Subtract(Rect(5, 5, 30, 30)); | 236 result.Subtract(Rect(5, 5, 30, 30)); |
236 EXPECT_EQ(Rect(0, 0, 0, 0).ToString(), result.ToString()); | 237 EXPECT_EQ(Rect(0, 0, 0, 0), result); |
237 | 238 |
238 // No intersection | 239 // No intersection |
239 result = Rect(10, 10, 20, 20); | 240 result = Rect(10, 10, 20, 20); |
240 result.Subtract(Rect(30, 30, 30, 30)); | 241 result.Subtract(Rect(30, 30, 30, 30)); |
241 EXPECT_EQ(Rect(10, 10, 20, 20).ToString(), result.ToString()); | 242 EXPECT_EQ(Rect(10, 10, 20, 20), result); |
242 | 243 |
243 // Not a complete intersection in either direction | 244 // Not a complete intersection in either direction |
244 result = Rect(10, 10, 20, 20); | 245 result = Rect(10, 10, 20, 20); |
245 result.Subtract(Rect(15, 15, 20, 20)); | 246 result.Subtract(Rect(15, 15, 20, 20)); |
246 EXPECT_EQ(Rect(10, 10, 20, 20).ToString(), result.ToString()); | 247 EXPECT_EQ(Rect(10, 10, 20, 20), result); |
247 | 248 |
248 // Complete intersection in the x-direction, top edge is fully covered. | 249 // Complete intersection in the x-direction, top edge is fully covered. |
249 result = Rect(10, 10, 20, 20); | 250 result = Rect(10, 10, 20, 20); |
250 result.Subtract(Rect(10, 15, 20, 20)); | 251 result.Subtract(Rect(10, 15, 20, 20)); |
251 EXPECT_EQ(Rect(10, 10, 20, 5).ToString(), result.ToString()); | 252 EXPECT_EQ(Rect(10, 10, 20, 5), result); |
252 | 253 |
253 // Complete intersection in the x-direction, top edge is fully covered. | 254 // Complete intersection in the x-direction, top edge is fully covered. |
254 result = Rect(10, 10, 20, 20); | 255 result = Rect(10, 10, 20, 20); |
255 result.Subtract(Rect(5, 15, 30, 20)); | 256 result.Subtract(Rect(5, 15, 30, 20)); |
256 EXPECT_EQ(Rect(10, 10, 20, 5).ToString(), result.ToString()); | 257 EXPECT_EQ(Rect(10, 10, 20, 5), result); |
257 | 258 |
258 // Complete intersection in the x-direction, bottom edge is fully covered. | 259 // Complete intersection in the x-direction, bottom edge is fully covered. |
259 result = Rect(10, 10, 20, 20); | 260 result = Rect(10, 10, 20, 20); |
260 result.Subtract(Rect(5, 5, 30, 20)); | 261 result.Subtract(Rect(5, 5, 30, 20)); |
261 EXPECT_EQ(Rect(10, 25, 20, 5).ToString(), result.ToString()); | 262 EXPECT_EQ(Rect(10, 25, 20, 5), result); |
262 | 263 |
263 // Complete intersection in the x-direction, none of the edges is fully | 264 // Complete intersection in the x-direction, none of the edges is fully |
264 // covered. | 265 // covered. |
265 result = Rect(10, 10, 20, 20); | 266 result = Rect(10, 10, 20, 20); |
266 result.Subtract(Rect(5, 15, 30, 1)); | 267 result.Subtract(Rect(5, 15, 30, 1)); |
267 EXPECT_EQ(Rect(10, 10, 20, 20).ToString(), result.ToString()); | 268 EXPECT_EQ(Rect(10, 10, 20, 20), result); |
268 | 269 |
269 // Complete intersection in the y-direction, left edge is fully covered. | 270 // Complete intersection in the y-direction, left edge is fully covered. |
270 result = Rect(10, 10, 20, 20); | 271 result = Rect(10, 10, 20, 20); |
271 result.Subtract(Rect(10, 10, 10, 30)); | 272 result.Subtract(Rect(10, 10, 10, 30)); |
272 EXPECT_EQ(Rect(20, 10, 10, 20).ToString(), result.ToString()); | 273 EXPECT_EQ(Rect(20, 10, 10, 20), result); |
273 | 274 |
274 // Complete intersection in the y-direction, left edge is fully covered. | 275 // Complete intersection in the y-direction, left edge is fully covered. |
275 result = Rect(10, 10, 20, 20); | 276 result = Rect(10, 10, 20, 20); |
276 result.Subtract(Rect(5, 5, 20, 30)); | 277 result.Subtract(Rect(5, 5, 20, 30)); |
277 EXPECT_EQ(Rect(25, 10, 5, 20).ToString(), result.ToString()); | 278 EXPECT_EQ(Rect(25, 10, 5, 20), result); |
278 | 279 |
279 // Complete intersection in the y-direction, right edge is fully covered. | 280 // Complete intersection in the y-direction, right edge is fully covered. |
280 result = Rect(10, 10, 20, 20); | 281 result = Rect(10, 10, 20, 20); |
281 result.Subtract(Rect(20, 5, 20, 30)); | 282 result.Subtract(Rect(20, 5, 20, 30)); |
282 EXPECT_EQ(Rect(10, 10, 10, 20).ToString(), result.ToString()); | 283 EXPECT_EQ(Rect(10, 10, 10, 20), result); |
283 | 284 |
284 // Complete intersection in the y-direction, none of the edges is fully | 285 // Complete intersection in the y-direction, none of the edges is fully |
285 // covered. | 286 // covered. |
286 result = Rect(10, 10, 20, 20); | 287 result = Rect(10, 10, 20, 20); |
287 result.Subtract(Rect(15, 5, 1, 30)); | 288 result.Subtract(Rect(15, 5, 1, 30)); |
288 EXPECT_EQ(Rect(10, 10, 20, 20).ToString(), result.ToString()); | 289 EXPECT_EQ(Rect(10, 10, 20, 20), result); |
289 } | 290 } |
290 | 291 |
291 TEST(RectTest, IsEmpty) { | 292 TEST(RectTest, IsEmpty) { |
292 EXPECT_TRUE(Rect(0, 0, 0, 0).IsEmpty()); | 293 EXPECT_TRUE(Rect(0, 0, 0, 0).IsEmpty()); |
293 EXPECT_TRUE(Rect(0, 0, 0, 0).size().IsEmpty()); | 294 EXPECT_TRUE(Rect(0, 0, 0, 0).size().IsEmpty()); |
294 EXPECT_TRUE(Rect(0, 0, 10, 0).IsEmpty()); | 295 EXPECT_TRUE(Rect(0, 0, 10, 0).IsEmpty()); |
295 EXPECT_TRUE(Rect(0, 0, 10, 0).size().IsEmpty()); | 296 EXPECT_TRUE(Rect(0, 0, 10, 0).size().IsEmpty()); |
296 EXPECT_TRUE(Rect(0, 0, 0, 10).IsEmpty()); | 297 EXPECT_TRUE(Rect(0, 0, 0, 10).IsEmpty()); |
297 EXPECT_TRUE(Rect(0, 0, 0, 10).size().IsEmpty()); | 298 EXPECT_TRUE(Rect(0, 0, 0, 10).size().IsEmpty()); |
298 EXPECT_FALSE(Rect(0, 0, 10, 10).IsEmpty()); | 299 EXPECT_FALSE(Rect(0, 0, 10, 10).IsEmpty()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 Rect enclosed = ToEnclosingRect(r1); | 563 Rect enclosed = ToEnclosingRect(r1); |
563 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); | 564 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), enclosed.x()); |
564 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); | 565 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), enclosed.y()); |
565 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); | 566 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), enclosed.width()); |
566 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); | 567 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), enclosed.height()); |
567 } | 568 } |
568 } | 569 } |
569 | 570 |
570 TEST(RectTest, ToNearestRect) { | 571 TEST(RectTest, ToNearestRect) { |
571 Rect rect; | 572 Rect rect; |
572 EXPECT_EQ(rect.ToString(), ToNearestRect(RectF(rect)).ToString()); | 573 EXPECT_EQ(rect, ToNearestRect(RectF(rect))); |
573 | 574 |
574 rect = Rect(-1, -1, 3, 3); | 575 rect = Rect(-1, -1, 3, 3); |
575 EXPECT_EQ(rect.ToString(), ToNearestRect(RectF(rect)).ToString()); | 576 EXPECT_EQ(rect, ToNearestRect(RectF(rect))); |
576 | 577 |
577 RectF rectf(-1.00001f, -0.999999f, 3.0000001f, 2.999999f); | 578 RectF rectf(-1.00001f, -0.999999f, 3.0000001f, 2.999999f); |
578 EXPECT_EQ(rect.ToString(), ToNearestRect(rectf).ToString()); | 579 EXPECT_EQ(rect, ToNearestRect(rectf)); |
579 } | 580 } |
580 | 581 |
581 TEST(RectTest, ToFlooredRect) { | 582 TEST(RectTest, ToFlooredRect) { |
582 static const struct Test { | 583 static const struct Test { |
583 float x1; // source | 584 float x1; // source |
584 float y1; | 585 float y1; |
585 float w1; | 586 float w1; |
586 float h1; | 587 float h1; |
587 int x2; // target | 588 int x2; // target |
588 int y2; | 589 int y2; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 }, { | 645 }, { |
645 Rect(-1, -2, 0, 0), | 646 Rect(-1, -2, 0, 0), |
646 1.5f, | 647 1.5f, |
647 Rect(-1, -3, 0, 0), | 648 Rect(-1, -3, 0, 0), |
648 } | 649 } |
649 }; | 650 }; |
650 | 651 |
651 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 652 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
652 Rect result = ScaleToEnclosedRect(tests[i].input_rect, | 653 Rect result = ScaleToEnclosedRect(tests[i].input_rect, |
653 tests[i].input_scale); | 654 tests[i].input_scale); |
654 EXPECT_EQ(tests[i].expected_rect.ToString(), result.ToString()); | 655 EXPECT_EQ(tests[i].expected_rect, result); |
655 } | 656 } |
656 } | 657 } |
657 | 658 |
658 TEST(RectTest, ScaleToEnclosingRect) { | 659 TEST(RectTest, ScaleToEnclosingRect) { |
659 static const struct Test { | 660 static const struct Test { |
660 Rect input_rect; | 661 Rect input_rect; |
661 float input_scale; | 662 float input_scale; |
662 Rect expected_rect; | 663 Rect expected_rect; |
663 } tests[] = { | 664 } tests[] = { |
664 { | 665 { |
(...skipping 23 matching lines...) Expand all Loading... |
688 }, { | 689 }, { |
689 Rect(-1, -2, 0, 0), | 690 Rect(-1, -2, 0, 0), |
690 1.5f, | 691 1.5f, |
691 Rect(-2, -3, 0, 0), | 692 Rect(-2, -3, 0, 0), |
692 } | 693 } |
693 }; | 694 }; |
694 | 695 |
695 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 696 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
696 Rect result = ScaleToEnclosingRect(tests[i].input_rect, | 697 Rect result = ScaleToEnclosingRect(tests[i].input_rect, |
697 tests[i].input_scale); | 698 tests[i].input_scale); |
698 EXPECT_EQ(tests[i].expected_rect.ToString(), result.ToString()); | 699 EXPECT_EQ(tests[i].expected_rect, result); |
699 } | 700 } |
700 } | 701 } |
701 | 702 |
702 #if defined(OS_WIN) | 703 #if defined(OS_WIN) |
703 TEST(RectTest, ConstructAndAssign) { | 704 TEST(RectTest, ConstructAndAssign) { |
704 const RECT rect_1 = { 0, 0, 10, 10 }; | 705 const RECT rect_1 = { 0, 0, 10, 10 }; |
705 const RECT rect_2 = { 0, 0, -10, -10 }; | 706 const RECT rect_2 = { 0, 0, -10, -10 }; |
706 Rect test1(rect_1); | 707 Rect test1(rect_1); |
707 Rect test2(rect_2); | 708 Rect test2(rect_2); |
708 } | 709 } |
709 #endif | 710 #endif |
710 | 711 |
711 TEST(RectTest, ToRectF) { | 712 TEST(RectTest, ToRectF) { |
712 // Check that implicit conversion from integer to float compiles. | 713 // Check that implicit conversion from integer to float compiles. |
713 Rect a(10, 20, 30, 40); | 714 Rect a(10, 20, 30, 40); |
714 RectF b(10, 20, 30, 40); | 715 RectF b(10, 20, 30, 40); |
715 | 716 |
716 RectF intersect = IntersectRects(a, b); | 717 RectF intersect = IntersectRects(a, b); |
717 EXPECT_EQ(b.ToString(), intersect.ToString()); | 718 EXPECT_EQ(b, intersect); |
718 | 719 |
719 EXPECT_EQ(a, b); | 720 EXPECT_EQ(a, b); |
720 EXPECT_EQ(b, a); | 721 EXPECT_EQ(b, a); |
721 } | 722 } |
722 | 723 |
723 TEST(RectTest, BoundingRect) { | 724 TEST(RectTest, BoundingRect) { |
724 struct { | 725 struct { |
725 Point a; | 726 Point a; |
726 Point b; | 727 Point b; |
727 Rect expected; | 728 Rect expected; |
728 } int_tests[] = { | 729 } int_tests[] = { |
729 // If point B dominates A, then A should be the origin. | 730 // If point B dominates A, then A should be the origin. |
730 { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, | 731 { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, |
731 { Point(4, 6), Point(8, 6), Rect(4, 6, 4, 0) }, | 732 { Point(4, 6), Point(8, 6), Rect(4, 6, 4, 0) }, |
732 { Point(4, 6), Point(4, 9), Rect(4, 6, 0, 3) }, | 733 { Point(4, 6), Point(4, 9), Rect(4, 6, 0, 3) }, |
733 { Point(4, 6), Point(8, 9), Rect(4, 6, 4, 3) }, | 734 { Point(4, 6), Point(8, 9), Rect(4, 6, 4, 3) }, |
734 // If point A dominates B, then B should be the origin. | 735 // If point A dominates B, then B should be the origin. |
735 { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, | 736 { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, |
736 { Point(8, 6), Point(4, 6), Rect(4, 6, 4, 0) }, | 737 { Point(8, 6), Point(4, 6), Rect(4, 6, 4, 0) }, |
737 { Point(4, 9), Point(4, 6), Rect(4, 6, 0, 3) }, | 738 { Point(4, 9), Point(4, 6), Rect(4, 6, 0, 3) }, |
738 { Point(8, 9), Point(4, 6), Rect(4, 6, 4, 3) }, | 739 { Point(8, 9), Point(4, 6), Rect(4, 6, 4, 3) }, |
739 // If neither point dominates, then the origin is a combination of the two. | 740 // If neither point dominates, then the origin is a combination of the two. |
740 { Point(4, 6), Point(6, 4), Rect(4, 4, 2, 2) }, | 741 { Point(4, 6), Point(6, 4), Rect(4, 4, 2, 2) }, |
741 { Point(-4, -6), Point(-6, -4), Rect(-6, -6, 2, 2) }, | 742 { Point(-4, -6), Point(-6, -4), Rect(-6, -6, 2, 2) }, |
742 { Point(-4, 6), Point(6, -4), Rect(-4, -4, 10, 10) }, | 743 { Point(-4, 6), Point(6, -4), Rect(-4, -4, 10, 10) }, |
743 }; | 744 }; |
744 | 745 |
745 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(int_tests); ++i) { | 746 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(int_tests); ++i) { |
746 Rect actual = BoundingRect(int_tests[i].a, int_tests[i].b); | 747 Rect actual = BoundingRect(int_tests[i].a, int_tests[i].b); |
747 EXPECT_EQ(int_tests[i].expected.ToString(), actual.ToString()); | 748 EXPECT_EQ(int_tests[i].expected, actual); |
748 } | 749 } |
749 | 750 |
750 struct { | 751 struct { |
751 PointF a; | 752 PointF a; |
752 PointF b; | 753 PointF b; |
753 RectF expected; | 754 RectF expected; |
754 } float_tests[] = { | 755 } float_tests[] = { |
755 // If point B dominates A, then A should be the origin. | 756 // If point B dominates A, then A should be the origin. |
756 { PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), | 757 { PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), |
757 RectF(4.2f, 6.8f, 0, 0) }, | 758 RectF(4.2f, 6.8f, 0, 0) }, |
(...skipping 16 matching lines...) Expand all Loading... |
774 { PointF(4.2f, 6.8f), PointF(6.8f, 4.2f), | 775 { PointF(4.2f, 6.8f), PointF(6.8f, 4.2f), |
775 RectF(4.2f, 4.2f, 2.6f, 2.6f) }, | 776 RectF(4.2f, 4.2f, 2.6f, 2.6f) }, |
776 { PointF(-4.2f, -6.8f), PointF(-6.8f, -4.2f), | 777 { PointF(-4.2f, -6.8f), PointF(-6.8f, -4.2f), |
777 RectF(-6.8f, -6.8f, 2.6f, 2.6f) }, | 778 RectF(-6.8f, -6.8f, 2.6f, 2.6f) }, |
778 { PointF(-4.2f, 6.8f), PointF(6.8f, -4.2f), | 779 { PointF(-4.2f, 6.8f), PointF(6.8f, -4.2f), |
779 RectF(-4.2f, -4.2f, 11.0f, 11.0f) } | 780 RectF(-4.2f, -4.2f, 11.0f, 11.0f) } |
780 }; | 781 }; |
781 | 782 |
782 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) { | 783 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) { |
783 RectF actual = BoundingRect(float_tests[i].a, float_tests[i].b); | 784 RectF actual = BoundingRect(float_tests[i].a, float_tests[i].b); |
784 EXPECT_EQ(float_tests[i].expected.ToString(), actual.ToString()); | 785 EXPECT_RECTF_EQ(float_tests[i].expected, actual); |
785 } | 786 } |
786 } | 787 } |
787 | 788 |
788 TEST(RectTest, IsExpressibleAsRect) { | 789 TEST(RectTest, IsExpressibleAsRect) { |
789 EXPECT_TRUE(RectF().IsExpressibleAsRect()); | 790 EXPECT_TRUE(RectF().IsExpressibleAsRect()); |
790 | 791 |
791 float min = std::numeric_limits<int>::min(); | 792 float min = std::numeric_limits<int>::min(); |
792 float max = std::numeric_limits<int>::max(); | 793 float max = std::numeric_limits<int>::max(); |
793 float infinity = std::numeric_limits<float>::infinity(); | 794 float infinity = std::numeric_limits<float>::infinity(); |
794 | 795 |
(...skipping 16 matching lines...) Expand all Loading... |
811 | 812 |
812 EXPECT_FALSE(RectF(infinity, 0, 1, 1).IsExpressibleAsRect()); | 813 EXPECT_FALSE(RectF(infinity, 0, 1, 1).IsExpressibleAsRect()); |
813 EXPECT_FALSE(RectF(0, infinity, 1, 1).IsExpressibleAsRect()); | 814 EXPECT_FALSE(RectF(0, infinity, 1, 1).IsExpressibleAsRect()); |
814 EXPECT_FALSE(RectF(0, 0, infinity, 1).IsExpressibleAsRect()); | 815 EXPECT_FALSE(RectF(0, 0, infinity, 1).IsExpressibleAsRect()); |
815 EXPECT_FALSE(RectF(0, 0, 1, infinity).IsExpressibleAsRect()); | 816 EXPECT_FALSE(RectF(0, 0, 1, infinity).IsExpressibleAsRect()); |
816 } | 817 } |
817 | 818 |
818 TEST(RectTest, Offset) { | 819 TEST(RectTest, Offset) { |
819 Rect i(1, 2, 3, 4); | 820 Rect i(1, 2, 3, 4); |
820 | 821 |
821 EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), (i + Vector2d(1, -1)).ToString()); | 822 EXPECT_EQ(Rect(2, 1, 3, 4), (i + Vector2d(1, -1))); |
822 EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), (Vector2d(1, -1) + i).ToString()); | 823 EXPECT_EQ(Rect(2, 1, 3, 4), (Vector2d(1, -1) + i)); |
823 i += Vector2d(1, -1); | 824 i += Vector2d(1, -1); |
824 EXPECT_EQ(Rect(2, 1, 3, 4).ToString(), i.ToString()); | 825 EXPECT_EQ(Rect(2, 1, 3, 4), i); |
825 EXPECT_EQ(Rect(1, 2, 3, 4).ToString(), (i - Vector2d(1, -1)).ToString()); | 826 EXPECT_EQ(Rect(1, 2, 3, 4), (i - Vector2d(1, -1))); |
826 i -= Vector2d(1, -1); | 827 i -= Vector2d(1, -1); |
827 EXPECT_EQ(Rect(1, 2, 3, 4).ToString(), i.ToString()); | 828 EXPECT_EQ(Rect(1, 2, 3, 4), i); |
828 | 829 |
829 RectF f(1.1f, 2.2f, 3.3f, 4.4f); | 830 RectF f(1.1f, 2.2f, 3.3f, 4.4f); |
830 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), | 831 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f), (f + Vector2dF(1.1f, -1.1f))); |
831 (f + Vector2dF(1.1f, -1.1f)).ToString()); | 832 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f), (Vector2dF(1.1f, -1.1f) + f)); |
832 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), | |
833 (Vector2dF(1.1f, -1.1f) + f).ToString()); | |
834 f += Vector2dF(1.1f, -1.1f); | 833 f += Vector2dF(1.1f, -1.1f); |
835 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f).ToString(), f.ToString()); | 834 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f), f); |
836 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), | 835 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f), (f - Vector2dF(1.1f, -1.1f))); |
837 (f - Vector2dF(1.1f, -1.1f)).ToString()); | |
838 f -= Vector2dF(1.1f, -1.1f); | 836 f -= Vector2dF(1.1f, -1.1f); |
839 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), f.ToString()); | 837 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f), f); |
840 } | 838 } |
841 | 839 |
842 TEST(RectTest, Corners) { | 840 TEST(RectTest, Corners) { |
843 Rect i(1, 2, 3, 4); | 841 Rect i(1, 2, 3, 4); |
844 RectF f(1.1f, 2.1f, 3.1f, 4.1f); | 842 RectF f(1.1f, 2.1f, 3.1f, 4.1f); |
845 | 843 |
846 EXPECT_EQ(Point(1, 2).ToString(), i.origin().ToString()); | 844 EXPECT_EQ(Point(1, 2), i.origin()); |
847 EXPECT_EQ(Point(4, 2).ToString(), i.top_right().ToString()); | 845 EXPECT_EQ(Point(4, 2), i.top_right()); |
848 EXPECT_EQ(Point(1, 6).ToString(), i.bottom_left().ToString()); | 846 EXPECT_EQ(Point(1, 6), i.bottom_left()); |
849 EXPECT_EQ(Point(4, 6).ToString(), i.bottom_right().ToString()); | 847 EXPECT_EQ(Point(4, 6), i.bottom_right()); |
850 | 848 |
851 EXPECT_EQ(PointF(1.1f, 2.1f).ToString(), f.origin().ToString()); | 849 EXPECT_EQ(PointF(1.1f, 2.1f), f.origin()); |
852 EXPECT_EQ(PointF(4.2f, 2.1f).ToString(), f.top_right().ToString()); | 850 EXPECT_EQ(PointF(4.2f, 2.1f), f.top_right()); |
853 EXPECT_EQ(PointF(1.1f, 6.2f).ToString(), f.bottom_left().ToString()); | 851 EXPECT_EQ(PointF(1.1f, 6.2f), f.bottom_left()); |
854 EXPECT_EQ(PointF(4.2f, 6.2f).ToString(), f.bottom_right().ToString()); | 852 EXPECT_EQ(PointF(4.2f, 6.2f), f.bottom_right()); |
855 } | 853 } |
856 | 854 |
857 TEST(RectTest, ManhattanDistanceToPoint) { | 855 TEST(RectTest, ManhattanDistanceToPoint) { |
858 Rect i(1, 2, 3, 4); | 856 Rect i(1, 2, 3, 4); |
859 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(1, 2))); | 857 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(1, 2))); |
860 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(4, 6))); | 858 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(4, 6))); |
861 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(2, 4))); | 859 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(2, 4))); |
862 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(0, 0))); | 860 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(0, 0))); |
863 EXPECT_EQ(2, i.ManhattanDistanceToPoint(Point(2, 0))); | 861 EXPECT_EQ(2, i.ManhattanDistanceToPoint(Point(2, 0))); |
864 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(5, 0))); | 862 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(5, 0))); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); | 914 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); |
917 EXPECT_FLOAT_EQ( | 915 EXPECT_FLOAT_EQ( |
918 0.1f + kEpsilon, | 916 0.1f + kEpsilon, |
919 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); | 917 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); |
920 EXPECT_FLOAT_EQ( | 918 EXPECT_FLOAT_EQ( |
921 kEpsilon, | 919 kEpsilon, |
922 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); | 920 f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); |
923 } | 921 } |
924 | 922 |
925 } // namespace gfx | 923 } // namespace gfx |
OLD | NEW |