distance_segment_box.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_CARTESIAN_DISTANCE_SEGMENT_BOX_HPP
  9. #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_SEGMENT_BOX_HPP
  10. #include <boost/geometry/algorithms/detail/distance/segment_to_box.hpp>
  11. #include <boost/geometry/strategies/cartesian/distance_projected_point.hpp>
  12. #include <boost/geometry/strategies/cartesian/distance_pythagoras.hpp>
  13. #include <boost/geometry/strategies/cartesian/distance_pythagoras_point_box.hpp>
  14. #include <boost/geometry/strategies/cartesian/point_in_point.hpp>
  15. #include <boost/geometry/strategies/cartesian/side_by_triangle.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. namespace strategy { namespace distance
  19. {
  20. template
  21. <
  22. typename CalculationType = void,
  23. typename Strategy = pythagoras<CalculationType>
  24. >
  25. struct cartesian_segment_box
  26. {
  27. template <typename PointOfSegment, typename PointOfBox>
  28. struct calculation_type
  29. : promote_floating_point
  30. <
  31. typename strategy::distance::services::return_type
  32. <
  33. Strategy,
  34. PointOfSegment,
  35. PointOfBox
  36. >::type
  37. >
  38. {};
  39. typedef cartesian_tag cs_tag;
  40. // point-point strategy getters
  41. struct distance_pp_strategy
  42. {
  43. typedef Strategy type;
  44. };
  45. inline typename distance_pp_strategy::type get_distance_pp_strategy() const
  46. {
  47. return typename distance_pp_strategy::type();
  48. }
  49. // point-segment strategy getters
  50. struct distance_ps_strategy
  51. {
  52. typedef projected_point<CalculationType, Strategy> type;
  53. };
  54. inline typename distance_ps_strategy::type get_distance_ps_strategy() const
  55. {
  56. return typename distance_ps_strategy::type();
  57. }
  58. struct distance_pb_strategy
  59. {
  60. typedef pythagoras_point_box<CalculationType> type;
  61. };
  62. inline typename distance_pb_strategy::type get_distance_pb_strategy() const
  63. {
  64. return typename distance_pb_strategy::type();
  65. }
  66. typedef side::side_by_triangle<CalculationType> side_strategy_type;
  67. static inline side_strategy_type get_side_strategy()
  68. {
  69. return side_strategy_type();
  70. }
  71. typedef within::cartesian_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. template <typename LessEqual, typename ReturnType,
  77. typename SegmentPoint, typename BoxPoint>
  78. inline ReturnType segment_below_of_box(SegmentPoint const& p0,
  79. SegmentPoint const& p1,
  80. BoxPoint const&,
  81. BoxPoint const&,
  82. BoxPoint const&,
  83. BoxPoint const& bottom_right) const
  84. {
  85. return geometry::detail::distance::segment_to_box_2D
  86. <
  87. ReturnType,
  88. SegmentPoint,
  89. BoxPoint,
  90. cartesian_segment_box<CalculationType, Strategy>
  91. >::template call_above_of_box
  92. <
  93. typename LessEqual::other
  94. >(p1, p0, bottom_right, *this);
  95. }
  96. template <typename SPoint, typename BPoint>
  97. static void mirror(SPoint&,
  98. SPoint&,
  99. BPoint&,
  100. BPoint&,
  101. BPoint&,
  102. BPoint&)
  103. {}
  104. };
  105. #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
  106. namespace services
  107. {
  108. template <typename CalculationType, typename Strategy>
  109. struct tag<cartesian_segment_box<CalculationType, Strategy> >
  110. {
  111. typedef strategy_tag_distance_segment_box type;
  112. };
  113. template <typename CalculationType, typename Strategy, typename PS, typename PB>
  114. struct return_type<cartesian_segment_box<CalculationType, Strategy>, PS, PB>
  115. : cartesian_segment_box<CalculationType, Strategy>::template calculation_type<PS, PB>
  116. {};
  117. template <typename CalculationType, typename Strategy>
  118. struct comparable_type<cartesian_segment_box<CalculationType, Strategy> >
  119. {
  120. // Define a cartesian_segment_box strategy with its underlying point-point
  121. // strategy being comparable
  122. typedef cartesian_segment_box
  123. <
  124. CalculationType,
  125. typename comparable_type<Strategy>::type
  126. > type;
  127. };
  128. template <typename CalculationType, typename Strategy>
  129. struct get_comparable<cartesian_segment_box<CalculationType, Strategy> >
  130. {
  131. typedef typename comparable_type
  132. <
  133. cartesian_segment_box<CalculationType, Strategy>
  134. >::type comparable_type;
  135. public :
  136. static inline comparable_type apply(cartesian_segment_box<CalculationType, Strategy> const& )
  137. {
  138. return comparable_type();
  139. }
  140. };
  141. template <typename CalculationType, typename Strategy, typename PS, typename PB>
  142. struct result_from_distance<cartesian_segment_box<CalculationType, Strategy>, PS, PB>
  143. {
  144. private :
  145. typedef typename return_type<
  146. cartesian_segment_box
  147. <
  148. CalculationType,
  149. Strategy
  150. >,
  151. PS,
  152. PB
  153. >::type return_type;
  154. public :
  155. template <typename T>
  156. static inline return_type apply(cartesian_segment_box<CalculationType,
  157. Strategy> const& ,
  158. T const& value)
  159. {
  160. Strategy s;
  161. return result_from_distance<Strategy, PS, PB>::apply(s, value);
  162. }
  163. };
  164. template <typename Segment, typename Box>
  165. struct default_strategy
  166. <
  167. segment_tag, box_tag, Segment, Box,
  168. cartesian_tag, cartesian_tag
  169. >
  170. {
  171. typedef cartesian_segment_box<> type;
  172. };
  173. template <typename Box, typename Segment>
  174. struct default_strategy
  175. <
  176. box_tag, segment_tag, Box, Segment,
  177. cartesian_tag, cartesian_tag
  178. >
  179. {
  180. typedef typename default_strategy
  181. <
  182. segment_tag, box_tag, Segment, Box,
  183. cartesian_tag, cartesian_tag
  184. >::type type;
  185. };
  186. }
  187. #endif
  188. }} // namespace strategy::distance
  189. }} // namespace boost::geometry
  190. #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_DISTANCE_SEGMENT_BOX_HPP