302TEST(RectTest, RectOverflowXYWH) {
303 auto min = std::numeric_limits<Scalar>::lowest();
304 auto max = std::numeric_limits<Scalar>::max();
305 auto inf = std::numeric_limits<Scalar>::infinity();
323 EXPECT_EQ(rect.GetLeft(), 5.0f);
324 EXPECT_EQ(rect.GetTop(), 10.0f);
325 EXPECT_EQ(rect.GetRight(), max);
326 EXPECT_EQ(rect.GetBottom(), 25.0f);
327 EXPECT_EQ(rect.GetX(), 5.0f);
328 EXPECT_EQ(rect.GetY(), 10.0f);
329 EXPECT_EQ(rect.GetWidth(), max);
330 EXPECT_EQ(rect.GetHeight(), 15.0f);
331 EXPECT_FALSE(rect.IsEmpty());
332 EXPECT_TRUE(rect.IsFinite());
338 EXPECT_EQ(rect.GetLeft(), max);
339 EXPECT_EQ(rect.GetTop(), 10.0f);
340 EXPECT_EQ(rect.GetRight(), inf);
341 EXPECT_EQ(rect.GetBottom(), 25.0f);
342 EXPECT_EQ(rect.GetX(), max);
343 EXPECT_EQ(rect.GetY(), 10.0f);
344 EXPECT_EQ(rect.GetWidth(), inf);
345 EXPECT_EQ(rect.GetHeight(), 15.0f);
346 EXPECT_FALSE(rect.IsEmpty());
347 EXPECT_FALSE(rect.IsFinite());
353 EXPECT_EQ(rect.GetLeft(), 5.0f);
354 EXPECT_EQ(rect.GetTop(), 10.0f);
355 EXPECT_EQ(rect.GetRight(), 25.0f);
356 EXPECT_EQ(rect.GetBottom(), max);
357 EXPECT_EQ(rect.GetX(), 5.0f);
358 EXPECT_EQ(rect.GetY(), 10.0f);
359 EXPECT_EQ(rect.GetWidth(), 20.0f);
360 EXPECT_EQ(rect.GetHeight(), max);
361 EXPECT_FALSE(rect.IsEmpty());
362 EXPECT_TRUE(rect.IsFinite());
368 EXPECT_EQ(rect.GetLeft(), 5.0f);
369 EXPECT_EQ(rect.GetTop(), max);
370 EXPECT_EQ(rect.GetRight(), 25.0f);
371 EXPECT_EQ(rect.GetBottom(), inf);
372 EXPECT_EQ(rect.GetX(), 5.0f);
373 EXPECT_EQ(rect.GetY(), max);
374 EXPECT_EQ(rect.GetWidth(), 20.0f);
375 EXPECT_EQ(rect.GetHeight(), inf);
376 EXPECT_FALSE(rect.IsEmpty());
377 EXPECT_FALSE(rect.IsFinite());
383 EXPECT_EQ(rect.GetLeft(), 5.0f);
384 EXPECT_EQ(rect.GetTop(), 10.0f);
385 EXPECT_EQ(rect.GetRight(), min);
386 EXPECT_EQ(rect.GetBottom(), 25.0f);
387 EXPECT_EQ(rect.GetX(), 5.0f);
388 EXPECT_EQ(rect.GetY(), 10.0f);
389 EXPECT_EQ(rect.GetWidth(), min);
390 EXPECT_EQ(rect.GetHeight(), 15.0f);
391 EXPECT_TRUE(rect.IsEmpty());
392 EXPECT_TRUE(rect.IsFinite());
398 EXPECT_EQ(rect.GetLeft(), min);
399 EXPECT_EQ(rect.GetTop(), 10.0f);
400 EXPECT_EQ(rect.GetRight(), -inf);
401 EXPECT_EQ(rect.GetBottom(), 25.0f);
402 EXPECT_EQ(rect.GetX(), min);
403 EXPECT_EQ(rect.GetY(), 10.0f);
404 EXPECT_EQ(rect.GetWidth(), -inf);
405 EXPECT_EQ(rect.GetHeight(), 15.0f);
406 EXPECT_TRUE(rect.IsEmpty());
407 EXPECT_FALSE(rect.IsFinite());
413 EXPECT_EQ(rect.GetLeft(), 5.0f);
414 EXPECT_EQ(rect.GetTop(), 10.0f);
415 EXPECT_EQ(rect.GetRight(), 25.0f);
416 EXPECT_EQ(rect.GetBottom(), min);
417 EXPECT_EQ(rect.GetX(), 5.0f);
418 EXPECT_EQ(rect.GetY(), 10.0f);
419 EXPECT_EQ(rect.GetWidth(), 20.0f);
420 EXPECT_EQ(rect.GetHeight(), min);
421 EXPECT_TRUE(rect.IsEmpty());
422 EXPECT_TRUE(rect.IsFinite());
428 EXPECT_EQ(rect.GetLeft(), 5.0f);
429 EXPECT_EQ(rect.GetTop(), min);
430 EXPECT_EQ(rect.GetRight(), 25.0f);
431 EXPECT_EQ(rect.GetBottom(), -inf);
432 EXPECT_EQ(rect.GetX(), 5.0f);
433 EXPECT_EQ(rect.GetY(), min);
434 EXPECT_EQ(rect.GetWidth(), 20.0f);
435 EXPECT_EQ(rect.GetHeight(), -inf);
436 EXPECT_TRUE(rect.IsEmpty());
437 EXPECT_FALSE(rect.IsFinite());
508TEST(RectTest, RectOverflowLTRB) {
509 auto min = std::numeric_limits<Scalar>::lowest();
510 auto max = std::numeric_limits<Scalar>::max();
511 auto inf = std::numeric_limits<Scalar>::infinity();
529 EXPECT_EQ(rect.GetLeft(), -5.0f);
530 EXPECT_EQ(rect.GetTop(), 10.0f);
531 EXPECT_EQ(rect.GetRight(), max);
532 EXPECT_EQ(rect.GetBottom(), 25.0f);
533 EXPECT_EQ(rect.GetX(), -5.0f);
534 EXPECT_EQ(rect.GetY(), 10.0f);
535 EXPECT_EQ(rect.GetWidth(), max);
536 EXPECT_EQ(rect.GetHeight(), 15.0f);
537 EXPECT_FALSE(rect.IsEmpty());
538 EXPECT_TRUE(rect.IsFinite());
544 EXPECT_EQ(rect.GetLeft(), min + 5.0f);
545 EXPECT_EQ(rect.GetTop(), 10.0f);
546 EXPECT_EQ(rect.GetRight(), max - 5.0f);
547 EXPECT_EQ(rect.GetBottom(), 25.0f);
548 EXPECT_EQ(rect.GetX(), min + 5.0f);
549 EXPECT_EQ(rect.GetY(), 10.0f);
550 EXPECT_EQ(rect.GetWidth(), inf);
551 EXPECT_EQ(rect.GetHeight(), 15.0f);
552 EXPECT_FALSE(rect.IsEmpty());
553 EXPECT_TRUE(rect.IsFinite());
559 EXPECT_EQ(rect.GetLeft(), 5.0f);
560 EXPECT_EQ(rect.GetTop(), -10.0f);
561 EXPECT_EQ(rect.GetRight(), 20.0f);
562 EXPECT_EQ(rect.GetBottom(), max);
563 EXPECT_EQ(rect.GetX(), 5.0f);
564 EXPECT_EQ(rect.GetY(), -10.0f);
565 EXPECT_EQ(rect.GetWidth(), 15.0f);
566 EXPECT_EQ(rect.GetHeight(), max);
567 EXPECT_FALSE(rect.IsEmpty());
568 EXPECT_TRUE(rect.IsFinite());
574 EXPECT_EQ(rect.GetLeft(), 5.0f);
575 EXPECT_EQ(rect.GetTop(), min + 10.0f);
576 EXPECT_EQ(rect.GetRight(), 20.0f);
577 EXPECT_EQ(rect.GetBottom(), max - 15.0f);
578 EXPECT_EQ(rect.GetX(), 5.0f);
579 EXPECT_EQ(rect.GetY(), min + 10.0f);
580 EXPECT_EQ(rect.GetWidth(), 15.0f);
581 EXPECT_EQ(rect.GetHeight(), inf);
582 EXPECT_FALSE(rect.IsEmpty());
583 EXPECT_TRUE(rect.IsFinite());
589 EXPECT_EQ(rect.GetLeft(), 5.0f);
590 EXPECT_EQ(rect.GetTop(), 10.0f);
591 EXPECT_EQ(rect.GetRight(), min);
592 EXPECT_EQ(rect.GetBottom(), 25.0f);
593 EXPECT_EQ(rect.GetX(), 5.0f);
594 EXPECT_EQ(rect.GetY(), 10.0f);
595 EXPECT_EQ(rect.GetWidth(), min);
596 EXPECT_EQ(rect.GetHeight(), 15.0f);
597 EXPECT_TRUE(rect.IsEmpty());
598 EXPECT_TRUE(rect.IsFinite());
604 EXPECT_EQ(rect.GetLeft(), max - 5.0f);
605 EXPECT_EQ(rect.GetTop(), 10.0f);
606 EXPECT_EQ(rect.GetRight(), min + 10.0f);
607 EXPECT_EQ(rect.GetBottom(), 25.0f);
608 EXPECT_EQ(rect.GetX(), max - 5.0f);
609 EXPECT_EQ(rect.GetY(), 10.0f);
610 EXPECT_EQ(rect.GetWidth(), -inf);
611 EXPECT_EQ(rect.GetHeight(), 15.0f);
612 EXPECT_TRUE(rect.IsEmpty());
613 EXPECT_TRUE(rect.IsFinite());
619 EXPECT_EQ(rect.GetLeft(), 5.0f);
620 EXPECT_EQ(rect.GetTop(), 10.0f);
621 EXPECT_EQ(rect.GetRight(), 20.0f);
622 EXPECT_EQ(rect.GetBottom(), min);
623 EXPECT_EQ(rect.GetX(), 5.0f);
624 EXPECT_EQ(rect.GetY(), 10.0f);
625 EXPECT_EQ(rect.GetWidth(), 15.0f);
626 EXPECT_EQ(rect.GetHeight(), min);
627 EXPECT_TRUE(rect.IsEmpty());
628 EXPECT_TRUE(rect.IsFinite());
634 EXPECT_EQ(rect.GetLeft(), 5.0f);
635 EXPECT_EQ(rect.GetTop(), max - 5.0f);
636 EXPECT_EQ(rect.GetRight(), 20.0f);
637 EXPECT_EQ(rect.GetBottom(), min + 10.0f);
638 EXPECT_EQ(rect.GetX(), 5.0f);
639 EXPECT_EQ(rect.GetY(), max - 5.0f);
640 EXPECT_EQ(rect.GetWidth(), 15.0f);
641 EXPECT_EQ(rect.GetHeight(), -inf);
642 EXPECT_TRUE(rect.IsEmpty());
643 EXPECT_TRUE(rect.IsFinite());
1056 rect.GetY() * scale,
1057 rect.GetWidth() * scale,
1058 rect.GetHeight() * scale);
1061 << rect <<
" * " << scale;
1063 << rect <<
" * " << scale;
1065 << rect <<
" * " << scale;
1067 << rect <<
" * " << scale;
1072 rect.GetY() * scale_y,
1073 rect.GetWidth() * scale_x,
1074 rect.GetHeight() * scale_y);
1077 << rect <<
" * " << scale_x <<
", " << scale_y;
1079 << rect <<
" * " << scale_x <<
", " << scale_y;
1081 << rect <<
" * " << scale_x <<
", " << scale_y;
1083 test1(rect, scale_x);
1084 test1(rect, scale_y);
1099 auto test1 = [](
IRect rect, int64_t scale) {
1101 rect.
GetY() * scale,
1105 EXPECT_EQ(rect.
Scale(scale), expected)
1106 << rect <<
" * " << scale;
1107 EXPECT_EQ(rect.
Scale(scale, scale), expected)
1108 << rect <<
" * " << scale;
1109 EXPECT_EQ(rect.
Scale(
IPoint(scale, scale)), expected)
1110 << rect <<
" * " << scale;
1111 EXPECT_EQ(rect.
Scale(
ISize(scale, scale)), expected)
1112 << rect <<
" * " << scale;
1115 auto test2 = [&test1](
IRect rect, int64_t scale_x, int64_t scale_y) {
1117 rect.
GetY() * scale_y,
1121 EXPECT_EQ(rect.
Scale(scale_x, scale_y), expected)
1122 << rect <<
" * " << scale_x <<
", " << scale_y;
1123 EXPECT_EQ(rect.
Scale(
IPoint(scale_x, scale_y)), expected)
1124 << rect <<
" * " << scale_x <<
", " << scale_y;
1125 EXPECT_EQ(rect.
Scale(
ISize(scale_x, scale_y)), expected)
1126 << rect <<
" * " << scale_x <<
", " << scale_y;
1128 test1(rect, scale_x);
1129 test1(rect, scale_y);
1158TEST(RectTest, RectGetNormalizingTransform) {
1164 EXPECT_EQ(r.GetNormalizingTransform(),
1173 auto m = r.GetNormalizingTransform();
1182 EXPECT_EQ(m *
Point(350, 600),
Point(0.5, 0.5));
1185 EXPECT_EQ(m *
Point(200, 300),
Point(-1, -1));
1186 EXPECT_EQ(m *
Point(500, 300),
Point(2, -1));
1188 EXPECT_EQ(m *
Point(200, 900),
Point(-1, 2));
1197 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 0, 10).GetNormalizingTransform(), zero);
1198 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 10, 0).GetNormalizingTransform(), zero);
1199 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 0, 0).GetNormalizingTransform(), zero);
1202 EXPECT_EQ(
Rect::MakeXYWH(10, 10, -1, 10).GetNormalizingTransform(), zero);
1203 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 10, -1).GetNormalizingTransform(), zero);
1204 EXPECT_EQ(
Rect::MakeXYWH(10, 10, -1, -1).GetNormalizingTransform(), zero);
1211 auto nan = std::numeric_limits<Scalar>::quiet_NaN();
1212 auto inf = std::numeric_limits<Scalar>::infinity();
1215 EXPECT_EQ(
Rect::MakeXYWH(10, 10, nan, 10).GetNormalizingTransform(), z);
1216 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 10, nan).GetNormalizingTransform(), z);
1217 EXPECT_EQ(
Rect::MakeXYWH(10, 10, nan, nan).GetNormalizingTransform(), z);
1220 EXPECT_EQ(
Rect::MakeXYWH(10, 10, inf, 10).GetNormalizingTransform(), z);
1221 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 10, inf).GetNormalizingTransform(), z);
1222 EXPECT_EQ(
Rect::MakeXYWH(10, 10, inf, inf).GetNormalizingTransform(), z);
1225 EXPECT_EQ(
Rect::MakeXYWH(10, 10, -inf, 10).GetNormalizingTransform(), z);
1226 EXPECT_EQ(
Rect::MakeXYWH(10, 10, 10, -inf).GetNormalizingTransform(), z);
1227 EXPECT_EQ(
Rect::MakeXYWH(10, 10, -inf, -inf).GetNormalizingTransform(), z);
1230 EXPECT_EQ(
Rect::MakeXYWH(nan, 10, 10, 10).GetNormalizingTransform(), z);
1231 EXPECT_EQ(
Rect::MakeXYWH(10, nan, 10, 10).GetNormalizingTransform(), z);
1232 EXPECT_EQ(
Rect::MakeXYWH(nan, nan, 10, 10).GetNormalizingTransform(), z);
1235 EXPECT_EQ(
Rect::MakeXYWH(inf, 10, 10, 10).GetNormalizingTransform(), z);
1236 EXPECT_EQ(
Rect::MakeXYWH(10, inf, 10, 10).GetNormalizingTransform(), z);
1237 EXPECT_EQ(
Rect::MakeXYWH(inf, inf, 10, 10).GetNormalizingTransform(), z);
1240 EXPECT_EQ(
Rect::MakeXYWH(-inf, 10, 10, 10).GetNormalizingTransform(), z);
1241 EXPECT_EQ(
Rect::MakeXYWH(10, -inf, 10, 10).GetNormalizingTransform(), z);
1242 EXPECT_EQ(
Rect::MakeXYWH(-inf, -inf, 10, 10).GetNormalizingTransform(), z);
1297 auto nan = std::numeric_limits<Scalar>::quiet_NaN();
1867 auto check_nans = [](
const Rect& a,
const Rect& b,
const std::string& label) {
1868 ASSERT_TRUE(a.IsFinite()) << label;
1869 ASSERT_TRUE(b.IsFinite()) << label;
1871 for (
int i = 1;
i < 16;
i++) {
1873 EXPECT_FALSE(
swap_nan(a,
i).Intersection(b).has_value())
1874 << label <<
", index = " <<
i;
1876 EXPECT_FALSE(a.Intersection(
swap_nan(b,
i)).has_value())
1877 << label <<
", index = " <<
i;
1879 for (
int j = 1; j < 16; j++) {
1881 << label <<
", indices = " <<
i <<
", " << j;
1886 auto check_empty_flips = [](
const Rect& a,
const Rect& b,
1887 const std::string& label) {
1888 ASSERT_FALSE(a.IsEmpty());
1892 EXPECT_FALSE(a.Intersection(
flip_lr(b)).has_value()) << label;
1893 EXPECT_TRUE(a.IntersectionOrEmpty(
flip_lr(b)).IsEmpty()) << label;
1894 EXPECT_FALSE(a.Intersection(
flip_tb(b)).has_value()) << label;
1895 EXPECT_TRUE(a.IntersectionOrEmpty(
flip_tb(b)).IsEmpty()) << label;
1896 EXPECT_FALSE(a.Intersection(
flip_lrtb(b)).has_value()) << label;
1897 EXPECT_TRUE(a.IntersectionOrEmpty(
flip_lrtb(b)).IsEmpty()) << label;
1900 EXPECT_FALSE(
flip_lr(a).Intersection(b).has_value()) << label;
1901 EXPECT_TRUE(
flip_lr(a).IntersectionOrEmpty(b).IsEmpty()) << label;
1902 EXPECT_FALSE(
flip_tb(a).Intersection(b).has_value()) << label;
1903 EXPECT_TRUE(
flip_tb(a).IntersectionOrEmpty(b).IsEmpty()) << label;
1904 EXPECT_FALSE(
flip_lrtb(a).Intersection(b).has_value()) << label;
1905 EXPECT_TRUE(
flip_lrtb(a).IntersectionOrEmpty(b).IsEmpty()) << label;
1908 EXPECT_FALSE(
flip_lr(a).Intersection(
flip_lr(b)).has_value()) << label;
1909 EXPECT_TRUE(
flip_lr(a).IntersectionOrEmpty(
flip_lr(b)).IsEmpty()) << label;
1910 EXPECT_FALSE(
flip_tb(a).Intersection(
flip_tb(b)).has_value()) << label;
1911 EXPECT_TRUE(
flip_tb(a).IntersectionOrEmpty(
flip_tb(b)).IsEmpty()) << label;
1917 auto test_non_empty = [&check_nans, &check_empty_flips](
1919 ASSERT_FALSE(a.IsEmpty()) << a;
1922 std::stringstream stream;
1923 stream << a <<
" union " << b;
1924 auto label = stream.str();
1926 EXPECT_TRUE(a.Intersection(b).has_value()) << label;
1927 EXPECT_TRUE(b.Intersection(a).has_value()) << label;
1928 EXPECT_EQ(a.Intersection(b), result) << label;
1929 EXPECT_EQ(b.Intersection(a), result) << label;
1930 check_empty_flips(a, b, label);
1931 check_nans(a, b, label);
1934 auto test_empty = [&check_nans, &check_empty_flips](
const Rect& a,
1936 ASSERT_FALSE(a.IsEmpty()) << a;
1939 std::stringstream stream;
1940 stream << a <<
" union " << b;
1941 auto label = stream.str();
1943 EXPECT_FALSE(a.Intersection(b).has_value()) << label;
1944 EXPECT_TRUE(a.IntersectionOrEmpty(b).IsEmpty()) << label;
1945 EXPECT_FALSE(b.Intersection(a).has_value()) << label;
1946 EXPECT_TRUE(b.IntersectionOrEmpty(a).IsEmpty()) << label;
1947 check_empty_flips(a, b, label);
1948 check_nans(a, b, label);
1970 test_non_empty(a, b, expected);
1984 test_non_empty(a, b, b);
2200TEST(RectTest, RectIntersectsWithRect) {
2201 auto check_nans = [](
const Rect& a,
const Rect& b,
const std::string& label) {
2202 ASSERT_TRUE(a.IsFinite()) << label;
2203 ASSERT_TRUE(b.IsFinite()) << label;
2205 for (
int i = 1;
i < 16;
i++) {
2207 EXPECT_FALSE(
swap_nan(a,
i).IntersectsWithRect(b))
2208 << label <<
", index = " <<
i;
2210 EXPECT_FALSE(a.IntersectsWithRect(
swap_nan(b,
i)))
2211 << label <<
", index = " <<
i;
2213 for (
int j = 1; j < 16; j++) {
2215 << label <<
", indices = " <<
i <<
", " << j;
2220 auto check_empty_flips = [](
const Rect& a,
const Rect& b,
2221 const std::string& label) {
2222 ASSERT_FALSE(a.IsEmpty());
2226 EXPECT_FALSE(a.IntersectsWithRect(
flip_lr(b))) << label;
2227 EXPECT_FALSE(a.IntersectsWithRect(
flip_tb(b))) << label;
2228 EXPECT_FALSE(a.IntersectsWithRect(
flip_lrtb(b))) << label;
2231 EXPECT_FALSE(
flip_lr(a).IntersectsWithRect(b)) << label;
2232 EXPECT_FALSE(
flip_tb(a).IntersectsWithRect(b)) << label;
2233 EXPECT_FALSE(
flip_lrtb(a).IntersectsWithRect(b)) << label;
2236 EXPECT_FALSE(
flip_lr(a).IntersectsWithRect(
flip_lr(b))) << label;
2237 EXPECT_FALSE(
flip_tb(a).IntersectsWithRect(
flip_tb(b))) << label;
2241 auto test_non_empty = [&check_nans, &check_empty_flips](
const Rect& a,
2243 ASSERT_FALSE(a.IsEmpty()) << a;
2246 std::stringstream stream;
2247 stream << a <<
" union " << b;
2248 auto label = stream.str();
2250 EXPECT_TRUE(a.IntersectsWithRect(b)) << label;
2251 EXPECT_TRUE(b.IntersectsWithRect(a)) << label;
2252 check_empty_flips(a, b, label);
2253 check_nans(a, b, label);
2256 auto test_empty = [&check_nans, &check_empty_flips](
const Rect& a,
2258 ASSERT_FALSE(a.IsEmpty()) << a;
2261 std::stringstream stream;
2262 stream << a <<
" union " << b;
2263 auto label = stream.str();
2265 EXPECT_FALSE(a.IntersectsWithRect(b)) << label;
2266 EXPECT_FALSE(b.IntersectsWithRect(a)) << label;
2267 check_empty_flips(a, b, label);
2268 check_nans(a, b, label);
2289 test_non_empty(a, b);
2303 test_non_empty(a, b);
2310 test_non_empty(a, b);
2406 auto check_nans = [](
const Rect& rect,
const Point& point,
2407 const std::string& label) {
2408 ASSERT_TRUE(rect.IsFinite()) << label;
2409 ASSERT_TRUE(point.IsFinite()) << label;
2411 for (
int i = 1;
i < 16;
i++) {
2412 EXPECT_FALSE(
swap_nan(rect,
i).Contains(point))
2413 << label <<
", index = " <<
i;
2414 for (
int j = 1; j < 4; j++) {
2416 << label <<
", indices = " <<
i <<
", " << j;
2421 auto check_empty_flips = [](
const Rect& rect,
const Point& point,
2422 const std::string& label) {
2423 ASSERT_FALSE(rect.IsEmpty());
2425 EXPECT_FALSE(
flip_lr(rect).Contains(point)) << label;
2426 EXPECT_FALSE(
flip_tb(rect).Contains(point)) << label;
2427 EXPECT_FALSE(
flip_lrtb(rect).Contains(point)) << label;
2430 auto test_inside = [&check_nans, &check_empty_flips](
const Rect& rect,
2431 const Point& point) {
2432 ASSERT_FALSE(rect.IsEmpty()) << rect;
2434 std::stringstream stream;
2435 stream << rect <<
" contains " << point;
2436 auto label = stream.str();
2438 EXPECT_TRUE(rect.Contains(point)) << label;
2439 check_empty_flips(rect, point, label);
2440 check_nans(rect, point, label);
2443 auto test_outside = [&check_nans, &check_empty_flips](
const Rect& rect,
2444 const Point& point) {
2445 ASSERT_FALSE(rect.IsEmpty()) << rect;
2447 std::stringstream stream;
2448 stream << rect <<
" contains " << point;
2449 auto label = stream.str();
2451 EXPECT_FALSE(rect.Contains(point)) << label;
2452 check_empty_flips(rect, point, label);
2453 check_nans(rect, point, label);
2459 auto p =
Point(100, 100);
2466 auto p =
Point(200, 200);
2472 auto p =
Point(99, 99);
2478 auto p =
Point(199, 199);
2485 auto p =
Point(199, 199);
2560TEST(RectTest, RectContainsInclusivePoint) {
2561 auto check_nans = [](
const Rect& rect,
const Point& point,
2562 const std::string& label) {
2563 ASSERT_TRUE(rect.IsFinite()) << label;
2564 ASSERT_TRUE(point.IsFinite()) << label;
2566 for (
int i = 1;
i < 16;
i++) {
2567 EXPECT_FALSE(
swap_nan(rect,
i).ContainsInclusive(point))
2568 << label <<
", index = " <<
i;
2569 for (
int j = 1; j < 4; j++) {
2571 << label <<
", indices = " <<
i <<
", " << j;
2576 auto check_empty_flips = [](
const Rect& rect,
const Point& point,
2577 const std::string& label) {
2578 ASSERT_FALSE(rect.IsEmpty());
2580 EXPECT_FALSE(
flip_lr(rect).ContainsInclusive(point)) << label;
2581 EXPECT_FALSE(
flip_tb(rect).ContainsInclusive(point)) << label;
2582 EXPECT_FALSE(
flip_lrtb(rect).ContainsInclusive(point)) << label;
2585 auto test_inside = [&check_nans, &check_empty_flips](
const Rect& rect,
2586 const Point& point) {
2587 ASSERT_FALSE(rect.IsEmpty()) << rect;
2589 std::stringstream stream;
2590 stream << rect <<
" contains " << point;
2591 auto label = stream.str();
2593 EXPECT_TRUE(rect.ContainsInclusive(point)) << label;
2594 check_empty_flips(rect, point, label);
2595 check_nans(rect, point, label);
2598 auto test_outside = [&check_nans, &check_empty_flips](
const Rect& rect,
2599 const Point& point) {
2600 ASSERT_FALSE(rect.IsEmpty()) << rect;
2602 std::stringstream stream;
2603 stream << rect <<
" contains " << point;
2604 auto label = stream.str();
2606 EXPECT_FALSE(rect.ContainsInclusive(point)) << label;
2607 check_empty_flips(rect, point, label);
2608 check_nans(rect, point, label);
2614 auto p =
Point(100, 100);
2621 auto p =
Point(200, 200);
2634 auto p =
Point(99, 99);
2640 auto p =
Point(199, 199);
2647 auto p =
Point(199, 199);
2730 auto check_nans = [](
const Rect& a,
const Rect& b,
const std::string& label) {
2731 ASSERT_TRUE(a.IsFinite()) << label;
2732 ASSERT_TRUE(b.IsFinite()) << label;
2733 ASSERT_FALSE(a.IsEmpty());
2735 for (
int i = 1;
i < 16;
i++) {
2737 EXPECT_FALSE(
swap_nan(a,
i).Contains(b)) << label <<
", index = " <<
i;
2739 EXPECT_TRUE(a.Contains(
swap_nan(b,
i))) << label <<
", index = " <<
i;
2741 for (
int j = 1; j < 16; j++) {
2743 << label <<
", indices = " <<
i <<
", " << j;
2748 auto check_empty_flips = [](
const Rect& a,
const Rect& b,
2749 const std::string& label) {
2750 ASSERT_FALSE(a.IsEmpty());
2752 ASSERT_FALSE(b.GetLeft() > b.GetRight() || b.GetTop() > b.GetBottom());
2755 EXPECT_TRUE(a.Contains(
flip_lr(b))) << label;
2756 EXPECT_TRUE(a.Contains(
flip_tb(b))) << label;
2757 EXPECT_TRUE(a.Contains(
flip_lrtb(b))) << label;
2760 EXPECT_FALSE(
flip_lr(a).Contains(b)) << label;
2761 EXPECT_FALSE(
flip_tb(a).Contains(b)) << label;
2762 EXPECT_FALSE(
flip_lrtb(a).Contains(b)) << label;
2770 auto test_inside = [&check_nans, &check_empty_flips](
const Rect& a,
2772 ASSERT_FALSE(a.IsEmpty()) << a;
2774 ASSERT_FALSE(b.GetLeft() > b.GetRight() || b.GetTop() > b.GetBottom());
2776 std::stringstream stream;
2777 stream << a <<
" contains " << b;
2778 auto label = stream.str();
2780 EXPECT_TRUE(a.Contains(b)) << label;
2781 check_empty_flips(a, b, label);
2782 check_nans(a, b, label);
2785 auto test_not_inside = [&check_nans, &check_empty_flips](
const Rect& a,
2787 ASSERT_FALSE(a.IsEmpty()) << a;
2790 ASSERT_FALSE(b.IsEmpty()) << b;
2792 std::stringstream stream;
2793 stream << a <<
" contains " << b;
2794 auto label = stream.str();
2796 EXPECT_FALSE(a.Contains(b)) << label;
2797 check_empty_flips(a, b, label);
2798 check_nans(a, b, label);
2822 test_not_inside(a, b);
2828 test_not_inside(a, b);
2834 test_not_inside(a, b);
2940 auto check_nans = [&cull_rect](
const Rect& diff_rect,
2941 const std::string& label) {
2942 EXPECT_TRUE(cull_rect.IsFinite()) << label;
2943 EXPECT_TRUE(diff_rect.IsFinite()) << label;
2945 for (
int i = 1;
i < 16;
i++) {
2947 EXPECT_FALSE(
swap_nan(cull_rect,
i).Cutout(diff_rect).has_value())
2948 << label <<
", index " <<
i;
2949 EXPECT_EQ(
swap_nan(cull_rect,
i).CutoutOrEmpty(diff_rect),
Rect())
2950 << label <<
", index " <<
i;
2953 EXPECT_TRUE(cull_rect.Cutout(
swap_nan(diff_rect,
i)).has_value())
2954 << label <<
", index " <<
i;
2955 EXPECT_EQ(cull_rect.CutoutOrEmpty(
swap_nan(diff_rect,
i)), cull_rect)
2956 << label <<
", index " <<
i;
2958 for (
int j = 1; j < 16; j++) {
2962 << label <<
", indices " <<
i <<
", " << j;
2965 << label <<
", indices " <<
i <<
", " << j;
2970 auto check_empty_flips = [&cull_rect](
const Rect& diff_rect,
2971 const std::string& label) {
2972 EXPECT_FALSE(cull_rect.IsEmpty()) << label;
2973 EXPECT_FALSE(diff_rect.IsEmpty()) << label;
2977 EXPECT_TRUE(cull_rect.Cutout(
flip_lr(diff_rect)).has_value()) << label;
2978 EXPECT_EQ(cull_rect.Cutout(
flip_lr(diff_rect)), cull_rect) << label;
2979 EXPECT_TRUE(cull_rect.Cutout(
flip_tb(diff_rect)).has_value()) << label;
2980 EXPECT_EQ(cull_rect.Cutout(
flip_tb(diff_rect)), cull_rect) << label;
2981 EXPECT_TRUE(cull_rect.Cutout(
flip_lrtb(diff_rect)).has_value()) << label;
2982 EXPECT_EQ(cull_rect.Cutout(
flip_lrtb(diff_rect)), cull_rect) << label;
2986 EXPECT_FALSE(
flip_lr(cull_rect).Cutout(diff_rect).has_value()) << label;
2987 EXPECT_EQ(
flip_lr(cull_rect).CutoutOrEmpty(diff_rect),
Rect()) << label;
2988 EXPECT_FALSE(
flip_tb(cull_rect).Cutout(diff_rect).has_value()) << label;
2989 EXPECT_EQ(
flip_tb(cull_rect).CutoutOrEmpty(diff_rect),
Rect()) << label;
2990 EXPECT_FALSE(
flip_lrtb(cull_rect).Cutout(diff_rect).has_value()) << label;
2991 EXPECT_EQ(
flip_lrtb(cull_rect).CutoutOrEmpty(diff_rect),
Rect()) << label;
2995 EXPECT_FALSE(
flip_lr(cull_rect).Cutout(
flip_lr(diff_rect)).has_value())
2999 EXPECT_FALSE(
flip_tb(cull_rect).Cutout(
flip_tb(diff_rect)).has_value())
3009 auto non_reducing = [&cull_rect, &check_empty_flips, &check_nans](
3010 const Rect& diff_rect,
const std::string& label) {
3011 EXPECT_EQ(cull_rect.Cutout(diff_rect), cull_rect) << label;
3012 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), cull_rect) << label;
3013 check_empty_flips(diff_rect, label);
3014 check_nans(diff_rect, label);
3017 auto reducing = [&cull_rect, &check_empty_flips, &check_nans](
3018 const Rect& diff_rect,
const Rect& result_rect,
3019 const std::string& label) {
3020 EXPECT_TRUE(!result_rect.IsEmpty());
3021 EXPECT_EQ(cull_rect.Cutout(diff_rect), result_rect) << label;
3022 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect), result_rect) << label;
3023 check_empty_flips(diff_rect, label);
3024 check_nans(diff_rect, label);
3027 auto emptying = [&cull_rect, &check_empty_flips, &check_nans](
3028 const Rect& diff_rect,
const std::string& label) {
3029 EXPECT_FALSE(cull_rect.Cutout(diff_rect).has_value()) << label;
3030 EXPECT_EQ(cull_rect.CutoutOrEmpty(diff_rect),
Rect()) << label;
3031 check_empty_flips(diff_rect, label);
3032 check_nans(diff_rect, label);
3036 non_reducing(
Rect::MakeLTRB(10, 10, 20, 20),
"outside UL corner");
3038 non_reducing(
Rect::MakeLTRB(40, 10, 50, 20),
"outside UR corner");
3040 non_reducing(
Rect::MakeLTRB(40, 40, 50, 50),
"outside LR corner");
3042 non_reducing(
Rect::MakeLTRB(10, 40, 20, 50),
"outside LR corner");
3046 non_reducing(
Rect::MakeLTRB(15, 15, 25, 25),
"covering UL corner");
3047 non_reducing(
Rect::MakeLTRB(35, 15, 45, 25),
"covering UR corner");
3048 non_reducing(
Rect::MakeLTRB(35, 35, 45, 45),
"covering LR corner");
3049 non_reducing(
Rect::MakeLTRB(15, 35, 25, 45),
"covering LL corner");
3052 non_reducing(
Rect::MakeLTRB(20, 15, 39, 25),
"Top edge left-biased");
3053 non_reducing(
Rect::MakeLTRB(21, 15, 40, 25),
"Top edge, right biased");
3054 non_reducing(
Rect::MakeLTRB(35, 20, 45, 39),
"Right edge, top-biased");
3055 non_reducing(
Rect::MakeLTRB(35, 21, 45, 40),
"Right edge, bottom-biased");
3056 non_reducing(
Rect::MakeLTRB(20, 35, 39, 45),
"Bottom edge, left-biased");
3057 non_reducing(
Rect::MakeLTRB(21, 35, 40, 45),
"Bottom edge, right-biased");
3058 non_reducing(
Rect::MakeLTRB(15, 20, 25, 39),
"Left edge, top-biased");
3059 non_reducing(
Rect::MakeLTRB(15, 21, 25, 40),
"Left edge, bottom-biased");
3062 non_reducing(
Rect::MakeLTRB(25, 15, 35, 45),
"Vertical interior slice");
3063 non_reducing(
Rect::MakeLTRB(15, 25, 45, 35),
"Horizontal interior slice");
3074 "Slice off bottom");
3080 non_reducing(
Rect::MakeLTRB(21, 21, 39, 39),
"Contained, non-covering");
3083 emptying(cull_rect,
"Perfectly covering");
3092 auto check_empty_flips = [&cull_rect](
const IRect& diff_rect,
3093 const std::string& label) {
3094 EXPECT_FALSE(diff_rect.
IsEmpty());
3095 EXPECT_FALSE(cull_rect.
IsEmpty());
3099 EXPECT_TRUE(cull_rect.
Cutout(
flip_lr(diff_rect)).has_value()) << label;
3100 EXPECT_EQ(cull_rect.
Cutout(
flip_lr(diff_rect)), cull_rect) << label;
3101 EXPECT_TRUE(cull_rect.
Cutout(
flip_tb(diff_rect)).has_value()) << label;
3102 EXPECT_EQ(cull_rect.
Cutout(
flip_tb(diff_rect)), cull_rect) << label;
3103 EXPECT_TRUE(cull_rect.
Cutout(
flip_lrtb(diff_rect)).has_value()) << label;
3104 EXPECT_EQ(cull_rect.
Cutout(
flip_lrtb(diff_rect)), cull_rect) << label;
3108 EXPECT_FALSE(
flip_lr(cull_rect).Cutout(diff_rect).has_value()) << label;
3109 EXPECT_EQ(
flip_lr(cull_rect).CutoutOrEmpty(diff_rect),
IRect()) << label;
3110 EXPECT_FALSE(
flip_tb(cull_rect).Cutout(diff_rect).has_value()) << label;
3111 EXPECT_EQ(
flip_tb(cull_rect).CutoutOrEmpty(diff_rect),
IRect()) << label;
3112 EXPECT_FALSE(
flip_lrtb(cull_rect).Cutout(diff_rect).has_value()) << label;
3113 EXPECT_EQ(
flip_lrtb(cull_rect).CutoutOrEmpty(diff_rect),
IRect()) << label;
3117 EXPECT_FALSE(
flip_lr(cull_rect).Cutout(
flip_lr(diff_rect)).has_value())
3121 EXPECT_FALSE(
flip_tb(cull_rect).Cutout(
flip_tb(diff_rect)).has_value())
3131 auto non_reducing = [&cull_rect, &check_empty_flips](
3132 const IRect& diff_rect,
const std::string& label) {
3133 EXPECT_EQ(cull_rect.
Cutout(diff_rect), cull_rect) << label;
3134 EXPECT_EQ(cull_rect.
CutoutOrEmpty(diff_rect), cull_rect) << label;
3135 check_empty_flips(diff_rect, label);
3138 auto reducing = [&cull_rect, &check_empty_flips](
const IRect& diff_rect,
3139 const IRect& result_rect,
3140 const std::string& label) {
3141 EXPECT_TRUE(!result_rect.IsEmpty());
3142 EXPECT_EQ(cull_rect.
Cutout(diff_rect), result_rect) << label;
3143 EXPECT_EQ(cull_rect.
CutoutOrEmpty(diff_rect), result_rect) << label;
3144 check_empty_flips(diff_rect, label);
3147 auto emptying = [&cull_rect, &check_empty_flips](
const IRect& diff_rect,
3148 const std::string& label) {
3149 EXPECT_FALSE(cull_rect.
Cutout(diff_rect).has_value()) << label;
3151 check_empty_flips(diff_rect, label);
3171 non_reducing(
IRect::MakeLTRB(20, 15, 39, 25),
"Top edge left-biased");
3172 non_reducing(
IRect::MakeLTRB(21, 15, 40, 25),
"Top edge, right biased");
3173 non_reducing(
IRect::MakeLTRB(35, 20, 45, 39),
"Right edge, top-biased");
3174 non_reducing(
IRect::MakeLTRB(35, 21, 45, 40),
"Right edge, bottom-biased");
3175 non_reducing(
IRect::MakeLTRB(20, 35, 39, 45),
"Bottom edge, left-biased");
3176 non_reducing(
IRect::MakeLTRB(21, 35, 40, 45),
"Bottom edge, right-biased");
3177 non_reducing(
IRect::MakeLTRB(15, 20, 25, 39),
"Left edge, top-biased");
3178 non_reducing(
IRect::MakeLTRB(15, 21, 25, 40),
"Left edge, bottom-biased");
3181 non_reducing(
IRect::MakeLTRB(25, 15, 35, 45),
"Vertical interior slice");
3182 non_reducing(
IRect::MakeLTRB(15, 25, 45, 35),
"Horizontal interior slice");
3193 "Slice off bottom");
3199 non_reducing(
IRect::MakeLTRB(21, 21, 39, 39),
"Contained, non-covering");
3202 emptying(cull_rect,
"Perfectly covering");