rectangle_tests.cpp (1734B)
1 // SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #include "common/gsvector.h" 5 #include <gtest/gtest.h> 6 7 TEST(Rectangle, AdjacentRectanglesNotIntersecting) 8 { 9 GSVector4i r1(0, 0, 10, 10); 10 GSVector4i r2(10, 10, 20, 20); 11 ASSERT_FALSE(r1.rintersects(r2)); 12 } 13 14 TEST(Rectangle, IntersectingRectanglesIntersecting) 15 { 16 GSVector4i r1(0, 0, 10, 10); 17 GSVector4i r2(9, 9, 14, 14); 18 ASSERT_TRUE(r1.rintersects(r2)); 19 ASSERT_TRUE(r2.rintersects(r1)); 20 } 21 22 TEST(Rectangle, PointContainedInRectangle) 23 { 24 GSVector4i r1(0, 0, 10, 10); 25 GSVector4i r2(5, 5, 6, 6); 26 ASSERT_TRUE(r1.rcontains(r2)); 27 } 28 29 TEST(Rectangle, PointOutsideRectangleNotContained) 30 { 31 GSVector4i r1(0, 0, 10, 10); 32 GSVector4i r2(10, 10, 11, 11); 33 ASSERT_FALSE(r1.rcontains(r2)); 34 } 35 36 TEST(Rectangle, RectangleSize) 37 { 38 GSVector4i r(0, 0, 10, 10); 39 ASSERT_EQ(r.width(), 10); 40 ASSERT_EQ(r.height(), 10); 41 } 42 43 TEST(Rectangle, IncludeAfterInvalid) 44 { 45 GSVector4i r(0, 0, 1, 1); 46 GSVector4i r2(5, 5, 10, 10); 47 GSVector4i ru(0, 0, 10, 10); 48 ASSERT_TRUE(r.runion(r2).eq(ru)); 49 } 50 51 TEST(Rectangle, EmptyRectangleHasNoExtents) 52 { 53 GSVector4i r(0, 0, 0, 0); 54 ASSERT_EQ(r.width(), 0); 55 ASSERT_EQ(r.height(), 0); 56 ASSERT_TRUE(r.rempty()); 57 } 58 59 TEST(Rectangle, NonEmptyRectangleHasExtents) 60 { 61 GSVector4i r(0, 0, 1, 1); 62 ASSERT_EQ(r.width(), 1); 63 ASSERT_EQ(r.height(), 1); 64 ASSERT_FALSE(r.rempty()); 65 } 66 67 TEST(Rectangle, RelationalOperators) 68 { 69 GSVector4i r1(0, 0, 1, 1); 70 GSVector4i r2(1, 1, 2, 2); 71 72 ASSERT_TRUE(r1.eq(r1)); 73 ASSERT_TRUE(r1.lt32(r2).alltrue()); 74 ASSERT_TRUE(r2.eq(r2)); 75 ASSERT_TRUE(r2.gt32(r1).alltrue()); 76 ASSERT_FALSE(r2.lt32(r1).alltrue()); 77 ASSERT_FALSE(r1.eq(r2)); 78 } 79