]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/geometries/initialization.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / geometries / initialization.cpp
1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2014-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 <geometry_test_common.hpp>
11
12 #include <boost/assign.hpp>
13 #include <boost/range.hpp>
14
15 #include <boost/geometry/geometries/geometries.hpp>
16 #include <boost/geometry/geometries/point_xy.hpp>
17 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
18 #include <boost/geometry/geometries/register/point.hpp>
19
20 #include <boost/geometry/algorithms/num_points.hpp>
21 #include <boost/geometry/algorithms/num_geometries.hpp>
22
23 typedef std::pair<float, float> pt_pair_t;
24 BOOST_GEOMETRY_REGISTER_POINT_2D(pt_pair_t, float, bg::cs::cartesian, first, second)
25 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
26
27 template <typename P>
28 void test_default()
29 {
30 typedef bg::model::multi_point<P> mpt;
31 typedef bg::model::linestring<P> ls;
32 typedef bg::model::multi_linestring<ls> mls;
33 typedef bg::model::ring<P> ring;
34 typedef bg::model::polygon<P> poly;
35 typedef bg::model::multi_polygon<poly> mpoly;
36
37 // multi_point()
38 mpt mptd;
39 BOOST_CHECK(bg::num_points(mptd) == 0);
40 // linestring()
41 ls lsd;
42 BOOST_CHECK(bg::num_points(lsd) == 0);
43 // multi_linestring()
44 mls mlsd;
45 BOOST_CHECK(bg::num_points(mlsd) == 0);
46 // ring()
47 ring rd;
48 BOOST_CHECK(bg::num_points(rd) == 0);
49 // polygon()
50 poly pd;
51 BOOST_CHECK(bg::num_points(pd) == 0);
52 // multi_polygon()
53 mpoly mpd;
54 BOOST_CHECK(bg::num_points(mpd) == 0);
55 }
56
57 template <typename P>
58 void test_boost_assign_2d()
59 {
60 typedef bg::model::multi_point<P> mpt;
61 typedef bg::model::linestring<P> ls;
62 typedef bg::model::ring<P> ring;
63
64 // using Boost.Assign
65 mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0));
66 BOOST_CHECK(bg::num_points(mpt2) == 2);
67 mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0));
68 BOOST_CHECK(bg::num_points(mpt2) == 2);
69
70 // using Boost.Assign
71 ls ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1));
72 BOOST_CHECK(bg::num_points(ls2) == 3);
73 ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1));
74 BOOST_CHECK(bg::num_points(ls2) == 3);
75
76 // using Boost.Assign
77 ring r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0));
78 BOOST_CHECK(bg::num_points(r2) == 5);
79 r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0));
80 BOOST_CHECK(bg::num_points(r2) == 5);
81 }
82
83 void test_boost_assign_pair_2d()
84 {
85 typedef std::pair<float, float> pt;
86
87 test_boost_assign_2d<pt>();
88
89 typedef bg::model::multi_point<pt> mpt;
90
91 // using Boost.Assign
92 mpt mpt2 = boost::assign::pair_list_of(0, 0)(1, 0);
93 BOOST_CHECK(bg::num_points(mpt2) == 2);
94 mpt2 = boost::assign::pair_list_of(0, 0)(1, 0);
95 BOOST_CHECK(bg::num_points(mpt2) == 2);
96 }
97
98 void test_boost_assign_tuple_2d()
99 {
100 typedef boost::tuple<float, float> pt;
101
102 test_boost_assign_2d<pt>();
103
104 typedef bg::model::multi_point<pt> mpt;
105
106 // using Boost.Assign
107 mpt mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0);
108 BOOST_CHECK(bg::num_points(mpt2) == 2);
109 mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0);
110 BOOST_CHECK(bg::num_points(mpt2) == 2);
111 }
112
113 template <typename P>
114 void test_initializer_list_2d()
115 {
116 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
117
118 typedef bg::model::multi_point<P> mpt;
119 typedef bg::model::linestring<P> ls;
120 typedef bg::model::multi_linestring<ls> mls;
121 typedef bg::model::ring<P> ring;
122 typedef bg::model::polygon<P> poly;
123 typedef bg::model::multi_polygon<poly> mpoly;
124
125 // multi_point(initializer_list<Point>)
126 mpt mpt1 = {{0, 0}, {1, 0}, {2, 0}};
127 BOOST_CHECK(bg::num_geometries(mpt1) == 3);
128 BOOST_CHECK(bg::num_points(mpt1) == 3);
129 // multi_point::operator=(initializer_list<Point>)
130 mpt1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
131 BOOST_CHECK(bg::num_points(mpt1) == 4);
132
133 // linestring(initializer_list<Point>)
134 ls ls1 = {{0, 0}, {1, 0}, {2, 0}};
135 BOOST_CHECK(bg::num_geometries(ls1) == 1);
136 BOOST_CHECK(bg::num_points(ls1) == 3);
137 // linestring::operator=(initializer_list<Point>)
138 ls1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
139 BOOST_CHECK(bg::num_points(ls1) == 4);
140
141 // multi_linestring(initializer_list<Linestring>)
142 mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}};
143 BOOST_CHECK(bg::num_geometries(mls1) == 2);
144 BOOST_CHECK(bg::num_points(mls1) == 5);
145 // multi_linestring::operator=(initializer_list<Linestring>)
146 mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}, {5, 0}}};
147 BOOST_CHECK(bg::num_points(mls1) == 6);
148
149 // ring(initializer_list<Point>)
150 ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
151 BOOST_CHECK(bg::num_geometries(r1) == 1);
152 BOOST_CHECK(bg::num_points(r1) == 5);
153 // ring::operator=(initializer_list<Point>)
154 r1 = {{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}};
155 BOOST_CHECK(bg::num_points(r1) == 6);
156
157 // polygon(initializer_list<ring_type>)
158 poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}};
159 BOOST_CHECK(bg::num_geometries(p1) == 1);
160 BOOST_CHECK(bg::num_points(p1) == 10);
161 BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1);
162 // polygon::operator=(initializer_list<ring_type>)
163 p1 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}};
164 BOOST_CHECK(bg::num_points(p1) == 11);
165 BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1);
166 p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}};
167 BOOST_CHECK(bg::num_points(p1) == 5);
168 BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0);
169 // polygon(initializer_list<ring_type>)
170 poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}};
171 BOOST_CHECK(bg::num_geometries(p2) == 1);
172 BOOST_CHECK(bg::num_points(p2) == 5);
173 BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0);
174 // polygon::operator=(initializer_list<ring_type>)
175 p2 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}};
176 BOOST_CHECK(bg::num_points(p2) == 6);
177
178 // multi_polygon(initializer_list<Polygon>)
179 mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}};
180 BOOST_CHECK(bg::num_geometries(mp1) == 2);
181 BOOST_CHECK(bg::num_points(mp1) == 10);
182 // multi_polygon::operator=(initializer_list<Polygon>)
183 mp1 = {{{{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}};
184 BOOST_CHECK(bg::num_points(mp1) == 11);
185
186 #endif
187 }
188
189 template <typename P>
190 void test_all_2d()
191 {
192 test_default<P>();
193 test_boost_assign_2d<P>();
194 test_initializer_list_2d<P>();
195 }
196
197 template <typename T>
198 struct test_point
199 {
200 test_point(T = T(), T = T()) {}
201 };
202
203 template <typename T>
204 struct test_range
205 {
206 test_range() {}
207 template <typename It>
208 test_range(It, It) {}
209 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
210 test_range(std::initializer_list<T>) {}
211 //test_range & operator=(std::initializer_list<T>) { return *this; }
212 #endif
213 };
214
215 void test_sanity_check()
216 {
217 typedef test_point<float> P;
218 typedef test_range<P> R;
219 typedef std::vector<P> V;
220
221 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
222 {
223 R r = {{1, 1},{2, 2},{3, 3}};
224 r = {{1, 1},{2, 2},{3, 3}};
225
226 V v = {{1, 1},{2, 2},{3, 3}};
227 v = {{1, 1},{2, 2},{3, 3}};
228 }
229 #endif
230 {
231 R r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
232 r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
233
234 V v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
235 //v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
236 v.empty();
237 }
238 }
239
240 int test_main(int, char* [])
241 {
242 test_all_2d< bg::model::point<float, 2, bg::cs::cartesian> >();
243 test_all_2d< bg::model::d2::point_xy<float> >();
244
245 test_boost_assign_pair_2d();
246 test_boost_assign_tuple_2d();
247
248 test_sanity_check();
249
250 return 0;
251 }
252