10#include "gtest/gtest.h"
20template <
typename T,
size_t N>
21constexpr size_t size(
const T (&array)[
N])
noexcept {
26 static const struct ContainsCase {
34 } contains_cases[] = {
35 {0, 0, 10, 10, 0, 0,
true},
36 {0, 0, 10, 10, 5, 5,
true},
37 {0, 0, 10, 10, 9, 9,
true},
38 {0, 0, 10, 10, 5, 10,
false},
39 {0, 0, 10, 10, 10, 5,
false},
40 {0, 0, 10, 10, -1, -1,
false},
41 {0, 0, 10, 10, 50, 50,
false},
42#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
43 {0, 0, -10, -10, 0, 0,
false},
46 for (
size_t i = 0;
i <
size(contains_cases); ++
i) {
47 const ContainsCase&
value = contains_cases[
i];
53TEST(RectTest, Intersects) {
64 }
tests[] = {{0, 0, 0, 0, 0, 0, 0, 0,
false},
65 {0, 0, 0, 0, -10, -10, 20, 20,
false},
66 {-10, 0, 0, 20, 0, -10, 20, 0,
false},
67 {0, 0, 10, 10, 0, 0, 10, 10,
true},
68 {0, 0, 10, 10, 10, 10, 10, 10,
false},
69 {10, 10, 10, 10, 0, 0, 10, 10,
false},
70 {10, 10, 10, 10, 5, 5, 10, 10,
true},
71 {10, 10, 10, 10, 15, 15, 10, 10,
true},
72 {10, 10, 10, 10, 20, 15, 10, 10,
false},
73 {10, 10, 10, 10, 21, 15, 10, 10,
false}};
96 }
tests[] = {{0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0},
99 0, 0, 4, 4, 0, 0, 4, 4},
101 4, 4, 4, 4, 0, 0, 0, 0},
103 2, 2, 4, 4, 2, 2, 2, 2},
105 3, 1, 4, 2, 3, 1, 1, 2},
107 0, 0, 2, 2, 0, 0, 0, 0}};
113 EXPECT_EQ(r3.
x(), ir.
x());
114 EXPECT_EQ(r3.
y(), ir.
y());
121 static const struct Test {
134 }
tests[] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
135 {0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4},
136 {0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 8, 8},
137 {0, 0, 4, 4, 0, 5, 4, 4, 0, 0, 4, 9},
138 {0, 0, 2, 2, 3, 3, 2, 2, 0, 0, 5, 5},
140 0, 0, 2, 2, 0, 0, 5, 5},
142 2, 2, 2, 2, 2, 2, 2, 2}};
148 EXPECT_EQ(r3.
x(), u.
x());
149 EXPECT_EQ(r3.
y(), u.
y());
156 ASSERT_TRUE(
Rect(0, 0, 0, 0) ==
Rect(0, 0, 0, 0));
157 ASSERT_TRUE(
Rect(1, 2, 3, 4) ==
Rect(1, 2, 3, 4));
158 ASSERT_FALSE(
Rect(0, 0, 0, 0) ==
Rect(0, 0, 0, 1));
159 ASSERT_FALSE(
Rect(0, 0, 0, 0) ==
Rect(0, 0, 1, 0));
160 ASSERT_FALSE(
Rect(0, 0, 0, 0) ==
Rect(0, 1, 0, 0));
161 ASSERT_FALSE(
Rect(0, 0, 0, 0) ==
Rect(1, 0, 0, 0));
165 static const struct Test {
178 }
tests[] = {{0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2},
179 {2, 2, 3, 3, 0, 0, 4, 4, 1, 1, 3, 3},
180 {-1, -1, 5, 5, 0, 0, 4, 4, 0, 0, 4, 4},
181 {2, 2, 4, 4, 0, 0, 3, 3, 0, 0, 3, 3},
182 {2, 2, 1, 1, 0, 0, 3, 3, 2, 2, 1, 1}};
189 EXPECT_EQ(r3.
x(), u.
x());
190 EXPECT_EQ(r3.
y(), u.
y());
273TEST(RectTest, SplitVertically) {
274 Rect left_half, right_half;
277 Rect(0, 0, 20, 20).SplitVertically(&left_half, &right_half);
282 Rect(10, 10, 20, 10).SplitVertically(&left_half, &right_half);
287 Rect(10, 10, 0, 10).SplitVertically(&left_half, &right_half);
292 Rect(10, 10, 5, 10).SplitVertically(&left_half, &right_half);
301 center =
Rect(0, 0, 20, 20).CenterPoint();
305 center =
Rect(10, 10, 20, 20).CenterPoint();
309 center =
Rect(11, 11, 20, 20).CenterPoint();
313 center =
Rect(10, 10, 0, 20).CenterPoint();
315 center =
Rect(10, 10, 20, 0).CenterPoint();
319 center =
Rect(10, 10, 21, 21).CenterPoint();
323 center =
Rect(11, 11, 21, 21).CenterPoint();
357TEST(RectTest, SharesEdgeWith) {
363 Rect just_above(2, 1, 4, 2);
364 Rect just_below(2, 8, 4, 2);
365 Rect just_left(0, 3, 2, 5);
366 Rect just_right(6, 3, 2, 5);
374 Rect same_height_no_edge(0, 0, 1, 5);
375 Rect same_width_no_edge(0, 0, 4, 1);
380 Rect just_above_no_edge(2, 1, 5, 2);
381 Rect just_below_no_edge(2, 8, 3, 2);
382 Rect just_left_no_edge(0, 3, 2, 6);
383 Rect just_right_no_edge(6, 3, 2, 4);
392#define EXPECT_FLOAT_AND_NAN_EQ(a, b) \
394 if (a == a || b == b) { \
395 EXPECT_FLOAT_EQ(a, b); \
400 static const struct Test {
411 {3, 3, 3, 3, 1.5f, 4.5f, 4.5f, 4.5f, 4.5f},
412 {3, 3, 3, 3, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
413 {3, 3, 3, 3, std::numeric_limits<float>::quiet_NaN(),
414 std::numeric_limits<float>::quiet_NaN(),
415 std::numeric_limits<float>::quiet_NaN(),
416 std::numeric_limits<float>::quiet_NaN(),
417 std::numeric_limits<float>::quiet_NaN()},
438 static const float max_int_f =
static_cast<float>(max_int);
439 static const float min_int_f =
static_cast<float>(min_int);
441 static const struct Test {
455 {{0.0f, 0.0f, 0.0f, 0.0f}, {0, 0, 0, 0}},
456 {{-1.5f, -1.5f, 3.0f, 3.0f}, {-1, -1, 2, 2}},
457 {{-1.5f, -1.5f, 3.5f, 3.5f}, {-1, -1, 3, 3}},
458 {{max_float, max_float, 2.0f, 2.0f}, {max_int, max_int, 0, 0}},
459 {{0.0f, 0.0f, max_float, max_float}, {0, 0, max_int, max_int}},
460 {{20000.5f, 20000.5f, 0.5f, 0.5f}, {20001, 20001, 0, 0}},
461 {{max_int_f, max_int_f, max_int_f, max_int_f}, {max_int, max_int, 0, 0}},
462 {{1.9999f, 2.0002f, 5.9998f, 6.0001f}, {2, 3, 5, 5}},
463 {{1.9999f, 2.0001f, 6.0002f, 5.9998f}, {2, 3, 6, 4}},
464 {{1.9998f, 2.0002f, 6.0001f, 5.9999f}, {2, 3, 5, 5}}};
471 EXPECT_EQ(
tests[
i].expected.x, enclosed.
x());
472 EXPECT_EQ(
tests[
i].expected.y, enclosed.
y());
473 EXPECT_EQ(
tests[
i].expected.width, enclosed.
width());
478 RectF source(min_int_f, min_int_f, max_int_f * 3.f, max_int_f * 3.f);
482 EXPECT_EQ(max_int, enclosed.
width());
483 EXPECT_EQ(max_int, enclosed.
height());
485 EXPECT_GT(1, enclosed.
x());
486 EXPECT_GT(1, enclosed.
y());
488 EXPECT_LT(0, enclosed.
right());
489 EXPECT_LT(0, enclosed.
bottom());
497 static const float epsilon_float = std::numeric_limits<float>::epsilon();
498 static const float max_int_f =
static_cast<float>(max_int);
499 static const float min_int_f =
static_cast<float>(min_int);
500 static const struct Test {
514 {{0.0f, 0.0f, 0.0f, 0.0f}, {0, 0, 0, 0}},
515 {{5.5f, 5.5f, 0.0f, 0.0f}, {5, 5, 0, 0}},
516 {{3.5f, 2.5f, epsilon_float, -0.0f}, {3, 2, 0, 0}},
517 {{3.5f, 2.5f, 0.f, 0.001f}, {3, 2, 0, 1}},
518 {{-1.5f, -1.5f, 3.0f, 3.0f}, {-2, -2, 4, 4}},
519 {{-1.5f, -1.5f, 3.5f, 3.5f}, {-2, -2, 4, 4}},
520 {{max_float, max_float, 2.0f, 2.0f}, {max_int, max_int, 0, 0}},
521 {{0.0f, 0.0f, max_float, max_float}, {0, 0, max_int, max_int}},
522 {{20000.5f, 20000.5f, 0.5f, 0.5f}, {20000, 20000, 1, 1}},
523 {{max_int_f, max_int_f, max_int_f, max_int_f}, {max_int, max_int, 0, 0}},
524 {{-0.5f, -0.5f, 22777712.f, 1.f}, {-1, -1, 22777713, 2}},
525 {{1.9999f, 2.0002f, 5.9998f, 6.0001f}, {1, 2, 7, 7}},
526 {{1.9999f, 2.0001f, 6.0002f, 5.9998f}, {1, 2, 8, 6}},
527 {{1.9998f, 2.0002f, 6.0001f, 5.9999f}, {1, 2, 7, 7}}};
534 EXPECT_EQ(
tests[
i].expected.x, enclosing.
x());
535 EXPECT_EQ(
tests[
i].expected.y, enclosing.
y());
536 EXPECT_EQ(
tests[
i].expected.width, enclosing.
width());
537 EXPECT_EQ(
tests[
i].expected.height, enclosing.
height());
541 RectF source(min_int_f, min_int_f, max_int_f * 3.f, max_int_f * 3.f);
545 EXPECT_EQ(max_int, enclosing.
width());
546 EXPECT_EQ(max_int, enclosing.
height());
548 EXPECT_GT(1, enclosing.
x());
549 EXPECT_GT(1, enclosing.
y());
551 EXPECT_LT(0, enclosing.
right());
552 EXPECT_LT(0, enclosing.
bottom());
559 static const float epsilon_float = std::numeric_limits<float>::epsilon();
560 static const float max_int_f =
static_cast<float>(max_int);
561 static const float error = 0.001f;
562 static const struct Test {
576 {{0.0f, 0.0f, 0.0f, 0.0f}, {0, 0, 0, 0}},
577 {{5.5f, 5.5f, 0.0f, 0.0f}, {5, 5, 0, 0}},
578 {{3.5f, 2.5f, epsilon_float, -0.0f}, {3, 2, 0, 0}},
579 {{3.5f, 2.5f, 0.f, 0.001f}, {3, 2, 0, 1}},
580 {{-1.5f, -1.5f, 3.0f, 3.0f}, {-2, -2, 4, 4}},
581 {{-1.5f, -1.5f, 3.5f, 3.5f}, {-2, -2, 4, 4}},
582 {{max_float, max_float, 2.0f, 2.0f}, {max_int, max_int, 0, 0}},
583 {{0.0f, 0.0f, max_float, max_float}, {0, 0, max_int, max_int}},
584 {{20000.5f, 20000.5f, 0.5f, 0.5f}, {20000, 20000, 1, 1}},
585 {{max_int_f, max_int_f, max_int_f, max_int_f}, {max_int, max_int, 0, 0}},
586 {{-0.5f, -0.5f, 22777712.f, 1.f}, {-1, -1, 22777713, 2}},
587 {{1.9999f, 2.0002f, 5.9998f, 6.0001f}, {2, 2, 6, 6}},
588 {{1.9999f, 2.0001f, 6.0002f, 5.9998f}, {2, 2, 6, 6}},
589 {{1.9998f, 2.0002f, 6.0001f, 5.9999f}, {2, 2, 6, 6}}};
596 EXPECT_EQ(
tests[
i].expected.x, enclosing.
x());
597 EXPECT_EQ(
tests[
i].expected.y, enclosing.
y());
598 EXPECT_EQ(
tests[
i].expected.width, enclosing.
width());
599 EXPECT_EQ(
tests[
i].expected.height, enclosing.
height());
610 RectF rectf(-1.00001f, -0.999999f, 3.0000001f, 2.999999f);
615 static const struct Test {
625 {0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0},
626 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 3, 3},
627 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 3, 3},
628 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 0, 0},
636 EXPECT_FLOAT_EQ(r2.
x(), floored.
x());
637 EXPECT_FLOAT_EQ(r2.
y(), floored.
y());
644 static const struct Test {
692 static const struct Test {
738 EXPECT_EQ(
tests[
i].expected_rect, result_safe);
743TEST(RectTest, ConstructAndAssign) {
744 const RECT rect_1 = {0, 0, 10, 10};
745 const RECT rect_2 = {0, 0, -10, -10};
753 Rect a(10, 20, 30, 40);
783 for (
size_t i = 0;
i <
size(int_tests); ++
i) {
785 EXPECT_EQ(int_tests[
i].expected, actual);
807 RectF(-6.8f, -6.8f, 2.6f, 2.6f)},
809 RectF(-4.2f, -4.2f, 11.0f, 11.0f)}};
811 for (
size_t i = 0;
i <
size(float_tests); ++
i) {
817TEST(RectTest, IsExpressibleAsRect) {
822 float infinity = std::numeric_limits<float>::infinity();
836 EXPECT_FALSE(
RectF(200, 0,
max + 200,
max - 200).IsExpressibleAsRect());
837 EXPECT_FALSE(
RectF(0, 200,
max - 200,
max + 200).IsExpressibleAsRect());
838 EXPECT_FALSE(
RectF(0, 0,
max + 200,
max - 200).IsExpressibleAsRect());
839 EXPECT_FALSE(
RectF(0, 0,
max - 200,
max + 200).IsExpressibleAsRect());
841 EXPECT_FALSE(
RectF(infinity, 0, 1, 1).IsExpressibleAsRect());
842 EXPECT_FALSE(
RectF(0, infinity, 1, 1).IsExpressibleAsRect());
843 EXPECT_FALSE(
RectF(0, 0, infinity, 1).IsExpressibleAsRect());
844 EXPECT_FALSE(
RectF(0, 0, 1, infinity).IsExpressibleAsRect());
853 EXPECT_EQ(
Rect(2, 1, 3, 4),
i);
856 EXPECT_EQ(
Rect(1, 2, 3, 4),
i);
858 RectF f(1.1f, 2.2f, 3.3f, 4.4f);
859 EXPECT_EQ(
RectF(2.2f, 1.1f, 3.3f, 4.4f), (
f +
Vector2dF(1.1f, -1.1f)));
860 EXPECT_EQ(
RectF(2.2f, 1.1f, 3.3f, 4.4f), (
Vector2dF(1.1f, -1.1f) +
f));
862 EXPECT_EQ(
RectF(2.2f, 1.1f, 3.3f, 4.4f),
f);
863 EXPECT_EQ(
RectF(1.1f, 2.2f, 3.3f, 4.4f), (
f -
Vector2dF(1.1f, -1.1f)));
865 EXPECT_EQ(
RectF(1.1f, 2.2f, 3.3f, 4.4f),
f);
870 RectF f(1.1f, 2.1f, 3.1f, 4.1f);
872 EXPECT_EQ(
Point(1, 2),
i.origin());
873 EXPECT_EQ(
Point(4, 2),
i.top_right());
874 EXPECT_EQ(
Point(1, 6),
i.bottom_left());
875 EXPECT_EQ(
Point(4, 6),
i.bottom_right());
877 EXPECT_EQ(
PointF(1.1f, 2.1f),
f.origin());
878 EXPECT_EQ(
PointF(4.2f, 2.1f),
f.top_right());
879 EXPECT_EQ(
PointF(1.1f, 6.2f),
f.bottom_left());
880 EXPECT_EQ(
PointF(4.2f, 6.2f),
f.bottom_right());
884 Rect i(10, 20, 30, 40);
885 EXPECT_EQ(
Point(10, 40),
i.left_center());
886 EXPECT_EQ(
Point(25, 20),
i.top_center());
887 EXPECT_EQ(
Point(40, 40),
i.right_center());
888 EXPECT_EQ(
Point(25, 60),
i.bottom_center());
890 RectF f(10.1f, 20.2f, 30.3f, 40.4f);
891 EXPECT_EQ(
PointF(10.1f, 40.4f),
f.left_center());
892 EXPECT_EQ(
PointF(25.25f, 20.2f),
f.top_center());
893 EXPECT_EQ(
PointF(40.4f, 40.4f),
f.right_center());
894 EXPECT_EQ(25.25f,
f.bottom_center().x());
895 EXPECT_NEAR(60.6f,
f.bottom_center().y(), 0.001f);
899 Rect i(10, 20, 30, 40);
901 EXPECT_EQ(
Rect(20, 10, 40, 30),
i);
903 RectF f(10.1f, 20.2f, 30.3f, 40.4f);
905 EXPECT_EQ(
RectF(20.2f, 10.1f, 40.4f, 30.3f),
f);
908TEST(RectTest, ManhattanDistanceToPoint) {
910 EXPECT_EQ(0,
i.ManhattanDistanceToPoint(
Point(1, 2)));
911 EXPECT_EQ(0,
i.ManhattanDistanceToPoint(
Point(4, 6)));
912 EXPECT_EQ(0,
i.ManhattanDistanceToPoint(
Point(2, 4)));
913 EXPECT_EQ(3,
i.ManhattanDistanceToPoint(
Point(0, 0)));
914 EXPECT_EQ(2,
i.ManhattanDistanceToPoint(
Point(2, 0)));
915 EXPECT_EQ(3,
i.ManhattanDistanceToPoint(
Point(5, 0)));
916 EXPECT_EQ(1,
i.ManhattanDistanceToPoint(
Point(5, 4)));
917 EXPECT_EQ(3,
i.ManhattanDistanceToPoint(
Point(5, 8)));
918 EXPECT_EQ(2,
i.ManhattanDistanceToPoint(
Point(3, 8)));
919 EXPECT_EQ(2,
i.ManhattanDistanceToPoint(
Point(0, 7)));
920 EXPECT_EQ(1,
i.ManhattanDistanceToPoint(
Point(0, 3)));
922 RectF f(1.1f, 2.1f, 3.1f, 4.1f);
923 EXPECT_FLOAT_EQ(0.f,
f.ManhattanDistanceToPoint(
PointF(1.1f, 2.1f)));
924 EXPECT_FLOAT_EQ(0.f,
f.ManhattanDistanceToPoint(
PointF(4.2f, 6.f)));
925 EXPECT_FLOAT_EQ(0.f,
f.ManhattanDistanceToPoint(
PointF(2.f, 4.f)));
926 EXPECT_FLOAT_EQ(3.2f,
f.ManhattanDistanceToPoint(
PointF(0.f, 0.f)));
927 EXPECT_FLOAT_EQ(2.1f,
f.ManhattanDistanceToPoint(
PointF(2.f, 0.f)));
928 EXPECT_FLOAT_EQ(2.9f,
f.ManhattanDistanceToPoint(
PointF(5.f, 0.f)));
929 EXPECT_FLOAT_EQ(.8f,
f.ManhattanDistanceToPoint(
PointF(5.f, 4.f)));
930 EXPECT_FLOAT_EQ(2.6f,
f.ManhattanDistanceToPoint(
PointF(5.f, 8.f)));
931 EXPECT_FLOAT_EQ(1.8f,
f.ManhattanDistanceToPoint(
PointF(3.f, 8.f)));
932 EXPECT_FLOAT_EQ(1.9f,
f.ManhattanDistanceToPoint(
PointF(0.f, 7.f)));
933 EXPECT_FLOAT_EQ(1.1f,
f.ManhattanDistanceToPoint(
PointF(0.f, 3.f)));
936TEST(RectTest, ManhattanInternalDistance) {
937 Rect i(0, 0, 400, 400);
938 EXPECT_EQ(0,
i.ManhattanInternalDistance(
gfx::Rect(-1, 0, 2, 1)));
939 EXPECT_EQ(1,
i.ManhattanInternalDistance(
gfx::Rect(400, 0, 1, 400)));
940 EXPECT_EQ(2,
i.ManhattanInternalDistance(
gfx::Rect(-100, -100, 100, 100)));
941 EXPECT_EQ(2,
i.ManhattanInternalDistance(
gfx::Rect(-101, 100, 100, 100)));
942 EXPECT_EQ(4,
i.ManhattanInternalDistance(
gfx::Rect(-101, -101, 100, 100)));
943 EXPECT_EQ(435,
i.ManhattanInternalDistance(
gfx::Rect(630, 603, 100, 100)));
945 RectF f(0.0f, 0.0f, 400.0f, 400.0f);
946 static const float kEpsilon = std::numeric_limits<float>::epsilon();
949 0.0f,
f.ManhattanInternalDistance(
gfx::RectF(-1.0f, 0.0f, 2.0f, 1.0f)));
950 EXPECT_FLOAT_EQ(
kEpsilon,
f.ManhattanInternalDistance(
953 -100.0f, -100.0f, 100.0f, 100.0f)));
955 -101.0f, 100.0f, 100.0f, 100.0f)));
956 EXPECT_FLOAT_EQ(2.0f + 2.0f *
kEpsilon,
957 f.ManhattanInternalDistance(
958 gfx::RectF(-101.0f, -101.0f, 100.0f, 100.0f)));
961 f.ManhattanInternalDistance(
gfx::RectF(630.0f, 603.0f, 100.0f, 100.0f)));
964 0.0f,
f.ManhattanInternalDistance(
gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f)));
965 EXPECT_FLOAT_EQ(0.1f +
kEpsilon,
f.ManhattanInternalDistance(
967 EXPECT_FLOAT_EQ(
kEpsilon,
f.ManhattanInternalDistance(
971TEST(RectTest, IntegerOverflow) {
975 int large_number = limit - expected;
977 Rect height_overflow(0, large_number, 100, 100);
978 EXPECT_EQ(large_number, height_overflow.
y());
979 EXPECT_EQ(expected, height_overflow.
height());
981 Rect width_overflow(large_number, 0, 100, 100);
982 EXPECT_EQ(large_number, width_overflow.
x());
983 EXPECT_EQ(expected, width_overflow.
width());
985 Rect size_height_overflow(
Point(0, large_number),
Size(100, 100));
986 EXPECT_EQ(large_number, size_height_overflow.
y());
987 EXPECT_EQ(expected, size_height_overflow.
height());
989 Rect size_width_overflow(
Point(large_number, 0),
Size(100, 100));
990 EXPECT_EQ(large_number, size_width_overflow.
x());
991 EXPECT_EQ(expected, size_width_overflow.
width());
993 Rect set_height_overflow(0, large_number, 100, 5);
994 EXPECT_EQ(5, set_height_overflow.
height());
996 EXPECT_EQ(expected, set_height_overflow.
height());
998 Rect set_y_overflow(100, 100, 100, 100);
999 EXPECT_EQ(100, set_y_overflow.
height());
1000 set_y_overflow.
set_y(large_number);
1001 EXPECT_EQ(expected, set_y_overflow.
height());
1003 Rect set_width_overflow(large_number, 0, 5, 100);
1004 EXPECT_EQ(5, set_width_overflow.
width());
1006 EXPECT_EQ(expected, set_width_overflow.
width());
1008 Rect set_x_overflow(100, 100, 100, 100);
1009 EXPECT_EQ(100, set_x_overflow.
width());
1010 set_x_overflow.
set_x(large_number);
1011 EXPECT_EQ(expected, set_x_overflow.
width());
1013 Point large_offset(large_number, large_number);
1015 Size expected_size(10, 10);
1017 Rect set_origin_overflow(100, 100, 100, 100);
1018 EXPECT_EQ(
size, set_origin_overflow.
size());
1019 set_origin_overflow.
set_origin(large_offset);
1020 EXPECT_EQ(large_offset, set_origin_overflow.
origin());
1021 EXPECT_EQ(expected_size, set_origin_overflow.
size());
1023 Rect set_size_overflow(large_number, large_number, 5, 5);
1024 EXPECT_EQ(
Size(5, 5), set_size_overflow.
size());
1026 EXPECT_EQ(large_offset, set_size_overflow.
origin());
1027 EXPECT_EQ(expected_size, set_size_overflow.
size());
1029 Rect set_rect_overflow;
1030 set_rect_overflow.
SetRect(large_number, large_number, 100, 100);
1031 EXPECT_EQ(large_offset, set_rect_overflow.
origin());
1032 EXPECT_EQ(expected_size, set_rect_overflow.
size());
1035 Rect inset_overflow;
1036 inset_overflow.
Inset(large_number, large_number, 100, 100);
1037 EXPECT_EQ(large_offset, inset_overflow.
origin());
1043 Rect inset_overflow2;
1044 inset_overflow2.
Inset(min_limit, min_limit, min_limit, min_limit);
1045 EXPECT_EQ(inset_overflow2,
gfx::Rect(min_limit, min_limit, limit, limit));
1053 Rect inset_overflow3(0, 0, limit, limit);
1054 inset_overflow3.
Inset(-100, -100, 100, 100);
1055 EXPECT_EQ(inset_overflow3,
gfx::Rect(-100, -100, limit, limit));
1057 Rect inset_overflow4(-1000, -1000, limit, limit);
1058 inset_overflow4.
Inset(100, 100, -100, -100);
1059 EXPECT_EQ(inset_overflow4,
gfx::Rect(-900, -900, limit, limit));
1061 Rect offset_overflow(0, 0, 100, 100);
1062 offset_overflow.
Offset(large_number, large_number);
1063 EXPECT_EQ(large_offset, offset_overflow.
origin());
1064 EXPECT_EQ(expected_size, offset_overflow.
size());
1066 Rect operator_overflow(0, 0, 100, 100);
1067 operator_overflow +=
Vector2d(large_number, large_number);
1068 EXPECT_EQ(large_offset, operator_overflow.
origin());
1069 EXPECT_EQ(expected_size, operator_overflow.
size());
1071 Rect origin_maxint(limit, limit, limit, limit);
1077 Rect origin_small(0, 0, 100, 100);
1078 Rect big_clamped(50, 50, limit, limit);
1079 EXPECT_EQ(big_clamped.
right(), limit);
1082 Rect rect_limit(0, 0, limit, limit);
1083 EXPECT_EQ(unioned, rect_limit);
1089 Rect small(-500, -400, 100, 100);
1090 Rect big(-400, -500, limit, limit);
1092 EXPECT_EQ(
UnionRects(small, big),
Rect(-500, -500, limit, limit));
1097 Rect clamped(500, 500, limit, limit);
1098 Rect positive_origin(100, 100, 500, 500);
1103 Rect expected(100, 100, limit - 100, limit - 100);
1104 EXPECT_EQ(
UnionRects(clamped, positive_origin), expected);
1111 int part_limit = min_limit / 3;
1112 Rect left_minint(min_limit, min_limit, 1, 1);
1113 Rect right_maxint(limit - 1, limit - 1, limit, limit);
1114 Rect expected(part_limit, part_limit, 2 * part_limit, 2 * part_limit);
1118 EXPECT_EQ(limit,
result.height());
1119 EXPECT_EQ(limit,
result.width());
1122 EXPECT_GT(-part_limit,
result.x());
1123 EXPECT_LT(part_limit,
result.right());
1124 EXPECT_GT(-part_limit,
result.y());
1125 EXPECT_LT(part_limit,
result.bottom());
1137 Rect xy_underflow(-100000, -123456, 10, 20);
1139 Rect(min_int, min_int, 1000000, 2000000));
1143 Rect xy_overflow(100000, 123456, 10, 20);
1145 Rect(max_int, max_int, 0, 0));
1149 Rect size_underflow(-1, -2, 100000, 100000);
1151 Rect(100000, 200000, 0, 0));
1153 Rect size_overflow(-1, -2, 123456, 234567);
1155 Rect(-100000, -200000, max_int, max_int));
1157 Rect size_overflow2(1, 2, 123456, 234567);
1159 Rect(100000, 200000, max_int - 100000, max_int - 200000));
1161 Rect max_rect(max_int, max_int, max_int, max_int);
1163 Rect(max_int, max_int, 0, 0));
1165 Rect min_rect(min_int, min_int, max_int, max_int);
static void Union(SkRegion *rgn, const SkIRect &rect)
static constexpr double kEpsilon
static void test1(skiatest::Reporter *reporter, SkWriter32 *writer)
PointF CenterPoint() const
constexpr float y() const
constexpr float width() const
constexpr float height() const
constexpr float x() const
bool Intersects(const Rect &rect) const
constexpr int height() const
void set_width(int width)
void Offset(int horizontal, int vertical)
void set_origin(const Point &origin)
void AdjustToFit(const Rect &rect)
constexpr int right() const
constexpr const Point & origin() const
constexpr int bottom() const
bool SharesEdgeWith(const Rect &rect) const
void set_size(const Size &size)
void set_height(int height)
constexpr const Size & size() const
void Inset(int horizontal, int vertical)
void SetRect(int x, int y, int width, int height)
constexpr int width() const
const uint8_t uint32_t uint32_t GError ** error
#define EXPECT_RECTF_EQ(a, b)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
sk_sp< SkBlender > blender SkRect rect
bool Contains(const Container &container, const Value &value)
bool Equals(const T *a, const T *b)
Rect BoundingRect(const Point &p1, const Point &p2)
Rect IntersectRects(const Rect &a, const Rect &b)
Rect UnionRects(const Rect &a, const Rect &b)
Rect ToEnclosingRectIgnoringError(const RectF &r, float error)
Rect ToEnclosingRect(const RectF &r)
Rect ScaleToEnclosedRect(const Rect &rect, float x_scale, float y_scale)
RectF ScaleRect(const RectF &r, float x_scale, float y_scale)
Rect ScaleToEnclosingRectSafe(const Rect &rect, float x_scale, float y_scale)
Rect ScaleToEnclosingRect(const Rect &rect, float x_scale, float y_scale)
constexpr size_t size(const T(&array)[N]) noexcept
Rect ToEnclosedRect(const RectF &rect)
Rect ToFlooredRectDeprecated(const RectF &rect)
TEST(PointTest, ToPointF)
Rect ToNearestRect(const RectF &rect)
bool EMSCRIPTEN_KEEPALIVE IsEmpty(const SkPath &path)
#define EXPECT_FLOAT_AND_NAN_EQ(a, b)
#define EXPECT_TRUE(handle)