distance_segment_box.hpp 9.1 KB

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