• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
5 
6 // Copyright (c) 2016, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 
13 #ifndef BOOST_GEOMETRY_TEST_STRATEGIES_SEGMENT_INTERSECTION_GEO_HPP
14 #define BOOST_GEOMETRY_TEST_STRATEGIES_SEGMENT_INTERSECTION_GEO_HPP
15 
16 
17 #include "segment_intersection_sph.hpp"
18 
19 #include <boost/geometry/strategies/geographic/intersection.hpp>
20 #include <boost/geometry/strategies/geographic/intersection_elliptic.hpp>
21 
22 
23 template <typename S, typename P>
test_default_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="",int opposite_id=-1)24 void test_default_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
25                            char m, std::size_t expected_count,
26                            std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
27                            int opposite_id = -1)
28 {
29     typename bg::strategy::intersection::services::default_strategy
30         <
31             bg::geographic_tag
32         >::type strategy;
33 
34     test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
35 }
36 
37 template <typename S, typename P>
test_great_elliptic(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="",int opposite_id=-1)38 void test_great_elliptic(std::string const& s1_wkt, std::string const& s2_wkt,
39                          char m, std::size_t expected_count,
40                          std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
41                          int opposite_id = -1)
42 {
43     bg::strategy::intersection::great_elliptic_segments<> strategy;
44 
45     test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
46 }
47 /*
48 template <typename S, typename P>
49 void test_experimental_elliptic(std::string const& s1_wkt, std::string const& s2_wkt,
50                                 char m, std::size_t expected_count,
51                                 std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
52                                 int opposite_id = -1)
53 {
54     bg::strategy::intersection::experimental_elliptic_segments<> strategy;
55 
56     test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
57 }
58 */
59 template <typename S, typename P>
test_geodesic_vincenty(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="",int opposite_id=-1)60 void test_geodesic_vincenty(std::string const& s1_wkt, std::string const& s2_wkt,
61                             char m, std::size_t expected_count,
62                             std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
63                             int opposite_id = -1)
64 {
65     bg::strategy::intersection::geographic_segments<bg::strategy::vincenty, 4> strategy;
66 
67     test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
68 }
69 
70 template <typename S, typename P>
test_geodesic_thomas(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="",int opposite_id=-1)71 void test_geodesic_thomas(std::string const& s1_wkt, std::string const& s2_wkt,
72                           char m, std::size_t expected_count,
73                           std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
74                           int opposite_id = -1)
75 {
76     bg::strategy::intersection::geographic_segments<bg::strategy::thomas, 2> strategy;
77 
78     test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
79 }
80 
81 template <typename S, typename P>
test_geodesic_andoyer(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="",int opposite_id=-1)82 void test_geodesic_andoyer(std::string const& s1_wkt, std::string const& s2_wkt,
83                            char m, std::size_t expected_count,
84                            std::string const& ip0_wkt = "", std::string const& ip1_wkt = "",
85                            int opposite_id = -1)
86 {
87     bg::strategy::intersection::geographic_segments<bg::strategy::andoyer, 1> strategy;
88 
89     test_strategy<S, S, P>(s1_wkt, s2_wkt, strategy, m, expected_count, ip0_wkt, ip1_wkt, opposite_id);
90 }
91 
92 
93 struct strategy_base
94 {
strategy_basestrategy_base95     strategy_base(char m_)
96         : m(m_), expected_count(0), opposite(-1)
97     {}
strategy_basestrategy_base98     strategy_base(char m_, std::string const& wkt1_)
99         : m(m_), expected_count(1), wkt1(wkt1_), opposite(-1)
100     {}
strategy_basestrategy_base101     strategy_base(char m_, std::string const& wkt1_, std::string const& wkt2_, bool opposite_)
102         : m(m_), expected_count(1), wkt1(wkt1_), wkt2(wkt2_), opposite(opposite_ ? 1 : 0)
103     {}
104 
105     char m;
106     std::size_t expected_count;
107     std::string wkt1, wkt2;
108     int opposite;
109 };
110 struct strategy_default : strategy_base
111 {
strategy_defaultstrategy_default112     strategy_default(char m)
113         : strategy_base(m)
114     {}
strategy_defaultstrategy_default115     strategy_default(char m, std::string const& wkt1)
116         : strategy_base(m, wkt1)
117     {}
strategy_defaultstrategy_default118     strategy_default(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
119         : strategy_base(m, wkt1, wkt2, opposite)
120     {}
121 };
122 struct geodesic_vincenty : strategy_base
123 {
geodesic_vincentygeodesic_vincenty124     geodesic_vincenty(char m)
125         : strategy_base(m)
126     {}
geodesic_vincentygeodesic_vincenty127     geodesic_vincenty(char m, std::string const& wkt1)
128         : strategy_base(m, wkt1)
129     {}
geodesic_vincentygeodesic_vincenty130     geodesic_vincenty(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
131         : strategy_base(m, wkt1, wkt2, opposite)
132     {}
133 };
134 struct geodesic_thomas : strategy_base
135 {
geodesic_thomasgeodesic_thomas136     geodesic_thomas(char m)
137         : strategy_base(m)
138     {}
geodesic_thomasgeodesic_thomas139     geodesic_thomas(char m, std::string const& wkt1)
140         : strategy_base(m, wkt1)
141     {}
geodesic_thomasgeodesic_thomas142     geodesic_thomas(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
143         : strategy_base(m, wkt1, wkt2, opposite)
144     {}
145 };
146 struct geodesic_andoyer : strategy_base
147 {
geodesic_andoyergeodesic_andoyer148     geodesic_andoyer(char m)
149         : strategy_base(m)
150     {}
geodesic_andoyergeodesic_andoyer151     geodesic_andoyer(char m, std::string const& wkt1)
152         : strategy_base(m, wkt1)
153     {}
geodesic_andoyergeodesic_andoyer154     geodesic_andoyer(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
155         : strategy_base(m, wkt1, wkt2, opposite)
156     {}
157 };
158 struct great_elliptic : strategy_base
159 {
great_ellipticgreat_elliptic160     great_elliptic(char m)
161         : strategy_base(m)
162     {}
great_ellipticgreat_elliptic163     great_elliptic(char m, std::string const& wkt1)
164         : strategy_base(m, wkt1)
165     {}
great_ellipticgreat_elliptic166     great_elliptic(char m, std::string const& wkt1, std::string const& wkt2, bool opposite)
167         : strategy_base(m, wkt1, wkt2, opposite)
168     {}
169 };
170 
171 
172 template <typename S, typename P>
test_strategy(std::string const & s1_wkt,std::string const & s2_wkt,strategy_default const & s)173 void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
174                    strategy_default const& s)
175 {
176     test_default_strategy<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
177 }
178 
179 template <typename S, typename P>
test_strategy(std::string const & s1_wkt,std::string const & s2_wkt,great_elliptic const & s)180 void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
181                    great_elliptic const& s)
182 {
183     test_great_elliptic<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
184 }
185 
186 template <typename S, typename P>
test_strategy(std::string const & s1_wkt,std::string const & s2_wkt,geodesic_vincenty const & s)187 void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
188                    geodesic_vincenty const& s)
189 {
190     test_geodesic_vincenty<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
191 }
192 
193 template <typename S, typename P>
test_strategy(std::string const & s1_wkt,std::string const & s2_wkt,geodesic_thomas const & s)194 void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
195                    geodesic_thomas const& s)
196 {
197     test_geodesic_thomas<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
198 }
199 
200 template <typename S, typename P>
test_strategy(std::string const & s1_wkt,std::string const & s2_wkt,geodesic_andoyer const & s)201 void test_strategy(std::string const& s1_wkt, std::string const& s2_wkt,
202                    geodesic_andoyer const& s)
203 {
204     test_geodesic_andoyer<S, P>(s1_wkt, s2_wkt, s.m, s.expected_count, s.wkt1, s.wkt2);
205 }
206 
207 
208 template <typename S, typename P, typename SR1>
test_strategies(std::string const & s1_wkt,std::string const & s2_wkt,SR1 const & sr1)209 void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
210                      SR1 const& sr1)
211 {
212     test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
213 }
214 template <typename S, typename P, typename SR1, typename SR2>
test_strategies(std::string const & s1_wkt,std::string const & s2_wkt,SR1 const & sr1,SR2 const & sr2)215 void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
216                      SR1 const& sr1, SR2 const& sr2)
217 {
218     test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
219     test_strategy<S, P>(s1_wkt, s2_wkt, sr2);
220 }
221 template <typename S, typename P, typename SR1, typename SR2, typename SR3>
test_strategies(std::string const & s1_wkt,std::string const & s2_wkt,SR1 const & sr1,SR2 const & sr2,SR3 const & sr3)222 void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
223                      SR1 const& sr1, SR2 const& sr2, SR3 const& sr3)
224 {
225     test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
226     test_strategy<S, P>(s1_wkt, s2_wkt, sr2);
227     test_strategy<S, P>(s1_wkt, s2_wkt, sr3);
228 }
229 template <typename S, typename P, typename SR1, typename SR2, typename SR3, typename SR4>
test_strategies(std::string const & s1_wkt,std::string const & s2_wkt,SR1 const & sr1,SR2 const & sr2,SR3 const & sr3,SR4 const & sr4)230 void test_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
231                      SR1 const& sr1, SR2 const& sr2, SR3 const& sr3, SR4 const& sr4)
232 {
233     test_strategy<S, P>(s1_wkt, s2_wkt, sr1);
234     test_strategy<S, P>(s1_wkt, s2_wkt, sr2);
235     test_strategy<S, P>(s1_wkt, s2_wkt, sr3);
236     test_strategy<S, P>(s1_wkt, s2_wkt, sr4);
237 }
238 
239 
240 template <typename S, typename P>
test_all_strategies(std::string const & s1_wkt,std::string const & s2_wkt,char m,std::string const & ip0_wkt="")241 void test_all_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
242                          char m, std::string const& ip0_wkt = "")
243 {
244     std::size_t expected_count = ip0_wkt.empty() ? 0 : 1;
245 
246     test_default_strategy<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
247     test_great_elliptic<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
248     //test_experimental_elliptic<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
249     test_geodesic_vincenty<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
250     test_geodesic_thomas<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
251     test_geodesic_andoyer<S, P>(s1_wkt, s2_wkt, m, expected_count, ip0_wkt);
252 }
253 
254 template <typename S, typename P>
test_all_strategies(std::string const & s1_wkt,std::string const & s2_wkt,char m,std::string const & ip0_wkt,std::string const & ip1_wkt,bool opposite)255 void test_all_strategies(std::string const& s1_wkt, std::string const& s2_wkt,
256                          char m,
257                          std::string const& ip0_wkt, std::string const& ip1_wkt,
258                          bool opposite)
259 {
260     int opposite_id = opposite ? 1 : 0;
261 
262     test_default_strategy<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
263     test_great_elliptic<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
264     //test_experimental_elliptic<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
265     test_geodesic_vincenty<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
266     test_geodesic_thomas<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
267     test_geodesic_andoyer<S, P>(s1_wkt, s2_wkt, m, 2, ip0_wkt, ip1_wkt, opposite_id);
268 }
269 
270 #endif // BOOST_GEOMETRY_TEST_STRATEGIES_SEGMENT_INTERSECTION_GEO_HPP
271