1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 
15 
16 #include <algorithms/test_convert.hpp>
17 
18 
19 
20 template <typename Point1, typename Point2>
test_mixed_point_types()21 void test_mixed_point_types()
22 {
23     // Point
24     test_mixed_identical_result<Point1, Point2>("POINT(1 2)");
25 
26     // Box
27     test_mixed_identical_result
28         <
29             bg::model::box<Point1>,
30             bg::model::box<Point2>
31         >
32         ("POLYGON((1 2,1 4,3 4,3 2,1 2))");
33 
34     test_mixed_identical_result
35         <
36             bg::model::segment<Point1>,
37             bg::model::segment<Point2>
38         >
39         ("LINESTRING(1 1,2 2)");
40 
41     // Linestring
42     test_mixed_identical_result
43         <
44             bg::model::linestring<Point1>,
45             bg::model::linestring<Point2>
46         >
47         ("LINESTRING(1 1,2 2)");
48 
49     // Ring
50     test_mixed_identical_result
51         <
52             bg::model::ring<Point1>,
53             bg::model::ring<Point2>
54         >
55         ("POLYGON((1 1,2 2,3 0,1 1))");
56 
57     test_mixed_reversible_result
58         <
59             bg::model::ring<Point1, true>,
60             bg::model::ring<Point2, false>
61         >
62         (
63             "POLYGON((1 1,2 2,3 0,1 1))",
64             "POLYGON((1 1,3 0,2 2,1 1))"
65         );
66 
67     test_mixed
68         <
69             bg::model::ring<Point1, true, true>,
70             bg::model::ring<Point2, true, false>
71         >
72         (
73             "POLYGON((1 1,2 2,3 0,1 1))",
74             "POLYGON((1 1,2 2,3 0))",
75             3
76         );
77 
78     test_mixed
79         <
80             bg::model::ring<Point1, true, false>,
81             bg::model::ring<Point2, true, true>
82         >
83         (
84             "POLYGON((1 1,2 2,3 0))",
85             "POLYGON((1 1,2 2,3 0,1 1))",
86             4
87         );
88 
89     // Polygon
90     test_mixed_reversible_result
91         <
92             bg::model::polygon<Point1, true>,
93             bg::model::polygon<Point2, false>
94         >
95         (
96             "POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,3 2,2 4,1 1))",
97             "POLYGON((0 0,5 0,5 5,0 5,0 0),(1 1,2 4,3 2,1 1))"
98         );
99 
100     test_mixed
101         <
102             bg::model::polygon<Point1>,
103             bg::model::polygon<Point2, false, false>
104         >
105         (
106             "POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,3 2,2 4,1 1))",
107             "POLYGON((0 0,5 0,5 5,0 5,0 0),(1 1,2 4,3 2,1 1))",
108             7 // WKT is closed, polygon is open
109         );
110     // (polygon uses ring, so other tests omitted here)
111 
112     // Combinations:
113     // ring <-> polygon
114     test_mixed_identical_result
115         <
116             bg::model::polygon<Point1>,
117             bg::model::ring<Point2>
118         >
119         ("POLYGON((1 1,2 2,3 0,1 1))");
120 
121     test_mixed_reversible_result
122         <
123             bg::model::polygon<Point1, true>,
124             bg::model::ring<Point2, false>
125         >
126         (
127             "POLYGON((1 1,2 2,3 0,1 1))",
128             "POLYGON((1 1,3 0,2 2,1 1))"
129         );
130 
131     // Any hole will be omitted going from polygon to ring
132     test_mixed
133         <
134             bg::model::polygon<Point1>,
135             bg::model::ring<Point2>
136         >
137         (
138             "POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,3 2,2 4,1 1))",
139             "POLYGON((0 0,0 5,5 5,5 0,0 0))",
140             5
141         );
142 
143     // point -> box
144     test_mixed
145         <
146             Point1,
147             bg::model::box<Point2>
148         >
149         (
150             "POINT(0 0)",
151             "POLYGON((0 0,0 0,0 0,0 0,0 0))",
152             4
153         );
154 
155     // segment -> line
156     test_mixed
157         <
158             bg::model::segment<Point1>,
159             bg::model::linestring<Point2>
160         >
161         (
162             "LINESTRING(0 0,1 1)",
163             "LINESTRING(0 0,1 1)",
164             2
165         );
166 
167     // box -> ring ( <- is NYI)
168     test_mixed
169         <
170             bg::model::box<Point1>,
171             bg::model::ring<Point2>
172         >
173         (
174             "BOX(0 0,2 2)",
175             "POLYGON((0 0,0 2,2 2,2 0,0 0))",
176             5
177         );
178 
179     test_mixed
180         <
181             bg::model::box<Point1>,
182             bg::model::ring<Point2, false>
183         >
184         (
185             "BOX(0 0,2 2)",
186             "POLYGON((0 0,2 0,2 2,0 2,0 0))",
187             5
188         );
189 
190     test_mixed
191         <
192             bg::model::box<Point1>,
193             bg::model::ring<Point2, true, false>
194         >
195         (
196             "BOX(0 0,2 2)",
197             "POLYGON((0 0,0 2,2 2,2 0))",
198             4
199         );
200 
201     test_mixed
202         <
203             bg::model::box<Point1>,
204             bg::model::ring<Point2, false, false>
205         >
206         (
207             "BOX(0 0,2 2)",
208             "POLYGON((0 0,2 0,2 2,0 2))",
209             4
210         );
211 
212     // box -> polygon ( <- is NYI)
213     test_mixed
214         <
215             bg::model::box<Point1>,
216             bg::model::polygon<Point2>
217         >
218         (
219             "BOX(0 0,2 2)",
220             "POLYGON((0 0,0 2,2 2,2 0,0 0))",
221             5
222         );
223 
224     test_mixed
225         <
226             bg::model::box<Point1>,
227             bg::model::polygon<Point2, false>
228         >
229         (
230             "BOX(0 0,2 2)",
231             "POLYGON((0 0,2 0,2 2,0 2,0 0))",
232             5
233         );
234 
235     test_mixed
236         <
237             bg::model::box<Point1>,
238             bg::model::polygon<Point2, true, false>
239         >
240         (
241             "BOX(0 0,2 2)",
242             "POLYGON((0 0,0 2,2 2,2 0,0 0))",
243             4 // WKT is closed, polygon is open
244         );
245 
246     test_mixed
247         <
248             bg::model::box<Point1>,
249             bg::model::polygon<Point2, false, false>
250         >
251         (
252             "BOX(0 0,2 2)",
253             "POLYGON((0 0,2 0,2 2,0 2,0 0))",
254             4 // WKT is closed, polygon is open
255         );
256 }
257 
258 template <typename Point1, typename Point2>
test_mixed_point_types_3d()259 void test_mixed_point_types_3d()
260 {
261     // Point
262     test_mixed_identical_result<Point1, Point2>("POINT(1 2 3)");
263 
264     test_mixed_identical_result
265         <
266             bg::model::segment<Point1>,
267             bg::model::segment<Point2>
268         >
269         ("LINESTRING(1 2 3,4 5 6)");
270 
271     // Linestring
272     test_mixed_identical_result
273         <
274             bg::model::linestring<Point1>,
275             bg::model::linestring<Point2>
276         >
277         ("LINESTRING(1 2 3,4 5 6,7 8 9)");
278 
279     // segment -> line
280     test_mixed
281         <
282             bg::model::segment<Point1>,
283             bg::model::linestring<Point2>
284         >
285         (
286             "LINESTRING(1 2 3,4 5 6)",
287             "LINESTRING(1 2 3,4 5 6)",
288             2
289         );
290 }
291 
292 
293 
294 template <typename Point1, typename Point2>
test_mixed_types()295 void test_mixed_types()
296 {
297     test_mixed_point_types<Point1, Point2>();
298     test_mixed_point_types<Point2, Point1>();
299 }
300 
301 
302 template <typename Point1, typename Point2>
test_mixed_types_3d()303 void test_mixed_types_3d()
304 {
305     test_mixed_point_types_3d<Point1, Point2>();
306     test_mixed_point_types_3d<Point2, Point1>();
307 }
308 
test_array()309 void test_array()
310 {
311     int a[2] = {1, 2};
312     int b[2];
313     bg::convert(a, b);
314     BOOST_CHECK_EQUAL(b[0], 1);
315     BOOST_CHECK_EQUAL(b[1], 2);
316 }
317 
test_main(int,char * [])318 int test_main(int, char* [])
319 {
320     test_mixed_types
321         <
322             bg::model::point<int, 2, bg::cs::cartesian>,
323             bg::model::point<double, 2, bg::cs::cartesian>
324         >();
325     test_mixed_types
326         <
327             boost::tuple<float, float>,
328             bg::model::point<float, 2, bg::cs::cartesian>
329         >();
330     test_mixed_types_3d
331         <
332             boost::tuple<double, double, double>,
333             bg::model::point<double, 3, bg::cs::cartesian>
334         >();
335 
336     test_array();
337     return 0;
338 }
339