• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit test
3 
4 // Copyright (c) 2015, Oracle and/or its affiliates.
5 
6 // Licensed under the Boost Software License version 1.0.
7 // http://www.boost.org/users/license.html
8 
9 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
10 
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_equals_on_spheroid
13 #endif
14 
15 #include <iostream>
16 
17 #include <boost/test/included/unit_test.hpp>
18 
19 #include "test_equals.hpp"
20 
21 #include <boost/geometry/geometries/geometries.hpp>
22 
23 #include <boost/geometry/core/cs.hpp>
24 
25 namespace bgm = bg::model;
26 
27 template <typename P1, typename P2 = P1>
28 struct test_point_point
29 {
applytest_point_point30     static inline void apply(std::string const& header)
31     {
32         std::string const str = header + "-";
33 
34         test_geometry<P1, P2>(str + "pp_01", "POINT(0 0)", "POINT(0 0)", true);
35         test_geometry<P1, P2>(str + "pp_02", "POINT(0 0)", "POINT(10 0)", false);
36 
37         // points whose longitudes differ by 360 degrees
38         test_geometry<P1, P2>(str + "pp_03", "POINT(0 0)", "POINT(360 0)", true);
39         test_geometry<P1, P2>(str + "pp_04", "POINT(10 0)", "POINT(370 0)", true);
40         test_geometry<P1, P2>(str + "pp_05", "POINT(10 0)", "POINT(-350 0)", true);
41         test_geometry<P1, P2>(str + "pp_06", "POINT(180 10)", "POINT(-180 10)", true);
42         test_geometry<P1, P2>(str + "pp_06a", "POINT(540 10)", "POINT(-540 10)", true);
43 
44 #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
45         test_geometry<P1, P2>(str + "pp_06b", "POINT(540 370)", "POINT(-540 -350)", true);
46         test_geometry<P1, P2>(str + "pp_06c", "POINT(1260 370)", "POINT(-1260 -350)", true);
47         test_geometry<P1, P2>(str + "pp_06d", "POINT(2340 370)", "POINT(-2340 -350)", true);
48 #endif
49 
50         test_geometry<P1, P2>(str + "pp_06e", "POINT(-180 10)", "POINT(-540 10)", true);
51         test_geometry<P1, P2>(str + "pp_06f", "POINT(180 10)", "POINT(-540 10)", true);
52 
53         // north & south pole
54         test_geometry<P1, P2>(str + "pp_07", "POINT(0 90)", "POINT(0 90)", true);
55 
56 #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
57         test_geometry<P1, P2>(str + "pp_07a", "POINT(0 450)", "POINT(10 -270)", true);
58         test_geometry<P1, P2>(str + "pp_07b", "POINT(0 270)", "POINT(10 90)", false);
59         test_geometry<P1, P2>(str + "pp_07c", "POINT(0 -450)", "POINT(10 90)", false);
60 #endif
61 
62         test_geometry<P1, P2>(str + "pp_08", "POINT(0 90)", "POINT(10 90)", true);
63         test_geometry<P1, P2>(str + "pp_09", "POINT(0 90)", "POINT(0 -90)", false);
64         test_geometry<P1, P2>(str + "pp_10", "POINT(0 -90)", "POINT(0 -90)", true);
65         test_geometry<P1, P2>(str + "pp_11", "POINT(0 -90)", "POINT(10 -90)", true);
66         test_geometry<P1, P2>(str + "pp_11a", "POINT(0 -90)", "POINT(10 90)", false);
67         test_geometry<P1, P2>(str + "pp_12", "POINT(0 -90)", "POINT(0 -85)", false);
68         test_geometry<P1, P2>(str + "pp_13", "POINT(0 90)", "POINT(0 85)", false);
69         test_geometry<P1, P2>(str + "pp_14", "POINT(0 90)", "POINT(10 85)", false);
70 
71         // symmetric wrt prime meridian
72         test_geometry<P1, P2>(str + "pp_15", "POINT(-10 45)", "POINT(10 45)", false);
73         test_geometry<P1, P2>(str + "pp_16", "POINT(-170 45)", "POINT(170 45)", false);
74 
75         // other points
76         test_geometry<P1, P2>(str + "pp_17", "POINT(-10 45)", "POINT(10 -45)", false);
77         test_geometry<P1, P2>(str + "pp_18", "POINT(-10 -45)", "POINT(10 45)", false);
78         test_geometry<P1, P2>(str + "pp_19", "POINT(10 -135)", "POINT(10 45)", false);
79 
80 #ifdef BOOST_GEOMETRY_NORMALIZE_LATITUDE
81         test_geometry<P1, P2>(str + "pp_20", "POINT(190 135)", "POINT(10 45)", true);
82         test_geometry<P1, P2>(str + "pp_21", "POINT(190 150)", "POINT(10 30)", true);
83         test_geometry<P1, P2>(str + "pp_21a", "POINT(-170 150)", "POINT(10 30)", true);
84         test_geometry<P1, P2>(str + "pp_22", "POINT(190 -135)", "POINT(10 -45)", true);
85         test_geometry<P1, P2>(str + "pp_23", "POINT(190 -150)", "POINT(10 -30)", true);
86         test_geometry<P1, P2>(str + "pp_23a", "POINT(-170 -150)", "POINT(10 -30)", true);
87 #endif
88     }
89 };
90 
91 
92 template <typename P1, typename P2 = P1>
93 struct test_point_point_with_height
94 {
applytest_point_point_with_height95     static inline void apply(std::string const& header)
96     {
97         std::string const str = header + "-";
98 
99         test_geometry<P1, P2>(str + "pp_01",
100                               "POINT(0 0 10)",
101                               "POINT(0 0 20)",
102                               true);
103 
104         test_geometry<P1, P2>(str + "pp_02",
105                               "POINT(0 0 10)",
106                               "POINT(10 0 10)",
107                               false);
108 
109         // points whose longitudes differ by 360 degrees
110         test_geometry<P1, P2>(str + "pp_03",
111                               "POINT(0 0 10)",
112                               "POINT(360 0 10)",
113                               true);
114 
115         // points whose longitudes differ by 360 degrees
116         test_geometry<P1, P2>(str + "pp_04",
117                               "POINT(10 0 10)",
118                               "POINT(370 0 10)",
119                               true);
120 
121         test_geometry<P1, P2>(str + "pp_05",
122                               "POINT(10 0 10)",
123                               "POINT(10 0 370)",
124                               false);
125     }
126 };
127 
128 
129 template <typename P>
test_segment_segment(std::string const & header)130 void test_segment_segment(std::string const& header)
131 {
132     typedef bgm::segment<P> seg;
133 
134     std::string const str = header + "-";
135 
136     test_geometry<seg, seg>(str + "ss_01",
137                             "SEGMENT(10 0,180 0)",
138                             "SEGMENT(10 0,-180 0)",
139                             true);
140     test_geometry<seg, seg>(str + "ss_02",
141                             "SEGMENT(0 90,180 0)",
142                             "SEGMENT(10 90,-180 0)",
143                             true);
144     test_geometry<seg, seg>(str + "ss_03",
145                             "SEGMENT(0 90,0 -90)",
146                             "SEGMENT(10 90,20 -90)",
147                             true);
148     test_geometry<seg, seg>(str + "ss_04",
149                             "SEGMENT(10 80,10 -80)",
150                             "SEGMENT(10 80,20 -80)",
151                             false);
152     test_geometry<seg, seg>(str + "ss_05",
153                             "SEGMENT(170 10,-170 10)",
154                             "SEGMENT(170 10,350 10)",
155                             false);
156 }
157 
158 
BOOST_AUTO_TEST_CASE(equals_point_point_se)159 BOOST_AUTO_TEST_CASE( equals_point_point_se )
160 {
161     typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
162 
163     test_point_point<bgm::point<int, 2, cs_type> >::apply("se");
164     test_point_point<bgm::point<double, 2, cs_type> >::apply("se");
165     test_point_point<bgm::point<long double, 2, cs_type> >::apply("se");
166 
167     // mixed point types
168     test_point_point
169         <
170             bgm::point<double, 2, cs_type>, bgm::point<int, 2, cs_type>
171         >::apply("se");
172 
173     test_point_point
174         <
175             bgm::point<double, 2, cs_type>, bgm::point<long double, 2, cs_type>
176         >::apply("se");
177 
178 #if defined(HAVE_TTMATH)
179     test_point_point<bgm::point<ttmath_big, 2, cs_type> >::apply("se");
180 #endif
181 }
182 
BOOST_AUTO_TEST_CASE(equals_point_point_with_height_se)183 BOOST_AUTO_TEST_CASE( equals_point_point_with_height_se )
184 {
185     typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
186 
187     test_point_point<bgm::point<int, 3, cs_type> >::apply("seh");
188     test_point_point<bgm::point<double, 3, cs_type> >::apply("seh");
189     test_point_point<bgm::point<long double, 3, cs_type> >::apply("seh");
190 
191     // mixed point types
192     test_point_point
193         <
194             bgm::point<double, 3, cs_type>, bgm::point<int, 3, cs_type>
195         >::apply("seh");
196 
197     test_point_point
198         <
199             bgm::point<double, 3, cs_type>, bgm::point<long double, 3, cs_type>
200         >::apply("seh");
201 
202 #if defined(HAVE_TTMATH)
203     test_point_point<bgm::point<ttmath_big, 3, cs_type> >::apply("seh");
204 #endif
205 }
206 
BOOST_AUTO_TEST_CASE(equals_point_point_geo)207 BOOST_AUTO_TEST_CASE( equals_point_point_geo )
208 {
209     typedef bg::cs::geographic<bg::degree> cs_type;
210 
211     test_point_point<bgm::point<int, 2, cs_type> >::apply("geo");
212     test_point_point<bgm::point<double, 2, cs_type> >::apply("geo");
213     test_point_point<bgm::point<long double, 2, cs_type> >::apply("geo");
214 
215     // mixed point types
216     test_point_point
217         <
218             bgm::point<double, 2, cs_type>, bgm::point<int, 2, cs_type>
219         >::apply("se");
220 
221     test_point_point
222         <
223             bgm::point<double, 2, cs_type>, bgm::point<long double, 2, cs_type>
224         >::apply("se");
225 
226 #if defined(HAVE_TTMATH)
227     test_point_point<bgm::point<ttmath_big, 2, cs_type> >::apply("geo");
228 #endif
229 }
230 
BOOST_AUTO_TEST_CASE(equals_segment_segment_se)231 BOOST_AUTO_TEST_CASE( equals_segment_segment_se )
232 {
233     typedef bg::cs::spherical_equatorial<bg::degree> cs_type;
234 
235     test_segment_segment<bgm::point<int, 2, cs_type> >("se");
236     test_segment_segment<bgm::point<double, 2, cs_type> >("se");
237     test_segment_segment<bgm::point<long double, 2, cs_type> >("se");
238 
239 #if defined(HAVE_TTMATH)
240     test_segment_segment<bgm::point<ttmath_big, 2, cs_type> >("se");
241 #endif
242 }
243 
BOOST_AUTO_TEST_CASE(equals_segment_segment_geo)244 BOOST_AUTO_TEST_CASE( equals_segment_segment_geo )
245 {
246     typedef bg::cs::geographic<bg::degree> cs_type;
247 
248     test_segment_segment<bgm::point<int, 2, cs_type> >("geo");
249     test_segment_segment<bgm::point<double, 2, cs_type> >("geo");
250     test_segment_segment<bgm::point<long double, 2, cs_type> >("geo");
251 
252 #if defined(HAVE_TTMATH)
253     test_segment_segment<bgm::point<ttmath_big, 2, cs_type> >("geo");
254 #endif
255 }
256