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