| 1 | #define BOOST_TEST_DYN_LINK
|
|---|
| 2 | #define BOOST_TEST_MODULE test_rtree_insert
|
|---|
| 3 |
|
|---|
| 4 | #include <random>
|
|---|
| 5 | #include <vector>
|
|---|
| 6 | #include <boost/geometry.hpp>
|
|---|
| 7 | #include <boost/test/unit_test.hpp>
|
|---|
| 8 |
|
|---|
| 9 | #include <boost/geometry/index/rtree.hpp>
|
|---|
| 10 |
|
|---|
| 11 | BOOST_AUTO_TEST_CASE(test_rtree_insert) {
|
|---|
| 12 | namespace bg = boost::geometry;
|
|---|
| 13 | namespace bgi = bg::index;
|
|---|
| 14 | typedef bg::model::point<int, 2, bg::cs::cartesian> point_t;
|
|---|
| 15 | typedef bgi::rtree<point_t, bgi::linear<32> > rtree_t;
|
|---|
| 16 | int width = 500;
|
|---|
| 17 | int height = 500;
|
|---|
| 18 | int n_points = 2000;
|
|---|
| 19 |
|
|---|
| 20 | rtree_t rtree;
|
|---|
| 21 |
|
|---|
| 22 | auto rx = std::bind(std::uniform_int_distribution<>{0, width}, std::default_random_engine{23});
|
|---|
| 23 | auto ry = std::bind(std::uniform_int_distribution<>{0, height}, std::default_random_engine{1223});
|
|---|
| 24 |
|
|---|
| 25 | int count_contains_failures = 0;
|
|---|
| 26 | for(int i = 0; i < n_points; i++) {
|
|---|
| 27 | point_t p(rx(), ry());
|
|---|
| 28 |
|
|---|
| 29 | rtree.insert(p);
|
|---|
| 30 | std::vector<point_t> result;
|
|---|
| 31 | auto t = rtree.query(bgi::contains(p), std::back_inserter(result));
|
|---|
| 32 |
|
|---|
| 33 | if(t != 1) {
|
|---|
| 34 | std::cout << "failed contains for point " << p.get<0>() << ", " << p.get<1>() << std::endl;
|
|---|
| 35 | count_contains_failures++;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | std::cout << "failed contains " << count_contains_failures << std::endl;
|
|---|
| 41 | BOOST_CHECK_EQUAL(count_contains_failures, 0);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|