distance_cross_track_point_box.hpp 6.6 KB

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