@@ -73,24 +73,28 @@ TEST(RectTest, NormalizePoint) {
73
73
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (Point (px, py)),
74
74
expected)
75
75
<< " Point(" << pt_desc << " ) in " << rect_desc << " Rect" ;
76
+
76
77
// Scalar point inside Integer rect
77
78
EXPECT_EQ (IRect::MakeLTRB (l, t, r, b).NormalizePoint (Point (px, py)),
78
79
expected)
79
80
<< " Point(" << pt_desc << " ) in " << rect_desc << " IRect" ;
81
+
80
82
// Integer point inside Scalar rect
81
83
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (IPoint (px, py)),
82
84
expected)
83
85
<< " IPoint(" << pt_desc << " ) in " << rect_desc << " Rect" ;
86
+
84
87
// Integer point inside Integer rect
85
88
EXPECT_EQ (IRect::MakeLTRB (l, t, r, b).NormalizePoint (IPoint (px, py)),
86
89
expected)
87
90
<< " IPoint(" << pt_desc << " ) in " << rect_desc << " IRect" ;
88
91
92
+ // Now test nan handling by substituting a nan for the X and/or Y of
93
+ // the point.
89
94
auto nan = std::numeric_limits<Scalar>::quiet_NaN ();
90
95
auto nan_x = Point (nan, py);
91
96
auto nan_y = Point (px, nan);
92
97
auto nan_p = Point (nan, nan);
93
- // Nan Scalar point inside Scalar and integer rects
94
98
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (nan_x), Point ())
95
99
<< " Point(NaN x) in " << rect_desc << " Rect" ;
96
100
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (nan_y), Point ())
@@ -105,29 +109,39 @@ TEST(RectTest, NormalizePoint) {
105
109
<< " Point(NaN x&y) in " << rect_desc << " Rect" ;
106
110
};
107
111
108
- // Tests a rectangle using test_one both normally and all variants of
109
- // being empty by reversing the lr and tb points.
112
+ // Tests the rectangle as specified, which is assumed to be non-empty
113
+ // and then tests it in various states of emptiness in both dimensions
114
+ // by reversing left/right and top/bottom or using the same value for
115
+ // both.
110
116
auto test = [&test_one](int64_t l, int64_t t, int64_t r, int64_t b, //
111
117
int64_t px, int64_t py, //
112
118
const std::string& pt_desc, Point expected) {
113
- test_one (l, t, r, b, " non-empty" , px, py, pt_desc, expected);
114
- test_one (l, t, l, b, " LR empty" , px, py, pt_desc, Point ());
115
- test_one (r, t, l, b, " LR reversed" , px, py, pt_desc, Point ());
116
- test_one (l, t, r, t, " TB empty" , px, py, pt_desc, Point ());
117
- test_one (l, b, r, t, " TB reversed" , px, py, pt_desc, Point ());
118
- test_one (l, t, l, t, " all empty" , px, py, pt_desc, Point ());
119
- test_one (r, b, l, t, " all reversed" , px, py, pt_desc, Point ());
119
+ // clang-format off
120
+ // rect point expected
121
+ // rect description point desc result
122
+ test_one (l, t, r, b, " non-empty" , px, py, pt_desc, expected);
123
+ test_one (l, t, l, b, " LR empty" , px, py, pt_desc, Point ());
124
+ test_one (r, t, l, b, " LR reversed" , px, py, pt_desc, Point ());
125
+ test_one (l, t, r, t, " TB empty" , px, py, pt_desc, Point ());
126
+ test_one (l, b, r, t, " TB reversed" , px, py, pt_desc, Point ());
127
+ test_one (l, t, l, t, " all empty" , px, py, pt_desc, Point ());
128
+ test_one (r, b, l, t, " all reversed" , px, py, pt_desc, Point ());
129
+ // clang-format on
120
130
};
121
131
122
- test (100 , 100 , 200 , 200 , 100 , 100 , " UL" , Point (0 , 0 ));
123
- test (100 , 100 , 200 , 200 , 200 , 100 , " UR" , Point (1 , 0 ));
124
- test (100 , 100 , 200 , 200 , 200 , 200 , " LR" , Point (1 , 1 ));
125
- test (100 , 100 , 200 , 200 , 100 , 200 , " LL" , Point (0 , 1 ));
126
- test (100 , 100 , 200 , 200 , 150 , 150 , " Center" , Point (0.5 , 0.5 ));
127
- test (100 , 100 , 200 , 200 , 0 , 0 , " outside UL" , Point (-1 , -1 ));
128
- test (100 , 100 , 200 , 200 , 300 , 0 , " outside UR" , Point (2 , -1 ));
129
- test (100 , 100 , 200 , 200 , 300 , 300 , " outside LR" , Point (2 , 2 ));
130
- test (100 , 100 , 200 , 200 , 0 , 300 , " outside LL" , Point (-1 , 2 ));
132
+ // clang-format off
133
+ // rect point point expected
134
+ // [ l t r b ] [ px py ] description result
135
+ test (100 , 100 , 200 , 200 , 100 , 100 , " UL" , Point (0 , 0 ));
136
+ test (100 , 100 , 200 , 200 , 200 , 100 , " UR" , Point (1 , 0 ));
137
+ test (100 , 100 , 200 , 200 , 200 , 200 , " LR" , Point (1 , 1 ));
138
+ test (100 , 100 , 200 , 200 , 100 , 200 , " LL" , Point (0 , 1 ));
139
+ test (100 , 100 , 200 , 200 , 150 , 150 , " Center" , Point (0.5 , 0.5 ));
140
+ test (100 , 100 , 200 , 200 , 0 , 0 , " outside UL" , Point (-1 , -1 ));
141
+ test (100 , 100 , 200 , 200 , 300 , 0 , " outside UR" , Point (2 , -1 ));
142
+ test (100 , 100 , 200 , 200 , 300 , 300 , " outside LR" , Point (2 , 2 ));
143
+ test (100 , 100 , 200 , 200 , 0 , 300 , " outside LL" , Point (-1 , 2 ));
144
+ // clang-format on
131
145
132
146
// We can't test the true min and max due to overflow of the xywh
133
147
// internal representation, but we can test with half their values.
@@ -156,56 +170,64 @@ TEST(RectTest, NormalizePointToNonFiniteRects) {
156
170
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (Point (px, py)),
157
171
expected)
158
172
<< " Point(" << pt_desc << " ) in Rect" ;
173
+
159
174
// Scalar point inside Scalar rect with NaN left
160
175
EXPECT_EQ (Rect::MakeLTRB (nan, t, r, b).NormalizePoint (Point (px, py)),
161
176
Point ())
162
177
<< " Point(" << pt_desc << " ) in Rect NaN Left" ;
178
+
163
179
// Scalar point inside Scalar rect with NaN top
164
180
EXPECT_EQ (Rect::MakeLTRB (l, nan, r, b).NormalizePoint (Point (px, py)),
165
181
Point ())
166
182
<< " Point(" << pt_desc << " ) in Rect NaN Top" ;
183
+
167
184
// Scalar point inside Scalar rect with NaN right
168
185
EXPECT_EQ (Rect::MakeLTRB (l, t, nan, b).NormalizePoint (Point (px, py)),
169
186
Point ())
170
187
<< " Point(" << pt_desc << " ) in Rect NaN Left" ;
188
+
171
189
// Scalar point inside Scalar rect with NaN bottom
172
190
EXPECT_EQ (Rect::MakeLTRB (l, t, r, nan).NormalizePoint (Point (px, py)),
173
191
Point ())
174
192
<< " Point(" << pt_desc << " ) in Rect NaN Top" ;
193
+
175
194
// Scalar point inside Scalar rect with infinite left
176
195
EXPECT_EQ (Rect::MakeLTRB (-inf, t, r, b).NormalizePoint (Point (px, py)),
177
196
Point ())
178
197
<< " Point(" << pt_desc << " ) in Rect -Inf Left" ;
198
+
179
199
// Scalar point inside Scalar rect with infinite top
180
200
EXPECT_EQ (Rect::MakeLTRB (l, -inf, r, b).NormalizePoint (Point (px, py)),
181
201
Point ())
182
202
<< " Point(" << pt_desc << " ) in Rect -Inf Top" ;
203
+
183
204
// Scalar point inside Scalar rect with infinite right
184
205
EXPECT_EQ (Rect::MakeLTRB (l, t, inf, b).NormalizePoint (Point (px, py)),
185
206
Point (0 , expected.y ))
186
207
<< " Point(" << pt_desc << " ) in Rect Inf Right" ;
208
+
187
209
// Scalar point inside Scalar rect with infinite bottom
188
210
EXPECT_EQ (Rect::MakeLTRB (l, t, r, inf).NormalizePoint (Point (px, py)),
189
211
Point (expected.x , 0 ))
190
212
<< " Point(" << pt_desc << " ) in Rect Inf Bottom" ;
191
213
192
- // Testing with NaN points
214
+ // Now test NaN handling by substituting a NaN for the X and/or Y of
215
+ // the point.
193
216
auto nan_x = Point (nan, py);
194
217
auto nan_y = Point (px, nan);
195
218
auto nan_p = Point (nan, nan);
196
- // Nan Scalar point inside Scalar rect
197
219
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (nan_x), Point ())
198
220
<< " Point(NaN x) in Rect" ;
199
221
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (nan_y), Point ())
200
222
<< " Point(NaN y) in Rect" ;
201
223
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (nan_p), Point ())
202
224
<< " Point(NaN x&y) in Rect" ;
203
225
204
- // Testing with infinite points
226
+ // Now test +/- infinity handling by substituting an infinity for the
227
+ // X and/or Y of the point.
205
228
auto inf_x = Point (inf, py);
206
229
auto inf_y = Point (px, inf);
207
230
auto inf_p = Point (inf, inf);
208
- // Infinite Scalar point inside Scalar rect
209
231
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (inf_x), Point ())
210
232
<< " Point(Infinite x) in Rect" ;
211
233
EXPECT_EQ (Rect::MakeLTRB (l, t, r, b).NormalizePoint (inf_y), Point ())
@@ -220,23 +242,19 @@ TEST(RectTest, NormalizePointToNonFiniteRects) {
220
242
<< " Point(-Infinite x&y) in Rect" ;
221
243
};
222
244
223
- test (100 , 100 , 200 , 200 , 100 , 100 , " UL" , Point (0 , 0 ));
224
- test (100 , 100 , 200 , 200 , 200 , 100 , " UR" , Point (1 , 0 ));
225
- test (100 , 100 , 200 , 200 , 200 , 200 , " LR" , Point (1 , 1 ));
226
- test (100 , 100 , 200 , 200 , 100 , 200 , " LL" , Point (0 , 1 ));
227
- test (100 , 100 , 200 , 200 , 150 , 150 , " Center" , Point (0.5 , 0.5 ));
228
- test (100 , 100 , 200 , 200 , 0 , 0 , " outside UL" , Point (-1 , -1 ));
229
- test (100 , 100 , 200 , 200 , 300 , 0 , " outside UR" , Point (2 , -1 ));
230
- test (100 , 100 , 200 , 200 , 300 , 300 , " outside LR" , Point (2 , 2 ));
231
- test (100 , 100 , 200 , 200 , 0 , 300 , " outside LL" , Point (-1 , 2 ));
232
-
233
- // We can't test the true min and max due to overflow of the xywh
234
- // internal representation, but we can test with half their values.
235
- // When TRect is converted to ltrb notation, we can relax this
236
- // restriction.
237
- int64_t min_int = std::numeric_limits<int64_t >::min () / 2 ;
238
- int64_t max_int = std::numeric_limits<int64_t >::max () / 2 ;
239
- test (min_int, 100 , max_int, 200 , 0 , 150 , " max int center" , Point (0.5 , 0.5 ));
245
+ // clang-format off
246
+ // rect point point expected
247
+ // [ l t r b ] [ px py ] description result
248
+ test (100 , 100 , 200 , 200 , 100 , 100 , " UL" , Point (0 , 0 ));
249
+ test (100 , 100 , 200 , 200 , 200 , 100 , " UR" , Point (1 , 0 ));
250
+ test (100 , 100 , 200 , 200 , 200 , 200 , " LR" , Point (1 , 1 ));
251
+ test (100 , 100 , 200 , 200 , 100 , 200 , " LL" , Point (0 , 1 ));
252
+ test (100 , 100 , 200 , 200 , 150 , 150 , " Center" , Point (0.5 , 0.5 ));
253
+ test (100 , 100 , 200 , 200 , 0 , 0 , " outside UL" , Point (-1 , -1 ));
254
+ test (100 , 100 , 200 , 200 , 300 , 0 , " outside UR" , Point (2 , -1 ));
255
+ test (100 , 100 , 200 , 200 , 300 , 300 , " outside LR" , Point (2 , 2 ));
256
+ test (100 , 100 , 200 , 200 , 0 , 300 , " outside LL" , Point (-1 , 2 ));
257
+ // clang-format on
240
258
}
241
259
242
260
} // namespace testing
0 commit comments