distance_segment_box.hpp 8.0 KB

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