56 int min[2] = { 10, 20 };
57 int max[2] = { 30, 40 };
58 builder.
Add( min, max, 42 );
60 auto tree = builder.
Build();
62 BOOST_CHECK( !tree.empty() );
66 int sMin[2] = { 0, 0 };
67 int sMax[2] = { 15, 25 };
68 std::vector<intptr_t> results;
70 auto collect = [&results]( intptr_t val )
72 results.push_back( val );
82 int sMin2[2] = { 100, 100 };
83 int sMax2[2] = { 200, 200 };
85 BOOST_CHECK( results.empty() );
95 for(
int y = 0; y < 10; ++y )
97 for(
int x = 0; x < 10; ++x )
99 int min[2] = { x * 10, y * 10 };
100 int max[2] = { x * 10 + 10, y * 10 + 10 };
101 builder.
Add( min, max,
static_cast<intptr_t
>( y * 10 + x ) );
105 auto tree = builder.
Build();
110 int sMin[2] = { 0, 0 };
111 int sMax[2] = { 19, 19 };
112 std::set<intptr_t> results;
114 auto collect = [&results]( intptr_t val )
116 results.insert( val );
120 tree.Search( sMin, sMax, collect );
123 BOOST_CHECK( results.count( 0 ) );
124 BOOST_CHECK( results.count( 1 ) );
125 BOOST_CHECK( results.count( 10 ) );
126 BOOST_CHECK( results.count( 11 ) );
130 int fullMin[2] = { 0, 0 };
131 int fullMax[2] = { 100, 100 };
132 tree.Search( fullMin, fullMax, collect );
142 for(
int i = 0; i < 50; ++i )
144 int min[2] = { i * 10, i * 10 };
145 int max[2] = { i * 10, i * 10 };
146 builder.
Add( min, max,
static_cast<intptr_t
>( i ) );
149 auto tree = builder.
Build();
154 int sMin[2] = { 100, 100 };
155 int sMax[2] = { 100, 100 };
156 std::vector<intptr_t> results;
158 auto collect = [&results]( intptr_t val )
160 results.push_back( val );
164 tree.Search( sMin, sMax, collect );
234 for(
int i = 0; i < 100; ++i )
236 int min[2] = { i, i };
237 int max[2] = { i + 1, i + 1 };
238 builder.
Add( min, max,
static_cast<intptr_t
>( i ) );
241 auto tree = builder.
Build();
243 std::set<intptr_t> iteratedValues;
245 for(
auto it = tree.begin(); it != tree.end(); ++it )
246 iteratedValues.insert( *it );
250 for(
int i = 0; i < 100; ++i )
251 BOOST_CHECK( iteratedValues.count( i ) );
259 std::mt19937
rng( 12345 );
260 std::uniform_int_distribution<int> coordDist( -1000000, 1000000 );
261 std::uniform_int_distribution<int> sizeDist( 1, 10000 );
270 std::vector<ITEM> items(
N );
274 for(
int i = 0; i <
N; ++i )
276 int x = coordDist(
rng );
277 int y = coordDist(
rng );
278 int w = sizeDist(
rng );
279 int h = sizeDist(
rng );
283 items[i].max[0] = x + w;
284 items[i].max[1] = y + h;
285 items[i].id =
static_cast<intptr_t
>( i );
287 builder.
Add( items[i].min, items[i].max, items[i].
id );
290 auto tree = builder.
Build();
293 for(
int q = 0; q < 100; ++q )
295 int qx = coordDist(
rng );
296 int qy = coordDist(
rng );
297 int qw = sizeDist(
rng ) * 10;
298 int qh = sizeDist(
rng ) * 10;
300 int qMin[2] = { qx, qy };
301 int qMax[2] = { qx + qw, qy + qh };
306 for(
const ITEM& item : items )
308 if( item.min[0] <= qMax[0] && item.max[0] >= qMin[0]
309 && item.min[1] <= qMax[1] && item.max[1] >= qMin[1] )
316 std::set<intptr_t>
actual;
318 auto collect = [&
actual]( intptr_t val )
324 tree.Search( qMin, qMax, collect );
402 for(
int i = 0; i < 100; ++i )
404 int min[3] = { i, i, i };
405 int max[3] = { i + 5, i + 5, i + 5 };
406 builder.
Add( min, max,
static_cast<intptr_t
>( i ) );
409 auto tree = builder.
Build();
414 int sMin[3] = { 10, 10, 10 };
415 int sMax[3] = { 20, 20, 20 };
418 auto counter = [&count]( intptr_t )
424 tree.Search( sMin, sMax, counter );
425 BOOST_CHECK_GT( count, 0 );
BOOST_CHECK_EQUAL(result, "25.4")