18 class TBOXTest :
public testing::Test {
21 std::locale::global(std::locale(
""));
27 TEST_F(TBOXTest, OverlapInside) {
28 TBOX a(10, 10, 20, 20);
29 TBOX b(11, 11, 12, 12);
31 EXPECT_TRUE(a.overlap(b));
32 EXPECT_TRUE(b.overlap(a));
33 EXPECT_DOUBLE_EQ(0.01, a.overlap_fraction(b));
34 EXPECT_DOUBLE_EQ(1.0, b.overlap_fraction(a));
37 TEST_F(TBOXTest, OverlapBoolCorners) {
38 TBOX mid(10, 10, 30, 30);
39 TBOX bottom_left(5, 5, 15, 15);
40 TBOX top_left(5, 25, 15, 35);
43 EXPECT_TRUE(mid.overlap(bottom_left));
44 EXPECT_TRUE(bottom_left.overlap(mid));
45 EXPECT_TRUE(mid.overlap(top_left));
46 EXPECT_TRUE(top_left.overlap(mid));
49 TEST_F(TBOXTest, OverlapFractionCorners) {
50 TBOX mid(10, 10, 30, 30);
51 TBOX bottom_left(5, 5, 15, 15);
52 TBOX top_left(5, 25, 15, 35);
55 EXPECT_DOUBLE_EQ((5.0 * 5.0) / (20.0 * 20.0),
56 mid.overlap_fraction(bottom_left));
57 EXPECT_DOUBLE_EQ((5.0 * 5.0) / (10.0 * 10.0),
58 bottom_left.overlap_fraction(mid));
59 EXPECT_DOUBLE_EQ((5.0 * 5.0) / (20.0 * 20.0), mid.overlap_fraction(top_left));
60 EXPECT_DOUBLE_EQ((5.0 * 5.0) / (10.0 * 10.0), top_left.overlap_fraction(mid));
63 TEST_F(TBOXTest, OverlapBoolSides) {
64 TBOX mid(10, 10, 30, 30);
65 TBOX left(5, 15, 15, 25);
66 TBOX bottom(15, 5, 25, 15);
69 EXPECT_TRUE(mid.overlap(left));
70 EXPECT_TRUE(left.overlap(mid));
71 EXPECT_TRUE(mid.overlap(bottom));
72 EXPECT_TRUE(bottom.overlap(mid));
75 TEST_F(TBOXTest, OverlapFractionSides) {
76 TBOX mid(10, 10, 30, 30);
77 TBOX left(5, 15, 15, 25);
78 TBOX bottom(15, 5, 25, 15);
81 EXPECT_DOUBLE_EQ((5.0 * 10.0) / (20.0 * 20.0), mid.overlap_fraction(left));
82 EXPECT_DOUBLE_EQ((5.0 * 10.0) / (10.0 * 10.0), left.overlap_fraction(mid));
83 EXPECT_DOUBLE_EQ((5.0 * 10.0) / (20.0 * 20.0), mid.overlap_fraction(bottom));
84 EXPECT_DOUBLE_EQ((5.0 * 10.0) / (10.0 * 10.0), bottom.overlap_fraction(mid));
87 TEST_F(TBOXTest, OverlapBoolSpan) {
88 TBOX mid(10, 10, 30, 30);
89 TBOX vertical(15, 5, 25, 35);
90 TBOX horizontal(5, 15, 35, 25);
93 EXPECT_TRUE(mid.overlap(vertical));
94 EXPECT_TRUE(vertical.overlap(mid));
95 EXPECT_TRUE(mid.overlap(horizontal));
96 EXPECT_TRUE(horizontal.overlap(mid));
99 TEST_F(TBOXTest, OverlapFractionSpan) {
100 TBOX mid(10, 10, 30, 30);
101 TBOX vertical(15, 5, 25, 35);
102 TBOX horizontal(5, 15, 35, 25);
105 EXPECT_DOUBLE_EQ((10.0 * 20.0) / (20.0 * 20.0),
106 mid.overlap_fraction(vertical));
107 EXPECT_DOUBLE_EQ((10.0 * 20.0) / (10.0 * 30.0),
108 vertical.overlap_fraction(mid));
109 EXPECT_DOUBLE_EQ((20.0 * 10.0) / (20.0 * 20.0),
110 mid.overlap_fraction(horizontal));
111 EXPECT_DOUBLE_EQ((20.0 * 10.0) / (30.0 * 10.0),
112 horizontal.overlap_fraction(mid));
116 TEST_F(TBOXTest, OverlapOutsideTests) {
117 TBOX mid(10, 10, 30, 30);
118 TBOX left(0, 15, 5, 25);
120 EXPECT_FALSE(mid.overlap(left));
121 EXPECT_FALSE(left.overlap(mid));
122 EXPECT_DOUBLE_EQ(0.0, mid.overlap_fraction(left));
123 EXPECT_DOUBLE_EQ(0.0, left.overlap_fraction(mid));
126 TEST_F(TBOXTest, OverlapXFraction) {
127 TBOX a(10, 10, 20, 20);
128 TBOX b(12, 100, 26, 200);
129 TBOX c(0, 0, 100, 100);
132 EXPECT_DOUBLE_EQ(8.0 / 10.0, a.x_overlap_fraction(b));
133 EXPECT_DOUBLE_EQ(8.0 / 14.0, b.x_overlap_fraction(a));
134 EXPECT_DOUBLE_EQ(1.0, a.x_overlap_fraction(c));
135 EXPECT_DOUBLE_EQ(10.0 / 100.0, c.x_overlap_fraction(a));
136 EXPECT_DOUBLE_EQ(0.0, a.x_overlap_fraction(d));
137 EXPECT_DOUBLE_EQ(0.0, d.x_overlap_fraction(a));
140 TEST_F(TBOXTest, OverlapYFraction) {
141 TBOX a(10, 10, 20, 20);
142 TBOX b(100, 12, 200, 26);
143 TBOX c(0, 0, 100, 100);
146 EXPECT_DOUBLE_EQ(8.0 / 10.0, a.y_overlap_fraction(b));
147 EXPECT_DOUBLE_EQ(8.0 / 14.0, b.y_overlap_fraction(a));
148 EXPECT_DOUBLE_EQ(1.0, a.y_overlap_fraction(c));
149 EXPECT_DOUBLE_EQ(10.0 / 100.0, c.y_overlap_fraction(a));
150 EXPECT_DOUBLE_EQ(0.0, a.y_overlap_fraction(d));
151 EXPECT_DOUBLE_EQ(0.0, d.y_overlap_fraction(a));
154 TEST_F(TBOXTest, OverlapXFractionZeroSize) {
155 TBOX zero(10, 10, 10, 10);
156 TBOX big(0, 0, 100, 100);
157 TBOX small(0, 0, 1, 1);
159 EXPECT_DOUBLE_EQ(1.0, zero.x_overlap_fraction(big));
160 EXPECT_DOUBLE_EQ(0.0, big.x_overlap_fraction(zero));
161 EXPECT_DOUBLE_EQ(0.0, zero.x_overlap_fraction(small));
162 EXPECT_DOUBLE_EQ(0.0, small.x_overlap_fraction(zero));
165 TEST_F(TBOXTest, OverlapYFractionZeroSize) {
166 TBOX zero(10, 10, 10, 10);
167 TBOX big(0, 0, 100, 100);
168 TBOX small(0, 0, 1, 1);
170 EXPECT_DOUBLE_EQ(1.0, zero.y_overlap_fraction(big));
171 EXPECT_DOUBLE_EQ(0.0, big.y_overlap_fraction(zero));
172 EXPECT_DOUBLE_EQ(0.0, zero.y_overlap_fraction(small));
173 EXPECT_DOUBLE_EQ(0.0, small.y_overlap_fraction(zero));