section_functions.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2015-2021.
  4. // Modifications copyright (c) 2015-2021, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
  11. #include <boost/geometry/core/access.hpp>
  12. #include <boost/geometry/core/coordinate_type.hpp>
  13. #include <boost/geometry/algorithms/detail/recalculate.hpp>
  14. #include <boost/geometry/policies/robustness/robust_point_type.hpp>
  15. // For spherical/geographic longitudes covered_by point/box
  16. #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
  17. #include <boost/geometry/util/select_coordinate_type.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace section
  22. {
  23. // TODO: This code is CS-specific, should be moved to strategies
  24. template
  25. <
  26. std::size_t Dimension,
  27. typename Geometry,
  28. typename CastedCSTag = typename tag_cast
  29. <
  30. typename cs_tag<Geometry>::type,
  31. spherical_tag
  32. >::type
  33. >
  34. struct preceding_check
  35. {
  36. template <typename Point, typename Box>
  37. static inline bool apply(int dir, Point const& point, Box const& /*point_box*/, Box const& other_box)
  38. {
  39. return (dir == 1 && get<Dimension>(point) < get<min_corner, Dimension>(other_box))
  40. || (dir == -1 && get<Dimension>(point) > get<max_corner, Dimension>(other_box));
  41. }
  42. };
  43. template <typename Geometry>
  44. struct preceding_check<0, Geometry, spherical_tag>
  45. {
  46. template <typename Point, typename Box>
  47. static inline bool apply(int dir, Point const& point, Box const& point_box, Box const& other_box)
  48. {
  49. typedef typename select_coordinate_type
  50. <
  51. Point, Box
  52. >::type calc_t;
  53. typedef typename coordinate_system<Point>::type::units units_t;
  54. calc_t const c0 = 0;
  55. calc_t const value = get<0>(point);
  56. calc_t const other_min = get<min_corner, 0>(other_box);
  57. calc_t const other_max = get<max_corner, 0>(other_box);
  58. bool const pt_covered = strategy::within::detail::covered_by_range
  59. <
  60. Point, 0, spherical_tag
  61. >::apply(value,
  62. other_min,
  63. other_max);
  64. if (pt_covered)
  65. {
  66. return false;
  67. }
  68. if (dir == 1)
  69. {
  70. calc_t const diff_min = math::longitude_distance_signed
  71. <
  72. units_t, calc_t
  73. >(other_min, value);
  74. calc_t const diff_min_min = math::longitude_distance_signed
  75. <
  76. units_t, calc_t
  77. >(other_min, get<min_corner, 0>(point_box));
  78. return diff_min < c0 && diff_min_min <= c0 && diff_min_min <= diff_min;
  79. }
  80. else if (dir == -1)
  81. {
  82. calc_t const diff_max = math::longitude_distance_signed
  83. <
  84. units_t, calc_t
  85. >(other_max, value);
  86. calc_t const diff_max_max = math::longitude_distance_signed
  87. <
  88. units_t, calc_t
  89. >(other_max, get<max_corner, 0>(point_box));
  90. return diff_max > c0 && diff_max_max >= c0 && diff_max <= diff_max_max;
  91. }
  92. return false;
  93. }
  94. };
  95. template
  96. <
  97. std::size_t Dimension,
  98. typename Point,
  99. typename Box,
  100. typename RobustPolicy
  101. >
  102. inline bool preceding(int dir,
  103. Point const& point,
  104. Box const& point_box,
  105. Box const& other_box,
  106. RobustPolicy const& robust_policy)
  107. {
  108. using box_point_type = typename geometry::point_type<Box>::type;
  109. typename geometry::robust_point_type<box_point_type, RobustPolicy>::type robust_point;
  110. geometry::recalculate(robust_point, point, robust_policy);
  111. // After recalculate() to prevent warning: 'robust_point' may be used uninitialized
  112. assert_coordinate_type_equal(robust_point, point_box);
  113. return preceding_check<Dimension, Box>::apply(dir, robust_point,
  114. point_box,
  115. other_box);
  116. }
  117. template
  118. <
  119. std::size_t Dimension,
  120. typename Point,
  121. typename Box,
  122. typename RobustPolicy
  123. >
  124. inline bool exceeding(int dir,
  125. Point const& point,
  126. Box const& point_box,
  127. Box const& other_box,
  128. RobustPolicy const& robust_policy)
  129. {
  130. return preceding<Dimension>(-dir, point, point_box, other_box, robust_policy);
  131. }
  132. }} // namespace detail::section
  133. #endif
  134. }} // namespace boost::geometry
  135. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP