3 // Copyright (c) 2017-2021 Oracle and/or its affiliates.
4 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
5 // Contributed and/or modified by Adam Wulkiewicz, 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/srs/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>
22 typedef bg::srs::spheroid
<double> stype
;
24 typedef bg::strategy::andoyer andoyer_formula
;
25 typedef bg::strategy::thomas thomas_formula
;
26 typedef bg::strategy::vincenty vincenty_formula
;
31 using ct
= typename
bg::coordinate_type
<P
>::type
;
32 return std::is_integral
<ct
>::value
|| std::is_floating_point
<ct
>::value
;
35 template <typename P1
, typename P2
, typename FormulaPolicy
>
36 void test_distance(double lon1
, double lat1
, double lon2
, double lat2
)
38 typedef typename
bg::promote_floating_point
40 typename
bg::select_calculation_type
<P1
, P2
, void>::type
43 calc_t tolerance
= non_precise_ct
<P1
>() || non_precise_ct
<P2
>() ?
49 bg::assign_values(p1
, lon1
, lat1
);
50 bg::assign_values(p2
, lon2
, lat2
);
52 // Test strategy that implements meridian distance against formula
53 // that implements general distance
54 // That may change in the future but in any case these calls must return
57 calc_t dist_formula
= FormulaPolicy::template inverse
59 double, true, false, false, false, false
60 >::apply(lon1
* bg::math::d2r
<double>(),
61 lat1
* bg::math::d2r
<double>(),
62 lon2
* bg::math::d2r
<double>(),
63 lat2
* bg::math::d2r
<double>(),
66 bg::strategy::distance::geographic
<FormulaPolicy
, stype
> strategy
;
67 calc_t dist_strategy
= strategy
.apply(p1
, p2
);
68 BOOST_CHECK_CLOSE(dist_formula
, dist_strategy
, tolerance
);
71 template <typename P1
, typename P2
, typename FormulaPolicy
>
72 void test_distance_reverse(double lon1
, double lat1
,
73 double lon2
, double lat2
)
75 test_distance
<P1
, P2
, FormulaPolicy
>(lon1
, lat1
, lon2
, lat2
);
76 test_distance
<P1
, P2
, FormulaPolicy
>(lon2
, lat2
, lon1
, lat1
);
79 template <typename P1
, typename P2
, typename FormulaPolicy
>
82 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., 70., 0., 80.);
83 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0, 70, 0., -80.);
84 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 0., 80.);
85 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 0., -80.);
87 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., 70., 180., 80.);
88 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., 70., 180., -80.);
89 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 180., 80.);
90 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(0., -70., 180., -80.);
92 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., 70., 170., 80.);
93 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., 70., 170., -80.);
94 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., -70., 170., 80.);
95 test_distance_reverse
<P1
, P2
, FormulaPolicy
>(350., -70., 170., -80.);
101 test_meridian
<P
, P
, andoyer_formula
>();
102 test_meridian
<P
, P
, thomas_formula
>();
103 test_meridian
<P
, P
, vincenty_formula
>();
106 int test_main(int, char* [])
108 test_all
<bg::model::point
<double, 2, bg::cs::geographic
<bg::degree
> > >();
109 test_all
<bg::model::point
<float, 2, bg::cs::geographic
<bg::degree
> > >();
110 test_all
<bg::model::point
<int, 2, bg::cs::geographic
<bg::degree
> > >();