distance_segment_box.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2018-2021 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fisikopoulos, 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_SEGMENT_BOX_HPP
  9. #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_SEGMENT_BOX_HPP
  10. #include <boost/geometry/srs/spheroid.hpp>
  11. #include <boost/geometry/core/coordinate_promotion.hpp>
  12. #include <boost/geometry/algorithms/detail/distance/segment_to_box.hpp>
  13. #include <boost/geometry/strategies/distance.hpp>
  14. #include <boost/geometry/strategies/geographic/azimuth.hpp>
  15. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  16. #include <boost/geometry/strategies/geographic/distance_cross_track_point_box.hpp>
  17. #include <boost/geometry/strategies/geographic/parameters.hpp>
  18. #include <boost/geometry/strategies/geographic/side.hpp>
  19. #include <boost/geometry/strategies/normalize.hpp>
  20. #include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
  21. #include <boost/geometry/strategies/spherical/distance_segment_box.hpp>
  22. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  23. #include <boost/geometry/util/select_calculation_type.hpp>
  24. namespace boost { namespace geometry
  25. {
  26. namespace strategy { namespace distance
  27. {
  28. template
  29. <
  30. typename FormulaPolicy = strategy::andoyer,
  31. typename Spheroid = srs::spheroid<double>,
  32. typename CalculationType = void
  33. >
  34. struct geographic_segment_box
  35. {
  36. template <typename PointOfSegment, typename PointOfBox>
  37. struct return_type
  38. : promote_floating_point
  39. <
  40. typename select_calculation_type
  41. <
  42. PointOfSegment,
  43. PointOfBox,
  44. CalculationType
  45. >::type
  46. >
  47. {};
  48. typedef geographic_tag cs_tag;
  49. //constructor
  50. explicit geographic_segment_box(Spheroid const& spheroid = Spheroid())
  51. : m_spheroid(spheroid)
  52. {}
  53. Spheroid model() const
  54. {
  55. return m_spheroid;
  56. }
  57. // methods
  58. template
  59. <
  60. typename LessEqual, typename ReturnType,
  61. typename SegmentPoint, typename BoxPoint,
  62. typename Strategies
  63. >
  64. inline ReturnType segment_below_of_box(SegmentPoint const& p0,
  65. SegmentPoint const& p1,
  66. BoxPoint const& top_left,
  67. BoxPoint const& top_right,
  68. BoxPoint const& bottom_left,
  69. BoxPoint const& bottom_right,
  70. Strategies const& strategies) const
  71. {
  72. return generic_segment_box::segment_below_of_box
  73. <
  74. LessEqual,
  75. ReturnType
  76. >(p0,p1,top_left,top_right,bottom_left,bottom_right,
  77. strategies);
  78. }
  79. template <typename SPoint, typename BPoint>
  80. static void mirror(SPoint& p0,
  81. SPoint& p1,
  82. BPoint& bottom_left,
  83. BPoint& bottom_right,
  84. BPoint& top_left,
  85. BPoint& top_right)
  86. {
  87. generic_segment_box::mirror(p0, p1,
  88. bottom_left, bottom_right,
  89. top_left, top_right);
  90. }
  91. private :
  92. Spheroid m_spheroid;
  93. };
  94. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  95. namespace services
  96. {
  97. //tags
  98. template <typename FormulaPolicy>
  99. struct tag<geographic_segment_box<FormulaPolicy> >
  100. {
  101. typedef strategy_tag_distance_segment_box type;
  102. };
  103. template
  104. <
  105. typename FormulaPolicy,
  106. typename Spheroid
  107. >
  108. struct tag<geographic_segment_box<FormulaPolicy, Spheroid> >
  109. {
  110. typedef strategy_tag_distance_segment_box type;
  111. };
  112. template
  113. <
  114. typename FormulaPolicy,
  115. typename Spheroid,
  116. typename CalculationType
  117. >
  118. struct tag<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> >
  119. {
  120. typedef strategy_tag_distance_segment_box type;
  121. };
  122. // return types
  123. template <typename FormulaPolicy, typename PS, typename PB>
  124. struct return_type<geographic_segment_box<FormulaPolicy>, PS, PB>
  125. : geographic_segment_box<FormulaPolicy>::template return_type<PS, PB>
  126. {};
  127. template
  128. <
  129. typename FormulaPolicy,
  130. typename Spheroid,
  131. typename PS,
  132. typename PB
  133. >
  134. struct return_type<geographic_segment_box<FormulaPolicy, Spheroid>, PS, PB>
  135. : geographic_segment_box<FormulaPolicy, Spheroid>::template return_type<PS, PB>
  136. {};
  137. template
  138. <
  139. typename FormulaPolicy,
  140. typename Spheroid,
  141. typename CalculationType,
  142. typename PS,
  143. typename PB
  144. >
  145. struct return_type<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>, PS, PB>
  146. : geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>::template return_type<PS, PB>
  147. {};
  148. //comparable types
  149. template
  150. <
  151. typename FormulaPolicy,
  152. typename Spheroid,
  153. typename CalculationType
  154. >
  155. struct comparable_type<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> >
  156. {
  157. typedef geographic_segment_box
  158. <
  159. FormulaPolicy, Spheroid, CalculationType
  160. > type;
  161. };
  162. template
  163. <
  164. typename FormulaPolicy,
  165. typename Spheroid,
  166. typename CalculationType
  167. >
  168. struct get_comparable<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> >
  169. {
  170. typedef typename comparable_type
  171. <
  172. geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>
  173. >::type comparable_type;
  174. public :
  175. static inline comparable_type
  176. apply(geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> const& )
  177. {
  178. return comparable_type();
  179. }
  180. };
  181. // result from distance
  182. template
  183. <
  184. typename FormulaPolicy,
  185. typename PS,
  186. typename PB
  187. >
  188. struct result_from_distance<geographic_segment_box<FormulaPolicy>, PS, PB>
  189. {
  190. private :
  191. typedef typename geographic_segment_box
  192. <
  193. FormulaPolicy
  194. >::template return_type<PS, PB>::type return_type;
  195. public :
  196. template <typename T>
  197. static inline return_type
  198. apply(geographic_segment_box<FormulaPolicy> const& , T const& distance)
  199. {
  200. return distance;
  201. }
  202. };
  203. template
  204. <
  205. typename FormulaPolicy,
  206. typename Spheroid,
  207. typename CalculationType,
  208. typename PS,
  209. typename PB
  210. >
  211. struct result_from_distance<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>, PS, PB>
  212. {
  213. private :
  214. typedef typename geographic_segment_box
  215. <
  216. FormulaPolicy, Spheroid, CalculationType
  217. >::template return_type<PS, PB>::type return_type;
  218. public :
  219. template <typename T>
  220. static inline return_type
  221. apply(geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> const& , T const& distance)
  222. {
  223. return distance;
  224. }
  225. };
  226. // default strategies
  227. template <typename Segment, typename Box>
  228. struct default_strategy
  229. <
  230. segment_tag, box_tag, Segment, Box,
  231. geographic_tag, geographic_tag
  232. >
  233. {
  234. typedef geographic_segment_box<> type;
  235. };
  236. template <typename Box, typename Segment>
  237. struct default_strategy
  238. <
  239. box_tag, segment_tag, Box, Segment,
  240. geographic_tag, geographic_tag
  241. >
  242. {
  243. typedef typename default_strategy
  244. <
  245. segment_tag, box_tag, Segment, Box,
  246. geographic_tag, geographic_tag
  247. >::type type;
  248. };
  249. }
  250. #endif
  251. }} // namespace strategy::distance
  252. }} // namespace boost::geometry
  253. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_SEGMENT_BOX_HPP