section_functions.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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, 2017, 2018.
  4. // Modifications copyright (c) 2015-2018, 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/algorithms/detail/recalculate.hpp>
  13. #include <boost/geometry/policies/robustness/robust_point_type.hpp>
  14. // For spherical/geographic longitudes covered_by point/box
  15. #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
  16. #include <boost/geometry/util/select_coordinate_type.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail { namespace section
  21. {
  22. // TODO: This code is CS-specific, should be moved to strategies
  23. template
  24. <
  25. std::size_t Dimension,
  26. typename Geometry,
  27. typename CastedCSTag = typename tag_cast
  28. <
  29. typename cs_tag<Geometry>::type,
  30. spherical_tag
  31. >::type
  32. >
  33. struct preceding_check
  34. {
  35. template <typename Point, typename Box>
  36. static inline bool apply(int dir, Point const& point, Box const& /*point_box*/, Box const& other_box)
  37. {
  38. return (dir == 1 && get<Dimension>(point) < get<min_corner, Dimension>(other_box))
  39. || (dir == -1 && get<Dimension>(point) > get<max_corner, Dimension>(other_box));
  40. }
  41. };
  42. template <typename Geometry>
  43. struct preceding_check<0, Geometry, spherical_tag>
  44. {
  45. template <typename Point, typename Box>
  46. static inline bool apply(int dir, Point const& point, Box const& point_box, Box const& other_box)
  47. {
  48. typedef typename select_coordinate_type
  49. <
  50. Point, Box
  51. >::type calc_t;
  52. typedef typename coordinate_system<Point>::type::units units_t;
  53. calc_t const c0 = 0;
  54. calc_t const value = get<0>(point);
  55. calc_t const other_min = get<min_corner, 0>(other_box);
  56. calc_t const other_max = get<max_corner, 0>(other_box);
  57. bool const pt_covered = strategy::within::detail::covered_by_range
  58. <
  59. Point, 0, spherical_tag
  60. >::apply(value,
  61. other_min,
  62. other_max);
  63. if (pt_covered)
  64. {
  65. return false;
  66. }
  67. if (dir == 1)
  68. {
  69. calc_t const diff_min = math::longitude_distance_signed
  70. <
  71. units_t, calc_t
  72. >(other_min, value);
  73. calc_t const diff_min_min = math::longitude_distance_signed
  74. <
  75. units_t, calc_t
  76. >(other_min, get<min_corner, 0>(point_box));
  77. return diff_min < c0 && diff_min_min <= c0 && diff_min_min <= diff_min;
  78. }
  79. else if (dir == -1)
  80. {
  81. calc_t const diff_max = math::longitude_distance_signed
  82. <
  83. units_t, calc_t
  84. >(other_max, value);
  85. calc_t const diff_max_max = math::longitude_distance_signed
  86. <
  87. units_t, calc_t
  88. >(other_max, get<max_corner, 0>(point_box));
  89. return diff_max > c0 && diff_max_max >= c0 && diff_max <= diff_max_max;
  90. }
  91. return false;
  92. }
  93. };
  94. template
  95. <
  96. std::size_t Dimension,
  97. typename Point,
  98. typename RobustBox,
  99. typename RobustPolicy
  100. >
  101. static inline bool preceding(int dir,
  102. Point const& point,
  103. RobustBox const& point_robust_box,
  104. RobustBox const& other_robust_box,
  105. RobustPolicy const& robust_policy)
  106. {
  107. typename geometry::robust_point_type<Point, RobustPolicy>::type robust_point;
  108. geometry::recalculate(robust_point, point, robust_policy);
  109. return preceding_check<Dimension, Point>::apply(dir, robust_point, point_robust_box, other_robust_box);
  110. }
  111. template
  112. <
  113. std::size_t Dimension,
  114. typename Point,
  115. typename RobustBox,
  116. typename RobustPolicy
  117. >
  118. static inline bool exceeding(int dir,
  119. Point const& point,
  120. RobustBox const& point_robust_box,
  121. RobustBox const& other_robust_box,
  122. RobustPolicy const& robust_policy)
  123. {
  124. return preceding<Dimension>(-dir, point, point_robust_box, other_robust_box, robust_policy);
  125. }
  126. }} // namespace detail::section
  127. #endif
  128. }} // namespace boost::geometry
  129. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP