]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/convert.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / convert.cpp
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 // This file was modified by Oracle on 2021.
9 // Modifications copyright (c) 2021, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19
20 #include <algorithms/test_convert.hpp>
21
22
23
24 template <typename Point1, typename Point2>
25 void test_mixed_point_types()
26 {
27 // Point
28 check<Point1, Point2>("POINT(1 2)");
29
30 // Box
31 check<bg::model::box<Point1>, bg::model::box<Point2>>("POLYGON((1 2,1 4,3 4,3 2,1 2))");
32
33 // Segment
34 check<bg::model::segment<Point1>, bg::model::segment<Point2>>("LINESTRING(1 1,2 2)");
35
36 // Linestring
37 check<bg::model::linestring<Point1>, bg::model::linestring<Point2>>("LINESTRING(1 1,2 2)");
38
39 // Ring
40 check<bg::model::ring<Point1, true, true>, bg::model::ring<Point2, true, true>>(
41 "POLYGON((1 1,2 2,3 0,1 1))", "POLYGON((1 1,2 2,3 0,1 1))", 4);
42 check<bg::model::ring<Point1, true, true>, bg::model::ring<Point2, false, true>>(
43 "POLYGON((1 1,2 2,3 0,1 1))", "POLYGON((1 1,3 0,2 2,1 1))", 4);
44 check<bg::model::ring<Point1, true, true>, bg::model::ring<Point2, true, false>>(
45 "POLYGON((1 1,2 2,3 0,1 1))", "POLYGON((1 1,2 2,3 0))", 3);
46 check<bg::model::ring<Point1, true, true>, bg::model::ring<Point2, false, false>>(
47 "POLYGON((1 1,2 2,3 0,1 1))", "POLYGON((1 1,3 0,2 2))", 3);
48
49 check<bg::model::ring<Point1, false, true>, bg::model::ring<Point2, true, true>>(
50 "POLYGON((1 1,3 0,2 2,1 1))", "POLYGON((1 1,2 2,3 0,1 1))", 4);
51 check<bg::model::ring<Point1, false, true>, bg::model::ring<Point2, false, true>>(
52 "POLYGON((1 1,3 0,2 2,1 1))", "POLYGON((1 1,3 0,2 2,1 1))", 4);
53 check<bg::model::ring<Point1, false, true>, bg::model::ring<Point2, true, false>>(
54 "POLYGON((1 1,3 0,2 2,1 1))", "POLYGON((1 1,2 2,3 0))", 3);
55 check<bg::model::ring<Point1, false, true>, bg::model::ring<Point2, false, false>>(
56 "POLYGON((1 1,3 0,2 2,1 1))", "POLYGON((1 1,3 0,2 2))", 3);
57
58 check<bg::model::ring<Point1, true, false>, bg::model::ring<Point2, true, true>>(
59 "POLYGON((1 1,2 2,3 0))", "POLYGON((1 1,2 2,3 0,1 1))", 4);
60 check<bg::model::ring<Point1, true, false>, bg::model::ring<Point2, false, true>>(
61 "POLYGON((1 1,2 2,3 0))", "POLYGON((1 1,3 0,2 2,1 1))", 4);
62 check<bg::model::ring<Point1, true, false>, bg::model::ring<Point2, true, false>>(
63 "POLYGON((1 1,2 2,3 0))", "POLYGON((1 1,2 2,3 0))", 3);
64 check<bg::model::ring<Point1, true, false>, bg::model::ring<Point2, false, false>>(
65 "POLYGON((1 1,2 2,3 0))", "POLYGON((1 1,3 0,2 2))", 3);
66
67 check<bg::model::ring<Point1, false, false>, bg::model::ring<Point2, true, true>>(
68 "POLYGON((1 1,3 0,2 2))", "POLYGON((1 1,2 2,3 0,1 1))", 4);
69 check<bg::model::ring<Point1, false, false>, bg::model::ring<Point2, false, true>>(
70 "POLYGON((1 1,3 0,2 2))", "POLYGON((1 1,3 0,2 2,1 1))", 4);
71 check<bg::model::ring<Point1, false, false>, bg::model::ring<Point2, true, false>>(
72 "POLYGON((1 1,3 0,2 2))", "POLYGON((1 1,2 2,3 0))", 3);
73 check<bg::model::ring<Point1, false, false>, bg::model::ring<Point2, false, false>>(
74 "POLYGON((1 1,3 0,2 2))", "POLYGON((1 1,3 0,2 2))", 3);
75
76 // Polygon
77 check<bg::model::polygon<Point1, true>, bg::model::polygon<Point2, false>>(
78 "POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,3 2,2 4,1 1))",
79 "POLYGON((0 0,5 0,5 5,0 5,0 0),(1 1,2 4,3 2,1 1))");
80
81 check<bg::model::polygon<Point1>, bg::model::polygon<Point2, false, false>>(
82 "POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,3 2,2 4,1 1))",
83 "POLYGON((0 0,5 0,5 5,0 5,0 0),(1 1,2 4,3 2,1 1))",
84 7); // WKT is closed, polygon is open
85 // (polygon uses ring, so other tests omitted here)
86
87 // Combinations:
88 // ring <-> polygon
89 check<bg::model::polygon<Point1>, bg::model::ring<Point2>>(
90 "POLYGON((1 1,2 2,3 0,1 1))");
91
92 check<bg::model::polygon<Point1, true>, bg::model::ring<Point2, false>>(
93 "POLYGON((1 1,2 2,3 0,1 1))", "POLYGON((1 1,3 0,2 2,1 1))");
94
95 // Any hole will be omitted going from polygon to ring
96 check<bg::model::polygon<Point1>, bg::model::ring<Point2>>(
97 "POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,3 2,2 4,1 1))",
98 "POLYGON((0 0,0 5,5 5,5 0,0 0))",
99 5);
100
101 // point -> box
102 check<Point1, bg::model::box<Point2>>(
103 "POINT(0 0)", "POLYGON((0 0,0 0,0 0,0 0,0 0))", 4);
104
105 // segment -> line
106 check<bg::model::segment<Point1>, bg::model::linestring<Point2>>(
107 "LINESTRING(0 0,1 1)", "LINESTRING(0 0,1 1)", 2);
108
109 // box -> ring ( <- is NYI)
110 check<bg::model::box<Point1>, bg::model::ring<Point2>>(
111 "BOX(0 0,2 2)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", 5);
112
113 check<bg::model::box<Point1>, bg::model::ring<Point2, false>>(
114 "BOX(0 0,2 2)", "POLYGON((0 0,2 0,2 2,0 2,0 0))", 5);
115
116 check<bg::model::box<Point1>, bg::model::ring<Point2, true, false>>(
117 "BOX(0 0,2 2)", "POLYGON((0 0,0 2,2 2,2 0))", 4);
118
119 check<bg::model::box<Point1>, bg::model::ring<Point2, false, false>>(
120 "BOX(0 0,2 2)", "POLYGON((0 0,2 0,2 2,0 2))", 4);
121
122 // box -> polygon ( <- is NYI)
123 check<bg::model::box<Point1>, bg::model::polygon<Point2>>(
124 "BOX(0 0,2 2)", "POLYGON((0 0,0 2,2 2,2 0,0 0))", 5);
125 check<bg::model::box<Point1>, bg::model::polygon<Point2, false>>(
126 "BOX(0 0,2 2)", "POLYGON((0 0,2 0,2 2,0 2,0 0))", 5);
127 check<bg::model::box<Point1>, bg::model::polygon<Point2, true, false>>(
128 "BOX(0 0,2 2)", "POLYGON((0 0,0 2,2 2,2 0,0 0))",
129 4); // WKT is closed, polygon is open
130
131 check<bg::model::box<Point1>, bg::model::polygon<Point2, false, false>>(
132 "BOX(0 0,2 2)", "POLYGON((0 0,2 0,2 2,0 2,0 0))",
133 4); // WKT is closed, polygon is open
134 }
135
136 template <typename Point1, typename Point2>
137 void test_mixed_point_types_3d()
138 {
139 // Point
140 check<Point1, Point2>("POINT(1 2 3)");
141
142 check<bg::model::segment<Point1>, bg::model::segment<Point2>>(
143 "LINESTRING(1 2 3,4 5 6)");
144
145 // Linestring
146 check<bg::model::linestring<Point1>, bg::model::linestring<Point2>>(
147 "LINESTRING(1 2 3,4 5 6,7 8 9)");
148
149 // segment -> line
150 check<bg::model::segment<Point1>, bg::model::linestring<Point2>>(
151 "LINESTRING(1 2 3,4 5 6)", "LINESTRING(1 2 3,4 5 6)", 2);
152 }
153
154
155
156 template <typename Point1, typename Point2>
157 void test_mixed_types()
158 {
159 test_mixed_point_types<Point1, Point2>();
160 test_mixed_point_types<Point2, Point1>();
161 }
162
163
164 template <typename Point1, typename Point2>
165 void test_mixed_types_3d()
166 {
167 test_mixed_point_types_3d<Point1, Point2>();
168 test_mixed_point_types_3d<Point2, Point1>();
169 }
170
171 void test_array()
172 {
173 int a[2] = {1, 2};
174 int b[2];
175 bg::convert(a, b);
176 BOOST_CHECK_EQUAL(b[0], 1);
177 BOOST_CHECK_EQUAL(b[1], 2);
178 }
179
180 int test_main(int, char* [])
181 {
182 test_mixed_types
183 <
184 bg::model::point<int, 2, bg::cs::cartesian>,
185 bg::model::point<double, 2, bg::cs::cartesian>
186 >();
187 test_mixed_types
188 <
189 boost::tuple<float, float>,
190 bg::model::point<float, 2, bg::cs::cartesian>
191 >();
192 test_mixed_types_3d
193 <
194 boost::tuple<double, double, double>,
195 bg::model::point<double, 3, bg::cs::cartesian>
196 >();
197
198 test_array();
199 return 0;
200 }