distance_segment_box.hpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2018-2019 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/algorithms/detail/distance/segment_to_box.hpp>
  12. #include <boost/geometry/strategies/distance.hpp>
  13. #include <boost/geometry/strategies/geographic/azimuth.hpp>
  14. #include <boost/geometry/strategies/geographic/distance_cross_track.hpp>
  15. #include <boost/geometry/strategies/geographic/parameters.hpp>
  16. #include <boost/geometry/strategies/geographic/side.hpp>
  17. #include <boost/geometry/strategies/normalize.hpp>
  18. #include <boost/geometry/strategies/spherical/disjoint_box_box.hpp>
  19. #include <boost/geometry/strategies/spherical/distance_segment_box.hpp>
  20. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  21. #include <boost/geometry/util/promote_floating_point.hpp>
  22. #include <boost/geometry/util/select_calculation_type.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. namespace strategy { namespace distance
  26. {
  27. template
  28. <
  29. typename FormulaPolicy = strategy::andoyer,
  30. typename Spheroid = srs::spheroid<double>,
  31. typename CalculationType = void
  32. >
  33. struct geographic_segment_box
  34. {
  35. template <typename PointOfSegment, typename PointOfBox>
  36. struct return_type
  37. : promote_floating_point
  38. <
  39. typename select_calculation_type
  40. <
  41. PointOfSegment,
  42. PointOfBox,
  43. CalculationType
  44. >::type
  45. >
  46. {};
  47. typedef geographic_tag cs_tag;
  48. // point-point strategy getters
  49. struct distance_pp_strategy
  50. {
  51. typedef geographic<FormulaPolicy, Spheroid, CalculationType> type;
  52. };
  53. inline typename distance_pp_strategy::type get_distance_pp_strategy() const
  54. {
  55. typedef typename distance_pp_strategy::type distance_type;
  56. return distance_type(m_spheroid);
  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. inline typename distance_ps_strategy::type get_distance_ps_strategy() const
  69. {
  70. typedef typename distance_ps_strategy::type distance_type;
  71. return distance_type(m_spheroid);
  72. }
  73. struct distance_pb_strategy
  74. {
  75. typedef geographic_cross_track_point_box
  76. <
  77. FormulaPolicy,
  78. Spheroid,
  79. CalculationType
  80. > type;
  81. };
  82. inline typename distance_pb_strategy::type get_distance_pb_strategy() const
  83. {
  84. return typename distance_pb_strategy::type(m_spheroid);
  85. }
  86. typedef side::geographic
  87. <
  88. FormulaPolicy,
  89. Spheroid,
  90. CalculationType
  91. > side_strategy_type;
  92. inline side_strategy_type get_side_strategy() const
  93. {
  94. return side_strategy_type(m_spheroid);
  95. }
  96. typedef within::spherical_point_point equals_point_point_strategy_type;
  97. static inline equals_point_point_strategy_type get_equals_point_point_strategy()
  98. {
  99. return equals_point_point_strategy_type();
  100. }
  101. //constructor
  102. explicit geographic_segment_box(Spheroid const& spheroid = Spheroid())
  103. : m_spheroid(spheroid)
  104. {}
  105. // methods
  106. template <typename LessEqual, typename ReturnType,
  107. typename SegmentPoint, typename BoxPoint>
  108. inline ReturnType segment_below_of_box(SegmentPoint const& p0,
  109. SegmentPoint const& p1,
  110. BoxPoint const& top_left,
  111. BoxPoint const& top_right,
  112. BoxPoint const& bottom_left,
  113. BoxPoint const& bottom_right) const
  114. {
  115. typedef typename azimuth::geographic
  116. <
  117. FormulaPolicy,
  118. Spheroid,
  119. CalculationType
  120. > azimuth_strategy_type;
  121. azimuth_strategy_type az_strategy(m_spheroid);
  122. typedef typename envelope::geographic_segment
  123. <
  124. FormulaPolicy,
  125. Spheroid,
  126. CalculationType
  127. > envelope_segment_strategy_type;
  128. envelope_segment_strategy_type es_strategy(m_spheroid);
  129. return generic_segment_box::segment_below_of_box
  130. <
  131. LessEqual,
  132. ReturnType
  133. >(p0,p1,top_left,top_right,bottom_left,bottom_right,
  134. geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>(),
  135. az_strategy, es_strategy,
  136. normalize::spherical_point(),
  137. covered_by::spherical_point_box(),
  138. disjoint::spherical_box_box());
  139. }
  140. template <typename SPoint, typename BPoint>
  141. static void mirror(SPoint& p0,
  142. SPoint& p1,
  143. BPoint& bottom_left,
  144. BPoint& bottom_right,
  145. BPoint& top_left,
  146. BPoint& top_right)
  147. {
  148. generic_segment_box::mirror(p0, p1,
  149. bottom_left, bottom_right,
  150. top_left, top_right);
  151. }
  152. private :
  153. Spheroid m_spheroid;
  154. };
  155. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  156. namespace services
  157. {
  158. //tags
  159. template <typename FormulaPolicy>
  160. struct tag<geographic_segment_box<FormulaPolicy> >
  161. {
  162. typedef strategy_tag_distance_segment_box type;
  163. };
  164. template
  165. <
  166. typename FormulaPolicy,
  167. typename Spheroid
  168. >
  169. struct tag<geographic_segment_box<FormulaPolicy, Spheroid> >
  170. {
  171. typedef strategy_tag_distance_segment_box type;
  172. };
  173. template
  174. <
  175. typename FormulaPolicy,
  176. typename Spheroid,
  177. typename CalculationType
  178. >
  179. struct tag<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> >
  180. {
  181. typedef strategy_tag_distance_segment_box type;
  182. };
  183. // return types
  184. template <typename FormulaPolicy, typename PS, typename PB>
  185. struct return_type<geographic_segment_box<FormulaPolicy>, PS, PB>
  186. : geographic_segment_box<FormulaPolicy>::template return_type<PS, PB>
  187. {};
  188. template
  189. <
  190. typename FormulaPolicy,
  191. typename Spheroid,
  192. typename PS,
  193. typename PB
  194. >
  195. struct return_type<geographic_segment_box<FormulaPolicy, Spheroid>, PS, PB>
  196. : geographic_segment_box<FormulaPolicy, Spheroid>::template return_type<PS, PB>
  197. {};
  198. template
  199. <
  200. typename FormulaPolicy,
  201. typename Spheroid,
  202. typename CalculationType,
  203. typename PS,
  204. typename PB
  205. >
  206. struct return_type<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>, PS, PB>
  207. : geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>::template return_type<PS, PB>
  208. {};
  209. //comparable types
  210. template
  211. <
  212. typename FormulaPolicy,
  213. typename Spheroid,
  214. typename CalculationType
  215. >
  216. struct comparable_type<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> >
  217. {
  218. typedef geographic_segment_box
  219. <
  220. FormulaPolicy, Spheroid, CalculationType
  221. > type;
  222. };
  223. template
  224. <
  225. typename FormulaPolicy,
  226. typename Spheroid,
  227. typename CalculationType
  228. >
  229. struct get_comparable<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> >
  230. {
  231. typedef typename comparable_type
  232. <
  233. geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>
  234. >::type comparable_type;
  235. public :
  236. static inline comparable_type
  237. apply(geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> const& )
  238. {
  239. return comparable_type();
  240. }
  241. };
  242. // result from distance
  243. template
  244. <
  245. typename FormulaPolicy,
  246. typename PS,
  247. typename PB
  248. >
  249. struct result_from_distance<geographic_segment_box<FormulaPolicy>, PS, PB>
  250. {
  251. private :
  252. typedef typename geographic_segment_box
  253. <
  254. FormulaPolicy
  255. >::template return_type<PS, PB>::type return_type;
  256. public :
  257. template <typename T>
  258. static inline return_type
  259. apply(geographic_segment_box<FormulaPolicy> const& , T const& distance)
  260. {
  261. return distance;
  262. }
  263. };
  264. template
  265. <
  266. typename FormulaPolicy,
  267. typename Spheroid,
  268. typename CalculationType,
  269. typename PS,
  270. typename PB
  271. >
  272. struct result_from_distance<geographic_segment_box<FormulaPolicy, Spheroid, CalculationType>, PS, PB>
  273. {
  274. private :
  275. typedef typename geographic_segment_box
  276. <
  277. FormulaPolicy, Spheroid, CalculationType
  278. >::template return_type<PS, PB>::type return_type;
  279. public :
  280. template <typename T>
  281. static inline return_type
  282. apply(geographic_segment_box<FormulaPolicy, Spheroid, CalculationType> const& , T const& distance)
  283. {
  284. return distance;
  285. }
  286. };
  287. // default strategies
  288. template <typename Segment, typename Box>
  289. struct default_strategy
  290. <
  291. segment_tag, box_tag, Segment, Box,
  292. geographic_tag, geographic_tag
  293. >
  294. {
  295. typedef geographic_segment_box<> type;
  296. };
  297. template <typename Box, typename Segment>
  298. struct default_strategy
  299. <
  300. box_tag, segment_tag, Box, Segment,
  301. geographic_tag, geographic_tag
  302. >
  303. {
  304. typedef typename default_strategy
  305. <
  306. segment_tag, box_tag, Segment, Box,
  307. geographic_tag, geographic_tag
  308. >::type type;
  309. };
  310. }
  311. #endif
  312. }} // namespace strategy::distance
  313. }} // namespace boost::geometry
  314. #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_DISTANCE_SEGMENT_BOX_HPP