]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/geometries/initialization.cpp
4 // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
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)
10 #include <geometry_test_common.hpp>
12 #include <boost/assign.hpp>
13 #include <boost/range.hpp>
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>
20 #include <boost/geometry/algorithms/num_points.hpp>
21 #include <boost/geometry/algorithms/num_geometries.hpp>
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
)
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
;
39 BOOST_CHECK(bg::num_points(mptd
) == 0);
42 BOOST_CHECK(bg::num_points(lsd
) == 0);
45 BOOST_CHECK(bg::num_points(mlsd
) == 0);
48 BOOST_CHECK(bg::num_points(rd
) == 0);
51 BOOST_CHECK(bg::num_points(pd
) == 0);
54 BOOST_CHECK(bg::num_points(mpd
) == 0);
58 void test_boost_assign_2d()
60 typedef bg::model::multi_point
<P
> mpt
;
61 typedef bg::model::linestring
<P
> ls
;
62 typedef bg::model::ring
<P
> ring
;
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);
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);
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);
83 void test_boost_assign_pair_2d()
85 typedef std::pair
<float, float> pt
;
87 test_boost_assign_2d
<pt
>();
89 typedef bg::model::multi_point
<pt
> mpt
;
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);
98 void test_boost_assign_tuple_2d()
100 typedef boost::tuple
<float, float> pt
;
102 test_boost_assign_2d
<pt
>();
104 typedef bg::model::multi_point
<pt
> mpt
;
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);
113 template <typename P
>
114 void test_initializer_list_2d()
116 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
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
;
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);
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);
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);
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);
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);
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);
189 template <typename P
>
193 test_boost_assign_2d
<P
>();
194 test_initializer_list_2d
<P
>();
197 template <typename T
>
200 test_point(T
= T(), T
= T()) {}
203 template <typename T
>
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; }
215 void test_sanity_check()
217 typedef test_point
<float> P
;
218 typedef test_range
<P
> R
;
219 typedef std::vector
<P
> V
;
221 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
223 R r
= {{1, 1},{2, 2},{3, 3}};
224 r
= {{1, 1},{2, 2},{3, 3}};
226 V v
= {{1, 1},{2, 2},{3, 3}};
227 v
= {{1, 1},{2, 2},{3, 3}};
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));
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));
240 int test_main(int, char* [])
242 test_all_2d
< bg::model::point
<float, 2, bg::cs::cartesian
> >();
243 test_all_2d
< bg::model::d2::point_xy
<float> >();
245 test_boost_assign_pair_2d();
246 test_boost_assign_tuple_2d();