intersection_content.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Boost.Geometry Index
  2. //
  3. // boxes union/intersection area/volume
  4. //
  5. // Copyright (c) 2011-2018 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2019.
  8. // Modifications copyright (c) 2019 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
  16. #include <boost/geometry/algorithms/detail/disjoint/box_box.hpp>
  17. #include <boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp>
  18. #include <boost/geometry/index/detail/algorithms/content.hpp>
  19. namespace boost { namespace geometry { namespace index { namespace detail {
  20. // Util to distinguish between default and non-default index strategy
  21. template <typename Box, typename Strategy>
  22. inline bool disjoint_box_box(Box const& box1, Box const& box2, Strategy const&)
  23. {
  24. return geometry::detail::disjoint::disjoint_box_box(box1, box2,
  25. typename Strategy::disjoint_box_box_strategy_type());
  26. }
  27. template <typename Box>
  28. inline bool disjoint_box_box(Box const& box1, Box const& box2, default_strategy const& )
  29. {
  30. typedef typename strategy::disjoint::services::default_strategy<Box, Box>::type strategy_type;
  31. return geometry::detail::disjoint::disjoint_box_box(box1, box2, strategy_type());
  32. }
  33. /**
  34. * \brief Compute the area, volume, ... of the intersection of b1 and b2
  35. */
  36. template <typename Box, typename Strategy>
  37. inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2, Strategy const& strategy)
  38. {
  39. bool const intersects = ! index::detail::disjoint_box_box(box1, box2, strategy);
  40. // NOTE: the code below may be inconsistent with the disjoint_box_box()
  41. // however intersection_box_box checks if the boxes intersect on the fly so it should be ok
  42. // but this also means that disjoint_box_box() is probably not needed
  43. if ( intersects )
  44. {
  45. Box box_intersection;
  46. bool const ok = geometry::detail::intersection::intersection_box_box
  47. <
  48. 0, geometry::dimension<Box>::value
  49. >::apply(box1, box2, 0, box_intersection, 0);
  50. if ( ok )
  51. {
  52. return index::detail::content(box_intersection);
  53. }
  54. }
  55. return 0;
  56. }
  57. template <typename Box>
  58. inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2)
  59. {
  60. return intersection_content(box1, box2, default_strategy());
  61. }
  62. }}}} // namespace boost::geometry::index::detail
  63. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP