1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
8 // This file was modified by Oracle on 2015, 2017.
9 // Modifications copyright (c) 2015-2017 Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
21 #include <geometry_test_common.hpp>
23 #include <boost/concept_check.hpp>
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>
33 #include <test_common/test_point.hpp>
36 template <typename P1
, typename P2
>
37 void test_distance(double lon1
, double lat1
, double lon2
, double lat2
, double expected_km
)
39 // Set radius type, but for integer coordinates we want to have floating point radius type
40 typedef typename
bg::promote_floating_point
42 typename
bg::coordinate_type
<P1
>::type
45 typedef bg::srs::spheroid
<rtype
> stype
;
47 typedef bg::strategy::distance::thomas
<stype
> thomas_type
;
48 typedef bg::strategy::distance::geographic
<bg::strategy::thomas
, stype
> geographic_type
;
52 (bg::concepts::PointDistanceStrategy
<thomas_type
, P1
, P2
>)
56 geographic_type geographic
;
57 typedef typename
bg::strategy::distance
58 ::services::return_type
<thomas_type
, P1
, P2
>::type return_type
;
64 bg::assign_values(p1
, lon1
, lat1
);
65 bg::assign_values(p2
, lon2
, lat2
);
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);
72 template <typename PS
, typename P
>
73 void test_side(double lon1
, double lat1
,
74 double lon2
, double lat2
,
75 double lon
, double lat
,
78 // Set radius type, but for integer coordinates we want to have floating point radius type
79 typedef typename
bg::promote_floating_point
81 typename
bg::coordinate_type
<PS
>::type
84 typedef bg::srs::spheroid
<rtype
> stype
;
86 typedef bg::strategy::side::thomas
<stype
> strategy_type
;
87 typedef bg::strategy::side::geographic
<bg::strategy::thomas
, stype
> strategy2_type
;
89 strategy_type strategy
;
90 strategy2_type strategy2
;
95 bg::assign_values(p1
, lon1
, lat1
);
96 bg::assign_values(p2
, lon2
, lat2
);
97 bg::assign_values(p
, lon
, lat
);
99 int side
= strategy
.apply(p1
, p2
, p
);
100 int side2
= strategy2
.apply(p1
, p2
, p
);
102 BOOST_CHECK_EQUAL(side
, expected_side
);
103 BOOST_CHECK_EQUAL(side2
, expected_side
);
106 template <typename P1
, typename P2
>
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
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);
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
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
128 template <typename P
>
134 int test_main(int, char* [])
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
> > >();