]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/thomas.cpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / libs / geometry / test / strategies / thomas.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 2015, 2017.
9 // Modifications copyright (c) 2015-2017 Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19
20
21 #include <geometry_test_common.hpp>
22
23 #include <boost/concept_check.hpp>
24
25 #include <boost/geometry/algorithms/assign.hpp>
26 #include <boost/geometry/algorithms/distance.hpp>
27 #include <boost/geometry/geometries/point.hpp>
28 #include <boost/geometry/srs/spheroid.hpp>
29 #include <boost/geometry/strategies/concepts/distance_concept.hpp>
30 #include <boost/geometry/strategies/geographic/distance_thomas.hpp>
31 #include <boost/geometry/strategies/geographic/side_thomas.hpp>
32
33 #include <test_common/test_point.hpp>
34
35
36 template <typename P1, typename P2>
37 void test_distance(double lon1, double lat1, double lon2, double lat2, double expected_km)
38 {
39 // Set radius type, but for integer coordinates we want to have floating point radius type
40 typedef typename bg::promote_floating_point
41 <
42 typename bg::coordinate_type<P1>::type
43 >::type rtype;
44
45 typedef bg::srs::spheroid<rtype> stype;
46
47 typedef bg::strategy::distance::thomas<stype> thomas_type;
48 typedef bg::strategy::distance::geographic<bg::strategy::thomas, stype> geographic_type;
49
50 BOOST_CONCEPT_ASSERT
51 (
52 (bg::concepts::PointDistanceStrategy<thomas_type, P1, P2>)
53 );
54
55 thomas_type thomas;
56 geographic_type geographic;
57 typedef typename bg::strategy::distance
58 ::services::return_type<thomas_type, P1, P2>::type return_type;
59
60
61 P1 p1;
62 P2 p2;
63
64 bg::assign_values(p1, lon1, lat1);
65 bg::assign_values(p2, lon2, lat2);
66
67 BOOST_CHECK_CLOSE(thomas.apply(p1, p2), return_type(1000.0 * expected_km), 0.001);
68 BOOST_CHECK_CLOSE(geographic.apply(p1, p2), return_type(1000.0 * expected_km), 0.001);
69 BOOST_CHECK_CLOSE(bg::distance(p1, p2, thomas), return_type(1000.0 * expected_km), 0.001);
70 }
71
72 template <typename PS, typename P>
73 void test_side(double lon1, double lat1,
74 double lon2, double lat2,
75 double lon, double lat,
76 int expected_side)
77 {
78 // Set radius type, but for integer coordinates we want to have floating point radius type
79 typedef typename bg::promote_floating_point
80 <
81 typename bg::coordinate_type<PS>::type
82 >::type rtype;
83
84 typedef bg::srs::spheroid<rtype> stype;
85
86 typedef bg::strategy::side::thomas<stype> strategy_type;
87 typedef bg::strategy::side::geographic<bg::strategy::thomas, stype> strategy2_type;
88
89 strategy_type strategy;
90 strategy2_type strategy2;
91
92 PS p1, p2;
93 P p;
94
95 bg::assign_values(p1, lon1, lat1);
96 bg::assign_values(p2, lon2, lat2);
97 bg::assign_values(p, lon, lat);
98
99 int side = strategy.apply(p1, p2, p);
100 int side2 = strategy2.apply(p1, p2, p);
101
102 BOOST_CHECK_EQUAL(side, expected_side);
103 BOOST_CHECK_EQUAL(side2, expected_side);
104 }
105
106 template <typename P1, typename P2>
107 void test_all()
108 {
109 test_distance<P1, P2>(0, 90, 1, 80, 1116.825795); // polar
110 test_distance<P1, P2>(0, -90, 1, -80, 1116.825795); // polar
111 test_distance<P1, P2>(4, 52, 4, 52, 0.0); // no point difference
112 test_distance<P1, P2>(4, 52, 3, 40, 1336.025365); // normal case
113
114 test_side<P1, P2>(0, 0, 0, 1, 0, 2, 0);
115 test_side<P1, P2>(0, 0, 0, 1, 0, -2, 0);
116 test_side<P1, P2>(10, 0, 10, 1, 10, 2, 0);
117 test_side<P1, P2>(10, 0, 10, -1, 10, 2, 0);
118
119 test_side<P1, P2>(10, 0, 10, 1, 0, 2, 1); // left
120 test_side<P1, P2>(10, 0, 10, -1, 0, 2, -1); // right
121
122 test_side<P1, P2>(-10, -10, 10, 10, 10, 0, -1); // right
123 test_side<P1, P2>(-10, -10, 10, 10, -10, 0, 1); // left
124 test_side<P1, P2>(170, -10, -170, 10, -170, 0, -1); // right
125 test_side<P1, P2>(170, -10, -170, 10, 170, 0, 1); // left
126 }
127
128 template <typename P>
129 void test_all()
130 {
131 test_all<P, P>();
132 }
133
134 int test_main(int, char* [])
135 {
136 //test_all<float[2]>();
137 //test_all<double[2]>();
138 test_all<bg::model::point<int, 2, bg::cs::geographic<bg::degree> > >();
139 test_all<bg::model::point<float, 2, bg::cs::geographic<bg::degree> > >();
140 test_all<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
141
142 return 0;
143 }