distance_segment_box.hpp 5.7 KB

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