1 // Boost.Geometry
2 // Unit Test
3
4 // Copyright (c) 2016-2018, Oracle and/or its affiliates.
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11
12 #define BOOST_GEOMETRY_TEST_GEO_INTERSECTION_TEST_SIMILAR
13 #include "segment_intersection_sph.hpp"
14
15
16 #include <boost/geometry/strategies/spherical/intersection.hpp>
17
18
19 template <typename S, typename P>
test_spherical_strategy(std::string const & s1_wkt,std::string const & s2_wkt,char m,std::size_t expected_count,std::string const & ip0_wkt="",std::string const & ip1_wkt="")20 void test_spherical_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
21 char m, std::size_t expected_count,
22 std::string const& ip0_wkt = "", std::string const& ip1_wkt = "")
23 {
24 bg::strategy::intersection::spherical_segments<> strategy;
25
26 test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt);
27 }
28
29 template <typename T>
test_spherical()30 void test_spherical()
31 {
32 typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > point_t;
33 typedef bg::model::segment<point_t> segment_t;
34
35 // crossing X
36 test_spherical_strategy<segment_t, point_t>(
37 "SEGMENT(-45 -45, 45 45)", "SEGMENT(-45 45, 45 -45)", 'i', 1, "POINT(0 0)");
38 test_spherical_strategy<segment_t, point_t>(
39 "SEGMENT(-45 -45, 45 45)", "SEGMENT(45 -45, -45 45)", 'i', 1, "POINT(0 0)");
40 test_spherical_strategy<segment_t, point_t>(
41 "SEGMENT(45 45, -45 -45)", "SEGMENT(-45 45, 45 -45)", 'i', 1, "POINT(0 0)");
42 test_spherical_strategy<segment_t, point_t>(
43 "SEGMENT(45 45, -45 -45)", "SEGMENT(45 -45, -45 45)", 'i', 1, "POINT(0 0)");
44 // crossing X
45 test_spherical_strategy<segment_t, point_t>(
46 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-1 1, 1 -1)", 'i', 1, "POINT(0 0)");
47 test_spherical_strategy<segment_t, point_t>(
48 "SEGMENT(-1 -1, 1 1)", "SEGMENT(1 -1, -1 1)", 'i', 1, "POINT(0 0)");
49 test_spherical_strategy<segment_t, point_t>(
50 "SEGMENT(1 1, -1 -1)", "SEGMENT(-1 1, 1 -1)", 'i', 1, "POINT(0 0)");
51 test_spherical_strategy<segment_t, point_t>(
52 "SEGMENT(1 1, -1 -1)", "SEGMENT(1 -1, -1 1)", 'i', 1, "POINT(0 0)");
53
54 // equal
55 // //
56 test_spherical_strategy<segment_t, point_t>(
57 "SEGMENT(-45 -45, 45 45)", "SEGMENT(-45 -45, 45 45)", 'e', 2, "POINT(-45 -45)", "POINT(45 45)");
58 // //
59 test_spherical_strategy<segment_t, point_t>(
60 "SEGMENT(-45 -45, 45 45)", "SEGMENT(45 45, -45 -45)", 'e', 2, "POINT(-45 -45)", "POINT(45 45)");
61
62 // starting outside s1
63 // /
64 // |
65 test_spherical_strategy<segment_t, point_t>(
66 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-2 -2, -1 -1)", 'a', 1, "POINT(-1 -1)");
67 // /
68 // /|
69 test_spherical_strategy<segment_t, point_t>(
70 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-2 -2, 0 0)", 'm', 1, "POINT(0 0)");
71 // /|
72 // / |
73 test_spherical_strategy<segment_t, point_t>(
74 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-2 -2, 1 1)", 't', 1, "POINT(1 1)");
75 // |/
76 // /|
77 test_spherical_strategy<segment_t, point_t>(
78 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-2 -2, 2 2)", 'i', 1, "POINT(0 0)");
79 // ------
80 // ------
81 test_spherical_strategy<segment_t, point_t>(
82 "SEGMENT(-1 0, 1 0)", "SEGMENT(-2 0, -1 0)", 'a', 1, "POINT(-1 0)");
83 // ------
84 // ------
85 test_spherical_strategy<segment_t, point_t>(
86 "SEGMENT(-1 0, 1 0)", "SEGMENT(-2 0, 0 0)", 'c', 2, "POINT(-1 0)", "POINT(0 0)");
87 // ------
88 // ---------
89 test_spherical_strategy<segment_t, point_t>(
90 "SEGMENT(-1 0, 1 0)", "SEGMENT(-2 0, 1 0)", 'c', 2, "POINT(-1 0)", "POINT(1 0)");
91 // ------
92 // ------------
93 test_spherical_strategy<segment_t, point_t>(
94 "SEGMENT(-1 0, 1 0)", "SEGMENT(-2 0, 2 0)", 'c', 2, "POINT(-1 0)", "POINT(1 0)");
95
96 // starting at s1
97 // /
98 // //
99 test_spherical_strategy<segment_t, point_t>(
100 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-1 -1, 0 0)", 'c', 2, "POINT(-1 -1)", "POINT(0 0)");
101 // //
102 // //
103 test_spherical_strategy<segment_t, point_t>(
104 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-1 -1, 1 1)", 'e', 2, "POINT(-1 -1)", "POINT(1 1)");
105 // | /
106 // |/
107 test_spherical_strategy<segment_t, point_t>(
108 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-1 -1, 2 2)", 'f', 1, "POINT(-1 -1)");
109 // ------
110 // ---
111 test_spherical_strategy<segment_t, point_t>(
112 "SEGMENT(-1 0, 1 0)", "SEGMENT(-1 0, 0 0)", 'c', 2, "POINT(-1 0)", "POINT(0 0)");
113 // ------
114 // ------
115 test_spherical_strategy<segment_t, point_t>(
116 "SEGMENT(-1 0, 1 0)", "SEGMENT(-1 0, 1 0)", 'e', 2, "POINT(-1 0)", "POINT(1 0)");
117 // ------
118 // ---------
119 test_spherical_strategy<segment_t, point_t>(
120 "SEGMENT(-1 0, 1 0)", "SEGMENT(-1 0, 2 0)", 'c', 2, "POINT(-1 0)", "POINT(1 0)");
121
122 // starting inside
123 // //
124 // /
125 test_spherical_strategy<segment_t, point_t>(
126 "SEGMENT(-1 -1, 1 1)", "SEGMENT(0 0, 1 1)", 'c', 2, "POINT(0 0)", "POINT(1 1)");
127 // |/
128 // /
129 test_spherical_strategy<segment_t, point_t>(
130 "SEGMENT(-1 -1, 1 1)", "SEGMENT(0 0, 2 2)", 's', 1, "POINT(0 0)");
131 // ------
132 // ---
133 test_spherical_strategy<segment_t, point_t>(
134 "SEGMENT(-1 0, 1 0)", "SEGMENT(0 0, 1 0)", 'c', 2, "POINT(0 0)", "POINT(1 0)");
135 // ------
136 // ------
137 test_spherical_strategy<segment_t, point_t>(
138 "SEGMENT(-1 0, 1 0)", "SEGMENT(0 0, 2 0)", 'c', 2, "POINT(0 0)", "POINT(1 0)");
139
140 // starting at p2
141 // |
142 // /
143 test_spherical_strategy<segment_t, point_t>(
144 "SEGMENT(-1 -1, 1 1)", "SEGMENT(1 1, 2 2)", 'a', 1, "POINT(1 1)");
145 // ------
146 // ---
147 test_spherical_strategy<segment_t, point_t>(
148 "SEGMENT(-1 0, 1 0)", "SEGMENT(1 0, 2 0)", 'a', 1, "POINT(1 0)");
149
150 // disjoint, crossing
151 // /
152 // |
153 test_spherical_strategy<segment_t, point_t>(
154 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-3 -3, -2 -2)", 'd', 0);
155 // |
156 // /
157 test_spherical_strategy<segment_t, point_t>(
158 "SEGMENT(-1 -1, 1 1)", "SEGMENT(2 2, 3 3)", 'd', 0);
159 // disjoint, collinear
160 // ------
161 // ------
162 test_spherical_strategy<segment_t, point_t>(
163 "SEGMENT(-1 0, 1 0)", "SEGMENT(-3 0, -2 0)", 'd', 0);
164 // ------
165 // ------
166 test_spherical_strategy<segment_t, point_t>(
167 "SEGMENT(-1 0, 1 0)", "SEGMENT(2 0, 3 0)", 'd', 0);
168
169 // degenerated
170 // /
171 // *
172 test_spherical_strategy<segment_t, point_t>(
173 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-2 -2, -2 -2)", 'd', 0);
174 // /
175 // *
176 test_spherical_strategy<segment_t, point_t>(
177 "SEGMENT(-1 -1, 1 1)", "SEGMENT(-1 -1, -1 -1)", '0', 1, "POINT(-1 -1)");
178 // /
179 // *
180 // /
181 test_spherical_strategy<segment_t, point_t>(
182 "SEGMENT(-1 -1, 1 1)", "SEGMENT(0 0, 0 0)", '0', 1, "POINT(0 0)");
183 // *
184 // /
185 test_spherical_strategy<segment_t, point_t>(
186 "SEGMENT(-1 -1, 1 1)", "SEGMENT(1 1, 1 1)", '0', 1, "POINT(1 1)");
187 // *
188 // /
189 test_spherical_strategy<segment_t, point_t>(
190 "SEGMENT(-1 -1, 1 1)", "SEGMENT(2 2, 2 2)", 'd', 0);
191 // similar to above, collinear
192 // * ------
193 test_spherical_strategy<segment_t, point_t>(
194 "SEGMENT(-1 0, 1 0)", "SEGMENT(-2 0, -2 0)", 'd', 0);
195 // *------
196 test_spherical_strategy<segment_t, point_t>(
197 "SEGMENT(-1 0, 1 0)", "SEGMENT(-1 0, -1 0)", '0', 1, "POINT(-1 0)");
198 // ---*---
199 test_spherical_strategy<segment_t, point_t>(
200 "SEGMENT(-1 0, 1 0)", "SEGMENT(0 0, 0 0)", '0', 1, "POINT(0 0)");
201 // ------*
202 test_spherical_strategy<segment_t, point_t>(
203 "SEGMENT(-1 0, 1 0)", "SEGMENT(1 0, 1 0)", '0', 1, "POINT(1 0)");
204 // ------ *
205 test_spherical_strategy<segment_t, point_t>(
206 "SEGMENT(-1 0, 1 0)", "SEGMENT(2 0, 2 0)", 'd', 0);
207
208 // Northern hemisphere
209 // --- ------
210 test_spherical_strategy<segment_t, point_t>(
211 "SEGMENT(-1 50, 1 50)", "SEGMENT(-3 50, -2 50)", 'd', 0);
212 // ------
213 // ---
214 test_spherical_strategy<segment_t, point_t>(
215 "SEGMENT(-1 50, 1 50)", "SEGMENT(-2 50, -1 50)", 'a', 1, "POINT(-1 50)");
216 // \/
217 // /\ (avoid multi-line comment)
218 test_spherical_strategy<segment_t, point_t>(
219 "SEGMENT(-1 50, 1 50)", "SEGMENT(-2 50, 0 50)", 'i', 1, "POINT(-0.5 50.0032229484023)");
220 // ________
221 // / _____\ (avoid multi-line comment)
222 test_spherical_strategy<segment_t, point_t>(
223 "SEGMENT(-1 50, 1 50)", "SEGMENT(-2 50, 1 50)", 't', 1, "POINT(1 50)");
224 // _________
225 // / _____ \ (avoid multi-line comment)
226 test_spherical_strategy<segment_t, point_t>(
227 "SEGMENT(-1 50, 1 50)", "SEGMENT(-2 50, 2 50)", 'd', 0);
228 // ______
229 // /___ \ (avoid multi-line comment)
230 test_spherical_strategy<segment_t, point_t>(
231 "SEGMENT(-1 50, 1 50)", "SEGMENT(-1 50, 0 50)", 'f', 1, "POINT(-1 50)");
232 // ------
233 // ------
234 test_spherical_strategy<segment_t, point_t>(
235 "SEGMENT(-1 50, 1 50)", "SEGMENT(-1 50, 1 50)", 'e', 2, "POINT(-1 50)", "POINT(1 50)");
236 // ________
237 // /_____ \ (avoid multi-line comment)
238 test_spherical_strategy<segment_t, point_t>(
239 "SEGMENT(-1 50, 1 50)", "SEGMENT(-1 50, 2 50)", 'f', 1, "POINT(-1 50)");
240 // ______
241 // / ___\ (avoid multi-line comment)
242 test_spherical_strategy<segment_t, point_t>(
243 "SEGMENT(-1 50, 1 50)", "SEGMENT(0 50, 1 50)", 't', 1, "POINT(1 50)");
244 // \/
245 // /\ (avoid multi-line comment)
246 test_spherical_strategy<segment_t, point_t>(
247 "SEGMENT(-1 50, 1 50)", "SEGMENT(0 50, 2 50)", 'i', 1, "POINT(0.5 50.0032229484023)");
248 // ------
249 // ---
250 test_spherical_strategy<segment_t, point_t>(
251 "SEGMENT(-1 50, 1 50)", "SEGMENT(1 50, 2 50)", 'a', 1, "POINT(1 50)");
252 // ------ ---
253 test_spherical_strategy<segment_t, point_t>(
254 "SEGMENT(-1 50, 1 50)", "SEGMENT(2 50, 3 50)", 'd', 0);
255
256 // ___|
257 test_spherical_strategy<segment_t, point_t>(
258 "SEGMENT(0 0, 1 0)", "SEGMENT(1 0, 1 1)", 'a', 1, "POINT(1 0)");
259 // ___|
260 test_spherical_strategy<segment_t, point_t>(
261 "SEGMENT(1 0, 1 1)", "SEGMENT(0 0, 1 0)", 'a', 1, "POINT(1 0)");
262
263 // |/
264 // /|
265 test_spherical_strategy<segment_t, point_t>(
266 "SEGMENT(10 -1, 20 1)", "SEGMENT(12.5 -1, 12.5 1)", 'i', 1, "POINT(12.5 -0.50051443471392)");
267 // |/
268 // /|
269 test_spherical_strategy<segment_t, point_t>(
270 "SEGMENT(10 -1, 20 1)", "SEGMENT(17.5 -1, 17.5 1)", 'i', 1, "POINT(17.5 0.50051443471392)");
271 }
272
273 template <typename T>
test_spherical_radian()274 void test_spherical_radian()
275 {
276 typedef bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::radian> > point_t;
277 typedef bg::model::segment<point_t> segment_t;
278
279 bg::strategy::intersection::spherical_segments<> strategy;
280
281 // https://github.com/boostorg/geometry/issues/470
282 point_t p0(0.00001, 0.00001);
283 point_t p1(0.00001, 0.00005);
284 point_t p2(0.00005, 0.00005);
285 segment_t s1(p0, p1);
286 segment_t s2(p1, p2);
287 test_strategy_one(s1, s1, strategy, 'e', 2, p0, p1);
288 test_strategy_one(s2, s2, strategy, 'e', 2, p1, p2);
289 }
290
test_main(int,char * [])291 int test_main(int, char* [])
292 {
293 //test_spherical<float>();
294 test_spherical<double>();
295
296 test_spherical_radian<double>();
297
298 return 0;
299 }
300