distance_segment_box.hpp 6.1 KB

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