3 // Copyright (c) 2017 Oracle and/or its affiliates.
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
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)
11 #include <geometry_test_common.hpp>
13 #include <boost/concept_check.hpp>
15 #include <boost/geometry/core/srs.hpp>
16 #include <boost/geometry/algorithms/assign.hpp>
17 #include <boost/geometry/geometries/point.hpp>
18 #include <boost/geometry/strategies/strategies.hpp>
20 #include <test_common/test_point.hpp>
23 # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
26 typedef bg::srs::spheroid
<double> stype
;
28 typedef bg::strategy::andoyer andoyer_formula
;
29 typedef bg::strategy::thomas thomas_formula
;
30 typedef bg::strategy::vincenty vincenty_formula
;
35 typedef typename
bg::coordinate_type
<P
>::type ct
;
36 return boost::is_integral
<ct
>::value
|| boost::is_float
<ct
>::value
;
39 template <typename P1
, typename P2
, typename FormulaPolicy
>
40 void test_distance(double lon1
, double lat1
, double lon2
, double lat2
)
42 typedef typename
bg::promote_floating_point
44 typename
bg::select_calculation_type
<P1
, P2
, void>::type
47 calc_t tolerance
= non_precise_ct
<P1
>() || non_precise_ct
<P2
>() ?
53 bg::assign_values(p1
, lon1
, lat1
);
54 bg::assign_values(p2
, lon2
, lat2
);
56 // Test strategy that implements meridian distance against formula
57 // that implements general distance
58 // That may change in the future but in any case these calls must return
61 calc_t dist_formula
= FormulaPolicy::template inverse
63 double, true, false, false, false, false
64 >::apply(lon1
* bg::math::d2r
<double>(),
65 lat1
* bg::math::d2r
<double>(),
66 lon2
* bg::math::d2r
<double>(),
67 lat2
* bg::math::d2r
<double>(),
70 bg::strategy::distance::geographic
<FormulaPolicy
, stype
> strategy
;
71 calc_t dist_strategy
= strategy
.apply(p1
, p2
);
72 BOOST_CHECK_CLOSE(dist_formula
, dist_strategy
, tolerance
);
75 template <typename P1
, typename P2
, typename FormulaPolicy
>
76 void test_distance_reverse(double lon1
, double lat1
,
77 double lon2
, double lat2
)
79 test_distance
<P1
, P2
, FormulaPolicy
>(lon1
, lat1
, lon2
, lat2
);
80 test_distance
<P1
, P2
, FormulaPolicy
>(lon2
, lat2
, lon1
, lat1
);
83 template <typename P1
, typename P2
, typename FormulaPolicy
>
86 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., 70., 0., 80.);
87 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0, 70, 0., -80.);
88 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 0., 80.);
89 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 0., -80.);
91 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., 70., 180., 80.);
92 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., 70., 180., -80.);
93 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 180., 80.);
94 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 180., -80.);
96 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., 70., 170., 80.);
97 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., 70., 170., -80.);
98 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., -70., 170., 80.);
99 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., -70., 170., -80.);
102 template <typename P
>
105 test_meridian
<P
, P
, andoyer_formula
>();
106 test_meridian
<P
, P
, thomas_formula
>();
107 test_meridian
<P
, P
, vincenty_formula
>();
110 int test_main(int, char* [])
112 test_all
<bg::model::point
<double, 2, bg::cs::geographic
<bg::degree
> > >();
113 test_all
<bg::model::point
<float, 2, bg::cs::geographic
<bg::degree
> > >();
114 test_all
<bg::model::point
<int, 2, bg::cs::geographic
<bg::degree
> > >();