distance_cross_track_box_box.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2017-2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_CROSS_TRACK_BOX_BOX_HPP
  9. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_CROSS_TRACK_BOX_BOX_HPP
  10. #include <boost/config.hpp>
  11. #include <boost/concept_check.hpp>
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/assert.hpp>
  14. #include <boost/geometry/core/point_type.hpp>
  15. #include <boost/geometry/core/radian_access.hpp>
  16. #include <boost/geometry/core/tags.hpp>
  17. #include <boost/geometry/strategies/distance.hpp>
  18. #include <boost/geometry/strategies/concepts/distance_concept.hpp>
  19. #include <boost/geometry/strategies/geographic/distance.hpp>
  20. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  21. #include <boost/geometry/strategies/spherical/distance_cross_track.hpp>
  22. #include <boost/geometry/strategies/spherical/distance_cross_track_box_box.hpp>
  23. #include <boost/geometry/util/math.hpp>
  24. #include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
  25. namespace boost { namespace geometry
  26. {
  27. namespace strategy { namespace distance
  28. {
  29. /*!
  30. \brief Strategy functor for distance point to box calculation
  31. \ingroup strategies
  32. \details Class which calculates the distance of a point to a box, for
  33. points and boxes on a sphere or globe
  34. \tparam CalculationType \tparam_calculation
  35. \tparam Strategy underlying point-segment distance strategy, defaults
  36. to cross track
  37. \qbk{
  38. [heading See also]
  39. [link geometry.reference.algorithms.distance.distance_3_with_strategy distance (with strategy)]
  40. }
  41. */
  42. template
  43. <
  44. typename FormulaPolicy = strategy::andoyer,
  45. typename Spheroid = srs::spheroid<double>,
  46. typename CalculationType = void
  47. >
  48. class geographic_cross_track_box_box
  49. {
  50. public:
  51. // point-point strategy getters
  52. struct distance_pp_strategy
  53. {
  54. typedef geographic<FormulaPolicy, Spheroid, CalculationType> type;
  55. };
  56. // point-segment strategy getters
  57. struct distance_ps_strategy
  58. {
  59. typedef geographic_cross_track
  60. <
  61. FormulaPolicy,
  62. Spheroid,
  63. CalculationType
  64. > type;
  65. };
  66. template <typename Box1, typename Box2>
  67. struct return_type : services::return_type
  68. <
  69. typename distance_ps_strategy::type,
  70. typename point_type<Box1>::type,
  71. typename point_type<Box2>::type
  72. >
  73. {};
  74. //constructor
  75. explicit geographic_cross_track_box_box(Spheroid const& spheroid = Spheroid())
  76. : m_spheroid(spheroid)
  77. {}
  78. template <typename Box1, typename Box2>
  79. inline typename return_type<Box1, Box2>::type
  80. apply(Box1 const& box1, Box2 const& box2) const
  81. {
  82. /*
  83. #if !defined(BOOST_MSVC)
  84. BOOST_CONCEPT_ASSERT
  85. (
  86. (concepts::PointSegmentDistanceStrategy
  87. <
  88. Strategy,
  89. typename point_type<Box1>::type,
  90. typename point_type<Box2>::type
  91. >)
  92. );
  93. #endif
  94. */
  95. typedef typename return_type<Box1, Box2>::type return_type;
  96. return details::cross_track_box_box_generic
  97. <return_type>::apply(box1, box2,
  98. typename distance_pp_strategy::type(m_spheroid),
  99. typename distance_ps_strategy::type(m_spheroid));
  100. }
  101. Spheroid model() const
  102. {
  103. return m_spheroid;
  104. }
  105. private :
  106. Spheroid m_spheroid;
  107. };
  108. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  109. namespace services
  110. {
  111. template <typename Strategy, typename Spheroid, typename CalculationType>
  112. struct tag<geographic_cross_track_box_box<Strategy, Spheroid, CalculationType> >
  113. {
  114. typedef strategy_tag_distance_box_box type;
  115. };
  116. template <typename Strategy, typename Spheroid, typename CalculationType, typename Box1, typename Box2>
  117. struct return_type<geographic_cross_track_box_box<Strategy, Spheroid, CalculationType>, Box1, Box2>
  118. : geographic_cross_track_box_box
  119. <
  120. Strategy, Spheroid, CalculationType
  121. >::template return_type<Box1, Box2>
  122. {};
  123. template <typename Strategy, typename Spheroid, typename Box1, typename Box2>
  124. struct return_type<geographic_cross_track_box_box<Strategy, Spheroid>, Box1, Box2>
  125. : geographic_cross_track_box_box
  126. <
  127. Strategy, Spheroid
  128. >::template return_type<Box1, Box2>
  129. {};
  130. template <typename Strategy, typename Box1, typename Box2>
  131. struct return_type<geographic_cross_track_box_box<Strategy>, Box1, Box2>
  132. : geographic_cross_track_box_box
  133. <
  134. Strategy
  135. >::template return_type<Box1, Box2>
  136. {};
  137. template <typename Strategy, typename Spheroid, typename CalculationType>
  138. struct comparable_type<geographic_cross_track_box_box<Strategy, Spheroid, CalculationType> >
  139. {
  140. typedef geographic_cross_track_box_box
  141. <
  142. typename comparable_type<Strategy>::type, Spheroid, CalculationType
  143. > type;
  144. };
  145. template <typename Strategy, typename Spheroid, typename CalculationType>
  146. struct get_comparable<geographic_cross_track_box_box<Strategy, Spheroid, CalculationType> >
  147. {
  148. public:
  149. static inline geographic_cross_track_box_box<Strategy, Spheroid, CalculationType>
  150. apply(geographic_cross_track_box_box<Strategy, Spheroid, CalculationType> const& str)
  151. {
  152. return str;
  153. }
  154. };
  155. template <typename Strategy, typename Spheroid, typename CalculationType, typename Box1, typename Box2>
  156. struct result_from_distance
  157. <
  158. geographic_cross_track_box_box<Strategy, Spheroid, CalculationType>, Box1, Box2
  159. >
  160. {
  161. private:
  162. typedef geographic_cross_track_box_box<Strategy, Spheroid, CalculationType> this_strategy;
  163. typedef typename this_strategy::template return_type
  164. <
  165. Box1, Box2
  166. >::type return_type;
  167. public:
  168. template <typename T>
  169. static inline return_type apply(this_strategy const& strategy,
  170. T const& distance)
  171. {
  172. result_from_distance
  173. <
  174. Strategy,
  175. typename point_type<Box1>::type,
  176. typename point_type<Box2>::type
  177. >::apply(strategy, distance);
  178. }
  179. };
  180. template <typename Box1, typename Box2>
  181. struct default_strategy
  182. <
  183. box_tag, box_tag, Box1, Box2,
  184. geographic_tag, geographic_tag
  185. >
  186. {
  187. typedef geographic_cross_track_box_box<> type;
  188. };
  189. } // namespace services
  190. #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  191. }} // namespace strategy::distance
  192. }} // namespace boost::geometry
  193. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_CROSS_TRACK_BOX_BOX_HPP