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 #include <rtree/test_rtree.hpp>
11 
12 #include <boost/geometry/geometries/register/point.hpp>
13 #include <boost/geometry/geometries/polygon.hpp>
14 
15 template <typename Params>
test_rtree(unsigned vcount)16 void test_rtree(unsigned vcount)
17 {
18     typedef bg::model::point<int, 1, bg::cs::cartesian> point_t;
19 
20     bgi::rtree<point_t, Params> rt;
21 
22     BOOST_CHECK(rt.remove(point_t(0)) == 0);
23 
24     for ( unsigned i = 0 ; i < vcount ; ++i )
25     {
26         rt.insert(point_t(static_cast<int>(i)));
27     }
28 
29     BOOST_CHECK(rt.size() == vcount);
30     BOOST_CHECK(rt.count(point_t(vcount / 2)) == 1);
31 
32     for ( unsigned i = 0 ; i < vcount + 3 ; ++i )
33     {
34         rt.remove(point_t((i + 3) % vcount));
35     }
36 
37     BOOST_CHECK(rt.size() == 0);
38     BOOST_CHECK(rt.count(point_t(vcount / 2)) == 0);
39 
40     for ( unsigned i = 0 ; i < vcount ; ++i )
41     {
42         rt.insert(point_t((i + 5) % vcount));
43     }
44 
45     BOOST_CHECK(rt.size() == vcount);
46     BOOST_CHECK(rt.count(point_t(vcount / 2)) == 1);
47 
48     for ( unsigned i = 0 ; i < vcount + 3 ; ++i )
49     {
50         rt.remove(point_t((i + 7) % vcount));
51     }
52 
53     BOOST_CHECK(rt.size() == 0);
54     BOOST_CHECK(rt.count(point_t(vcount / 2)) == 0);
55 }
56 
57 template <int Max, int Min>
test_rtree_all()58 void test_rtree_all()
59 {
60     int pow = Max;
61     for (int l = 0 ; l < 3 ; ++l)
62     {
63         pow *= Max;
64         int vcount = (pow * 8) / 10;
65 
66         //std::cout << Max << " " << Min << " " << vcount << std::endl;
67 
68         test_rtree< bgi::linear<Max, Min> >(vcount);
69         test_rtree< bgi::quadratic<Max, Min> >(vcount);
70         test_rtree< bgi::rstar<Max, Min> >(vcount);
71     }
72 }
73 
test_main(int,char * [])74 int test_main(int, char* [])
75 {
76     test_rtree_all<2, 1>();
77     test_rtree_all<4, 1>();
78     test_rtree_all<4, 2>();
79     test_rtree_all<5, 3>();
80 
81     return 0;
82 }
83