1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2016 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2014-2017.
6 // Modifications copyright (c) 2014-2017 Oracle and/or its affiliates.
8 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
16 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_HPP
17 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_HPP
20 #include <boost/geometry/core/coordinate_type.hpp>
21 #include <boost/geometry/core/radian_access.hpp>
22 #include <boost/geometry/core/radius.hpp>
23 #include <boost/geometry/core/srs.hpp>
25 #include <boost/geometry/formulas/andoyer_inverse.hpp>
26 #include <boost/geometry/formulas/elliptic_arc_length.hpp>
27 #include <boost/geometry/formulas/flattening.hpp>
29 #include <boost/geometry/strategies/distance.hpp>
30 #include <boost/geometry/strategies/geographic/parameters.hpp>
32 #include <boost/geometry/util/math.hpp>
33 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
34 #include <boost/geometry/util/promote_floating_point.hpp>
35 #include <boost/geometry/util/select_calculation_type.hpp>
38 namespace boost { namespace geometry
41 namespace strategy { namespace distance
46 typename FormulaPolicy = strategy::andoyer,
47 typename Spheroid = srs::spheroid<double>,
48 typename CalculationType = void
53 template <typename Point1, typename Point2>
54 struct calculation_type
55 : promote_floating_point
57 typename select_calculation_type
66 typedef Spheroid model_type;
72 explicit inline geographic(Spheroid const& spheroid)
73 : m_spheroid(spheroid)
76 template <typename CT>
77 static inline CT apply(CT lon1, CT lat1, CT lon2, CT lat2,
78 Spheroid const& spheroid)
80 typedef typename formula::elliptic_arc_length
82 CT, strategy::default_order<FormulaPolicy>::value
83 > elliptic_arc_length;
85 typename elliptic_arc_length::result res =
86 elliptic_arc_length::apply(lon1, lat1, lon2, lat2, spheroid);
93 return FormulaPolicy::template inverse
95 CT, true, false, false, false, false
96 >::apply(lon1, lat1, lon2, lat2, spheroid).distance;
99 template <typename Point1, typename Point2>
100 inline typename calculation_type<Point1, Point2>::type
101 apply(Point1 const& point1, Point2 const& point2) const
103 typedef typename calculation_type<Point1, Point2>::type CT;
105 CT lon1 = get_as_radian<0>(point1);
106 CT lat1 = get_as_radian<1>(point1);
107 CT lon2 = get_as_radian<0>(point2);
108 CT lat2 = get_as_radian<1>(point2);
110 return apply(lon1, lat1, lon2, lat2, m_spheroid);
113 inline Spheroid const& model() const
123 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
129 typename FormulaPolicy,
131 typename CalculationType
133 struct tag<geographic<FormulaPolicy, Spheroid, CalculationType> >
135 typedef strategy_tag_distance_point_point type;
141 typename FormulaPolicy,
143 typename CalculationType,
147 struct return_type<geographic<FormulaPolicy, Spheroid, CalculationType>, P1, P2>
148 : geographic<FormulaPolicy, Spheroid, CalculationType>::template calculation_type<P1, P2>
154 typename FormulaPolicy,
156 typename CalculationType
158 struct comparable_type<geographic<FormulaPolicy, Spheroid, CalculationType> >
160 typedef geographic<FormulaPolicy, Spheroid, CalculationType> type;
166 typename FormulaPolicy,
168 typename CalculationType
170 struct get_comparable<geographic<FormulaPolicy, Spheroid, CalculationType> >
172 static inline geographic<FormulaPolicy, Spheroid, CalculationType>
173 apply(geographic<FormulaPolicy, Spheroid, CalculationType> const& input)
181 typename FormulaPolicy,
183 typename CalculationType,
187 struct result_from_distance<geographic<FormulaPolicy, Spheroid, CalculationType>, P1, P2>
189 template <typename T>
190 static inline typename return_type<geographic<FormulaPolicy, Spheroid, CalculationType>, P1, P2>::type
191 apply(geographic<FormulaPolicy, Spheroid, CalculationType> const& , T const& value)
198 template <typename Point1, typename Point2>
199 struct default_strategy<point_tag, point_tag, Point1, Point2, geographic_tag, geographic_tag>
201 typedef strategy::distance::geographic
206 typename select_coordinate_type<Point1, Point2>::type
212 } // namespace services
213 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
216 }} // namespace strategy::distance
219 }} // namespace boost::geometry
222 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_HPP