60 int min[2] = { 10, 20 };
61 int max[2] = { 30, 40 };
62 builder.
Add( min, max, 42 );
64 auto tree = builder.
Build();
66 BOOST_CHECK( !tree.empty() );
70 int sMin[2] = { 0, 0 };
71 int sMax[2] = { 15, 25 };
72 std::vector<intptr_t> results;
74 auto collect = [&results]( intptr_t val )
76 results.push_back( val );
86 int sMin2[2] = { 100, 100 };
87 int sMax2[2] = { 200, 200 };
89 BOOST_CHECK( results.empty() );
99 for(
int y = 0; y < 10; ++y )
101 for(
int x = 0; x < 10; ++x )
103 int min[2] = { x * 10, y * 10 };
104 int max[2] = { x * 10 + 10, y * 10 + 10 };
105 builder.
Add( min, max,
static_cast<intptr_t
>( y * 10 + x ) );
109 auto tree = builder.
Build();
114 int sMin[2] = { 0, 0 };
115 int sMax[2] = { 19, 19 };
116 std::set<intptr_t> results;
118 auto collect = [&results]( intptr_t val )
120 results.insert( val );
124 tree.Search( sMin, sMax, collect );
127 BOOST_CHECK( results.count( 0 ) );
128 BOOST_CHECK( results.count( 1 ) );
129 BOOST_CHECK( results.count( 10 ) );
130 BOOST_CHECK( results.count( 11 ) );
134 int fullMin[2] = { 0, 0 };
135 int fullMax[2] = { 100, 100 };
136 tree.Search( fullMin, fullMax, collect );
146 for(
int i = 0; i < 50; ++i )
148 int min[2] = { i * 10, i * 10 };
149 int max[2] = { i * 10, i * 10 };
150 builder.
Add( min, max,
static_cast<intptr_t
>( i ) );
153 auto tree = builder.
Build();
158 int sMin[2] = { 100, 100 };
159 int sMax[2] = { 100, 100 };
160 std::vector<intptr_t> results;
162 auto collect = [&results]( intptr_t val )
164 results.push_back( val );
168 tree.Search( sMin, sMax, collect );
238 for(
int i = 0; i < 100; ++i )
240 int min[2] = { i, i };
241 int max[2] = { i + 1, i + 1 };
242 builder.
Add( min, max,
static_cast<intptr_t
>( i ) );
245 auto tree = builder.
Build();
247 std::set<intptr_t> iteratedValues;
249 for(
auto it = tree.begin(); it != tree.end(); ++it )
250 iteratedValues.insert( *it );
254 for(
int i = 0; i < 100; ++i )
255 BOOST_CHECK( iteratedValues.count( i ) );
263 std::mt19937
rng( 12345 );
264 std::uniform_int_distribution<int> coordDist( -1000000, 1000000 );
265 std::uniform_int_distribution<int> sizeDist( 1, 10000 );
274 std::vector<ITEM> items(
N );
278 for(
int i = 0; i <
N; ++i )
280 int x = coordDist(
rng );
281 int y = coordDist(
rng );
282 int w = sizeDist(
rng );
283 int h = sizeDist(
rng );
287 items[i].max[0] = x + w;
288 items[i].max[1] = y + h;
289 items[i].id =
static_cast<intptr_t
>( i );
291 builder.
Add( items[i].min, items[i].max, items[i].
id );
294 auto tree = builder.
Build();
297 for(
int q = 0; q < 100; ++q )
299 int qx = coordDist(
rng );
300 int qy = coordDist(
rng );
301 int qw = sizeDist(
rng ) * 10;
302 int qh = sizeDist(
rng ) * 10;
304 int qMin[2] = { qx, qy };
305 int qMax[2] = { qx + qw, qy + qh };
310 for(
const ITEM& item : items )
312 if( item.min[0] <= qMax[0] && item.max[0] >= qMin[0]
313 && item.min[1] <= qMax[1] && item.max[1] >= qMin[1] )
320 std::set<intptr_t>
actual;
322 auto collect = [&
actual]( intptr_t val )
328 tree.Search( qMin, qMax, collect );
406 for(
int i = 0; i < 100; ++i )
408 int min[3] = { i, i, i };
409 int max[3] = { i + 5, i + 5, i + 5 };
410 builder.
Add( min, max,
static_cast<intptr_t
>( i ) );
413 auto tree = builder.
Build();
418 int sMin[3] = { 10, 10, 10 };
419 int sMax[3] = { 20, 20, 20 };
422 auto counter = [&count]( intptr_t )
428 tree.Search( sMin, sMax, counter );
429 BOOST_CHECK_GT( count, 0 );
BOOST_CHECK_EQUAL(result, "25.4")