distance_cross_track_box_box.hpp 7.0 KB

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