• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry Index
2 // Unit Test
3 
4 // Copyright (c) 2016 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/geometries.hpp>
13 #include <boost/geometry/io/wkt/read.hpp>
14 
15 template <typename Point>
fill(Point & pt,double x,double y)16 inline void fill(Point & pt, double x, double y)
17 {
18     bg::set<0>(pt, x);
19     bg::set<1>(pt, y);
20 }
21 
22 template <typename Point>
fill(bg::model::box<Point> & box,double x,double y)23 inline void fill(bg::model::box<Point> & box, double x, double y)
24 {
25     bg::set<0, 0>(box, x);
26     bg::set<0, 1>(box, y);
27     bg::set<1, 0>(box, x + 20);
28     bg::set<1, 1>(box, y + 20);
29 }
30 
31 template <typename Rtree>
test_rtree()32 void test_rtree()
33 {
34     typedef typename Rtree::value_type value_t;
35 
36     Rtree rtree;
37     value_t v;
38 
39     // This is not fully valid because both point's longitude and box's min
40     // longitude should be in range [-180, 180]. So if this stopped passing
41     // in the future it wouldn't be that bad. Still it works as it is now.
42 
43     size_t n = 0;
44     for (double x = -170; x < 400; x += 30, ++n)
45     {
46         //double lon = x <= 180 ? x : x - 360;
47         double lon = x;
48         double lat = x <= 180 ? 0 : 30;
49 
50         fill(v, lon, lat);
51         rtree.insert(v);
52         BOOST_CHECK_EQUAL(rtree.size(), n + 1);
53         size_t vcount = 1; // x < 180 ? 1 : 2;
54         BOOST_CHECK_EQUAL(rtree.count(v), vcount);
55         std::vector<value_t> res;
56         rtree.query(bgi::intersects(v), std::back_inserter(res));
57         BOOST_CHECK_EQUAL(res.size(), vcount);
58     }
59 
60     for (double x = -170; x < 400; x += 30, --n)
61     {
62         //double lon = x <= 180 ? x : x - 360;
63         double lon = x;
64         double lat = x <= 180 ? 0 : 30;
65 
66         fill(v, lon, lat);
67         rtree.remove(v);
68         BOOST_CHECK_EQUAL(rtree.size(), n - 1);
69         size_t vcount = 0; // x < 180 ? 1 : 0;
70         BOOST_CHECK_EQUAL(rtree.count(v), vcount);
71         std::vector<value_t> res;
72         rtree.query(bgi::intersects(v), std::back_inserter(res));
73         BOOST_CHECK_EQUAL(res.size(), vcount);
74     }
75 }
76 
77 template <typename Value>
test_value()78 void test_value()
79 {
80     test_rtree<bgi::rtree<Value, bgi::linear<4> > >();
81     test_rtree<bgi::rtree<Value, bgi::quadratic<4> > >();
82     test_rtree<bgi::rtree<Value, bgi::rstar<4> > >();
83 }
84 
85 template <typename Rtree>
test_ticket_12413()86 void test_ticket_12413()
87 {
88     typedef typename Rtree::value_type pair_t;
89     typedef typename pair_t::first_type point_t;
90 
91     Rtree rtree;
92     rtree.insert(std::make_pair(point_t(-1.558444, 52.38664), 792));
93     rtree.insert(std::make_pair(point_t(-1.558444, 52.38664), 793));
94     rtree.insert(std::make_pair(point_t(-2.088824, 51.907406), 800));
95     rtree.insert(std::make_pair(point_t(-1.576363, 53.784089), 799));
96     rtree.insert(std::make_pair(point_t(-77.038816, 38.897282), 801));
97     rtree.insert(std::make_pair(point_t(-1.558444, 52.38664), 794));
98     rtree.insert(std::make_pair(point_t(-0.141588, 51.501009), 797));
99     rtree.insert(std::make_pair(point_t(-118.410468, 34.103003), 798));
100     rtree.insert(std::make_pair(point_t(-0.127592, 51.503407), 796));
101 
102     size_t num_removed = rtree.remove(std::make_pair(point_t(-0.127592, 51.503407), 796));
103 
104     BOOST_CHECK_EQUAL(num_removed, 1);
105 }
106 
107 template <typename Point>
test_cs()108 void test_cs()
109 {
110     test_value<Point>();
111     test_value<bg::model::box<Point> >();
112 
113     {
114         typedef std::pair<Point, unsigned> value_t;
115         test_ticket_12413<bgi::rtree<value_t, bgi::linear<4> > >();
116         test_ticket_12413<bgi::rtree<value_t, bgi::quadratic<4> > >();
117         test_ticket_12413<bgi::rtree<value_t, bgi::rstar<4> > >();
118     }
119 }
120 
test_main(int,char * [])121 int test_main(int, char* [])
122 {
123     //test_cs<bg::model::point<double, 2, bg::cs::cartesian> >();
124     test_cs<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
125     test_cs<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
126 
127     return 0;
128 }
129