distance_cross_track_point_box.hpp 6.6 KB

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