distance_segment_box.hpp 5.6 KB

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