• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry Index
2 // Unit Test
3 
4 // Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland.
5 
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Enable enlargement of Values' bounds by epsilon in the rtree
11 // for Points and Segments
12 #define BOOST_GEOMETRY_INDEX_EXPERIMENTAL_ENLARGE_BY_EPSILON
13 
14 #include <vector>
15 
16 #include <rtree/test_rtree.hpp>
17 
18 #include <boost/geometry/geometries/register/point.hpp>
19 #include <boost/geometry/geometries/polygon.hpp>
20 
21 template <typename Params>
test_rtree(unsigned vcount)22 void test_rtree(unsigned vcount)
23 {
24     typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
25 
26     std::vector<point_t> values;
27 
28     double eps = std::numeric_limits<double>::epsilon();
29     values.push_back(point_t(eps/2, eps/2));
30 
31     for ( unsigned i = 1 ; i < vcount ; ++i )
32     {
33         values.push_back(point_t(i, i));
34     }
35 
36     point_t qpt(0, 0);
37 
38     BOOST_CHECK(bg::intersects(qpt, values[0]));
39 
40     {
41         bgi::rtree<point_t, Params> rt(values);
42 
43         std::vector<point_t> result;
44         rt.query(bgi::intersects(qpt), std::back_inserter(result));
45         BOOST_CHECK(result.size() == 1);
46 
47         rt.remove(values.begin() + vcount/2, values.end());
48 
49         result.clear();
50         rt.query(bgi::intersects(qpt), std::back_inserter(result));
51         BOOST_CHECK(result.size() == 1);
52     }
53 
54     {
55         bgi::rtree<point_t, Params> rt;
56         rt.insert(values);
57 
58         std::vector<point_t> result;
59         rt.query(bgi::intersects(qpt), std::back_inserter(result));
60         BOOST_CHECK(result.size() == 1);
61 
62         rt.remove(values.begin() + vcount/2, values.end());
63 
64         result.clear();
65         rt.query(bgi::intersects(qpt), std::back_inserter(result));
66         BOOST_CHECK(result.size() == 1);
67     }
68 }
69 
70 template <int Max, int Min>
test_rtree_all()71 void test_rtree_all()
72 {
73     int pow = Max;
74     for (int l = 0 ; l < 3 ; ++l)
75     {
76         pow *= Max;
77         int vcount = (pow * 8) / 10;
78 
79         //std::cout << Max << " " << Min << " " << vcount << std::endl;
80 
81         test_rtree< bgi::linear<Max, Min> >(vcount);
82         test_rtree< bgi::quadratic<Max, Min> >(vcount);
83         test_rtree< bgi::rstar<Max, Min> >(vcount);
84     }
85 }
86 
test_main(int,char * [])87 int test_main(int, char* [])
88 {
89     test_rtree_all<2, 1>();
90     test_rtree_all<4, 1>();
91     test_rtree_all<4, 2>();
92     test_rtree_all<5, 3>();
93 
94     return 0;
95 }
96