File indexing completed on 2025-12-16 09:51:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GEOMETRY_STRATEGIES_DISTANCE_SPHERICAL_HPP
0011 #define BOOST_GEOMETRY_STRATEGIES_DISTANCE_SPHERICAL_HPP
0012
0013
0014 #include <boost/geometry/strategies/distance/comparable.hpp>
0015 #include <boost/geometry/strategies/distance/detail.hpp>
0016 #include <boost/geometry/strategies/distance/services.hpp>
0017 #include <boost/geometry/strategies/detail.hpp>
0018
0019 #include <boost/geometry/strategies/normalize.hpp>
0020 #include <boost/geometry/strategies/relate/spherical.hpp>
0021
0022 #include <boost/geometry/strategies/spherical/azimuth.hpp>
0023
0024 #include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
0025 #include <boost/geometry/strategies/spherical/distance_cross_track_box_box.hpp>
0026 #include <boost/geometry/strategies/spherical/distance_cross_track_point_box.hpp>
0027 #include <boost/geometry/strategies/spherical/distance_haversine.hpp>
0028 #include <boost/geometry/strategies/spherical/distance_segment_box.hpp>
0029
0030
0031 namespace boost { namespace geometry
0032 {
0033
0034 namespace strategies { namespace distance
0035 {
0036
0037 #ifndef DOXYGEN_NO_DETAIL
0038 namespace detail
0039 {
0040
0041
0042
0043
0044 template <typename RadiusTypeOrSphere, typename CalculationType>
0045 class spherical
0046 : public strategies::relate::detail::spherical<RadiusTypeOrSphere, CalculationType>
0047 {
0048 using base_t = strategies::relate::detail::spherical<RadiusTypeOrSphere, CalculationType>;
0049
0050 public:
0051 spherical() = default;
0052
0053 template <typename RadiusOrSphere>
0054 explicit spherical(RadiusOrSphere const& radius_or_sphere)
0055 : base_t(radius_or_sphere)
0056 {}
0057
0058
0059
0060 static auto azimuth()
0061 {
0062 return strategy::azimuth::spherical<CalculationType>();
0063 }
0064
0065
0066
0067 template <typename Geometry1, typename Geometry2>
0068 auto distance(Geometry1 const&, Geometry2 const&,
0069 detail::enable_if_pp_t<Geometry1, Geometry2> * = nullptr) const
0070 {
0071 return strategy::distance::haversine
0072 <
0073 typename base_t::radius_type, CalculationType
0074 >(base_t::radius());
0075 }
0076
0077 template <typename Geometry1, typename Geometry2>
0078 auto distance(Geometry1 const&, Geometry2 const&,
0079 detail::enable_if_ps_t<Geometry1, Geometry2> * = nullptr) const
0080 {
0081 return strategy::distance::cross_track
0082 <
0083 CalculationType,
0084 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
0085 >(base_t::radius());
0086 }
0087
0088 template <typename Geometry1, typename Geometry2>
0089 auto distance(Geometry1 const&, Geometry2 const&,
0090 detail::enable_if_pb_t<Geometry1, Geometry2> * = nullptr) const
0091 {
0092 return strategy::distance::cross_track_point_box
0093 <
0094 CalculationType,
0095 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
0096 >(base_t::radius());
0097 }
0098
0099 template <typename Geometry1, typename Geometry2>
0100 auto distance(Geometry1 const&, Geometry2 const&,
0101 detail::enable_if_sb_t<Geometry1, Geometry2> * = nullptr) const
0102 {
0103 return strategy::distance::spherical_segment_box
0104 <
0105 CalculationType,
0106 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
0107 >(base_t::radius());
0108 }
0109
0110 template <typename Geometry1, typename Geometry2>
0111 auto distance(Geometry1 const&, Geometry2 const&,
0112 detail::enable_if_bb_t<Geometry1, Geometry2> * = nullptr) const
0113 {
0114 return strategy::distance::cross_track_box_box
0115 <
0116 CalculationType,
0117 strategy::distance::haversine<typename base_t::radius_type, CalculationType>
0118 >(base_t::radius());
0119 }
0120
0121
0122
0123 template <typename Geometry>
0124 static auto normalize(Geometry const&,
0125 std::enable_if_t
0126 <
0127 util::is_point<Geometry>::value
0128 > * = nullptr)
0129 {
0130 return strategy::normalize::spherical_point();
0131 }
0132 };
0133
0134
0135 }
0136 #endif
0137
0138
0139 template
0140 <
0141 typename RadiusTypeOrSphere = double,
0142 typename CalculationType = void
0143 >
0144 class spherical
0145 : public strategies::distance::detail::spherical<RadiusTypeOrSphere, CalculationType>
0146 {
0147 using base_t = strategies::distance::detail::spherical<RadiusTypeOrSphere, CalculationType>;
0148
0149 public:
0150 spherical() = default;
0151
0152 template <typename RadiusOrSphere>
0153 explicit spherical(RadiusOrSphere const& radius_or_sphere)
0154 : base_t(radius_or_sphere)
0155 {}
0156 };
0157
0158
0159 namespace services
0160 {
0161
0162 template <typename Geometry1, typename Geometry2>
0163 struct default_strategy
0164 <
0165 Geometry1, Geometry2,
0166 spherical_equatorial_tag, spherical_equatorial_tag
0167 >
0168 {
0169 using type = strategies::distance::spherical<>;
0170 };
0171
0172
0173 template <typename R, typename CT>
0174 struct strategy_converter<strategy::distance::haversine<R, CT> >
0175 {
0176 template <typename S>
0177 static auto get(S const& s)
0178 {
0179 return strategies::distance::spherical<R, CT>(s.radius());
0180 }
0181 };
0182
0183 template <typename CT, typename PPS>
0184 struct strategy_converter<strategy::distance::cross_track<CT, PPS> >
0185 : strategy_converter<PPS>
0186 {};
0187
0188 template <typename CT, typename PPS>
0189 struct strategy_converter<strategy::distance::cross_track_point_box<CT, PPS> >
0190 : strategy_converter<PPS>
0191 {};
0192
0193 template <typename CT, typename PPS>
0194 struct strategy_converter<strategy::distance::spherical_segment_box<CT, PPS> >
0195 : strategy_converter<PPS>
0196 {};
0197
0198 template <typename CT, typename PPS>
0199 struct strategy_converter<strategy::distance::cross_track_box_box<CT, PPS> >
0200 : strategy_converter<PPS>
0201 {};
0202
0203
0204 template <typename R, typename CT>
0205 struct strategy_converter<strategy::distance::comparable::haversine<R, CT> >
0206 {
0207 template <typename S>
0208 static auto get(S const& s)
0209 {
0210 return strategies::distance::detail::make_comparable(
0211 strategies::distance::spherical<R, CT>(s.radius()));
0212 }
0213 };
0214
0215 template <typename CT, typename PPS>
0216 struct strategy_converter<strategy::distance::comparable::cross_track<CT, PPS> >
0217 : strategy_converter<PPS>
0218 {};
0219
0220
0221 }
0222
0223 }}
0224
0225 }}
0226
0227 #endif