@@ -1369,6 +1369,65 @@ TEST(GeometryTest, RectIntersectsWithRect) {
13691369 }
13701370}
13711371
1372+ TEST (GeometryTest, RectCutout) {
1373+ // No cutout.
1374+ {
1375+ Rect a (0 , 0 , 100 , 100 );
1376+ Rect b (0 , 0 , 50 , 50 );
1377+ auto u = a.Cutout (b);
1378+ ASSERT_TRUE (u.has_value ());
1379+ ASSERT_RECT_NEAR (u.value (), a);
1380+ }
1381+
1382+ // Full cutout.
1383+ {
1384+ Rect a (0 , 0 , 100 , 100 );
1385+ Rect b (-10 , -10 , 120 , 120 );
1386+ auto u = a.Cutout (b);
1387+ ASSERT_FALSE (u.has_value ());
1388+ }
1389+
1390+ // Cutout from top.
1391+ {
1392+ auto a = Rect::MakeLTRB (0 , 0 , 100 , 100 );
1393+ auto b = Rect::MakeLTRB (-10 , -10 , 110 , 90 );
1394+ auto u = a.Cutout (b);
1395+ auto expected = Rect::MakeLTRB (0 , 90 , 100 , 100 );
1396+ ASSERT_TRUE (u.has_value ());
1397+ ASSERT_RECT_NEAR (u.value (), expected);
1398+ }
1399+
1400+ // Cutout from bottom.
1401+ {
1402+ auto a = Rect::MakeLTRB (0 , 0 , 100 , 100 );
1403+ auto b = Rect::MakeLTRB (-10 , 10 , 110 , 110 );
1404+ auto u = a.Cutout (b);
1405+ auto expected = Rect::MakeLTRB (0 , 0 , 100 , 10 );
1406+ ASSERT_TRUE (u.has_value ());
1407+ ASSERT_RECT_NEAR (u.value (), expected);
1408+ }
1409+
1410+ // Cutout from left.
1411+ {
1412+ auto a = Rect::MakeLTRB (0 , 0 , 100 , 100 );
1413+ auto b = Rect::MakeLTRB (-10 , -10 , 90 , 110 );
1414+ auto u = a.Cutout (b);
1415+ auto expected = Rect::MakeLTRB (90 , 0 , 100 , 100 );
1416+ ASSERT_TRUE (u.has_value ());
1417+ ASSERT_RECT_NEAR (u.value (), expected);
1418+ }
1419+
1420+ // Cutout from right.
1421+ {
1422+ auto a = Rect::MakeLTRB (0 , 0 , 100 , 100 );
1423+ auto b = Rect::MakeLTRB (10 , -10 , 110 , 110 );
1424+ auto u = a.Cutout (b);
1425+ auto expected = Rect::MakeLTRB (0 , 0 , 10 , 100 );
1426+ ASSERT_TRUE (u.has_value ());
1427+ ASSERT_RECT_NEAR (u.value (), expected);
1428+ }
1429+ }
1430+
13721431TEST (GeometryTest, RectContainsPoint) {
13731432 {
13741433 // Origin is inclusive
0 commit comments