]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/thomas.cpp
add subtree-ish sources for 12.0.3
[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.
9 // Modifications copyright (c) 2015 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/strategies/geographic/distance_thomas.hpp>
26 #include <boost/geometry/strategies/geographic/side_thomas.hpp>
27
28 #include <boost/geometry/core/srs.hpp>
29 #include <boost/geometry/strategies/strategies.hpp>
30 #include <boost/geometry/algorithms/assign.hpp>
31 #include <boost/geometry/geometries/point.hpp>
32 #include <test_common/test_point.hpp>
33
34 #ifdef HAVE_TTMATH
35 # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
36 #endif
37
38
39
40 template <typename P1, typename P2>
41 void test_distance(double lon1, double lat1, double lon2, double lat2, double expected_km)
42 {
43 // Set radius type, but for integer coordinates we want to have floating point radius type
44 typedef typename bg::promote_floating_point
45 <
46 typename bg::coordinate_type<P1>::type
47 >::type rtype;
48
49 typedef bg::srs::spheroid<rtype> stype;
50
51 typedef bg::strategy::distance::thomas<stype> thomas_type;
52
53 BOOST_CONCEPT_ASSERT
54 (
55 (bg::concepts::PointDistanceStrategy<thomas_type, P1, P2>)
56 );
57
58 thomas_type thomas;
59 typedef typename bg::strategy::distance
60 ::services::return_type<thomas_type, P1, P2>::type return_type;
61
62
63 P1 p1;
64 P2 p2;
65
66 bg::assign_values(p1, lon1, lat1);
67 bg::assign_values(p2, lon2, lat2);
68
69 BOOST_CHECK_CLOSE(thomas.apply(p1, p2), return_type(1000.0 * expected_km), 0.001);
70 BOOST_CHECK_CLOSE(bg::distance(p1, p2, thomas), return_type(1000.0 * expected_km), 0.001);
71 }
72
73 template <typename PS, typename P>
74 void test_side(double lon1, double lat1,
75 double lon2, double lat2,
76 double lon, double lat,
77 int expected_side)
78 {
79 // Set radius type, but for integer coordinates we want to have floating point radius type
80 typedef typename bg::promote_floating_point
81 <
82 typename bg::coordinate_type<PS>::type
83 >::type rtype;
84
85 typedef bg::srs::spheroid<rtype> stype;
86
87 typedef bg::strategy::side::thomas<stype> strategy_type;
88
89 strategy_type strategy;
90
91 PS p1, p2;
92 P p;
93
94 bg::assign_values(p1, lon1, lat1);
95 bg::assign_values(p2, lon2, lat2);
96 bg::assign_values(p, lon, lat);
97
98 int side = strategy.apply(p1, p2, p);
99
100 BOOST_CHECK_EQUAL(side, expected_side);
101 }
102
103 template <typename P1, typename P2>
104 void test_all()
105 {
106 test_distance<P1, P2>(0, 90, 1, 80, 1116.825795); // polar
107 test_distance<P1, P2>(0, -90, 1, -80, 1116.825795); // polar
108 test_distance<P1, P2>(4, 52, 4, 52, 0.0); // no point difference
109 test_distance<P1, P2>(4, 52, 3, 40, 1336.025365); // normal case
110
111 test_side<P1, P2>(0, 0, 0, 1, 0, 2, 0);
112 test_side<P1, P2>(0, 0, 0, 1, 0, -2, 0);
113 test_side<P1, P2>(10, 0, 10, 1, 10, 2, 0);
114 test_side<P1, P2>(10, 0, 10, -1, 10, 2, 0);
115
116 test_side<P1, P2>(10, 0, 10, 1, 0, 2, 1); // left
117 test_side<P1, P2>(10, 0, 10, -1, 0, 2, -1); // right
118
119 test_side<P1, P2>(-10, -10, 10, 10, 10, 0, -1); // right
120 test_side<P1, P2>(-10, -10, 10, 10, -10, 0, 1); // left
121 test_side<P1, P2>(170, -10, -170, 10, -170, 0, -1); // right
122 test_side<P1, P2>(170, -10, -170, 10, 170, 0, 1); // left
123 }
124
125 template <typename P>
126 void test_all()
127 {
128 test_all<P, P>();
129 }
130
131 int test_main(int, char* [])
132 {
133 //test_all<float[2]>();
134 //test_all<double[2]>();
135 test_all<bg::model::point<int, 2, bg::cs::geographic<bg::degree> > >();
136 test_all<bg::model::point<float, 2, bg::cs::geographic<bg::degree> > >();
137 test_all<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
138
139 #if defined(HAVE_TTMATH)
140 test_all<bg::model::point<ttmath::Big<1,4>, 2, bg::cs::geographic<bg::degree> > >();
141 test_all<bg::model::point<ttmath_big, 2, bg::cs::geographic<bg::degree> > >();
142 #endif
143
144 return 0;
145 }