intersection_box_box.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2015.
  4. // Modifications copyright (c) 2015, 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_OVERLAY_INTERSECTION_BOX_BOX_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP
  11. #include <boost/geometry/core/access.hpp>
  12. #include <boost/geometry/core/coordinate_type.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. #ifndef DOXYGEN_NO_DETAIL
  16. namespace detail { namespace intersection
  17. {
  18. template <std::size_t Dimension, std::size_t DimensionCount>
  19. struct intersection_box_box
  20. {
  21. template
  22. <
  23. typename Box1, typename Box2,
  24. typename RobustPolicy,
  25. typename BoxOut,
  26. typename Strategy
  27. >
  28. static inline bool apply(Box1 const& box1,
  29. Box2 const& box2,
  30. RobustPolicy const& robust_policy,
  31. BoxOut& box_out,
  32. Strategy const& strategy)
  33. {
  34. typedef typename coordinate_type<BoxOut>::type ct;
  35. ct max1 = get<max_corner, Dimension>(box1);
  36. ct min2 = get<min_corner, Dimension>(box2);
  37. if (max1 < min2)
  38. {
  39. return false;
  40. }
  41. ct max2 = get<max_corner, Dimension>(box2);
  42. ct min1 = get<min_corner, Dimension>(box1);
  43. if (max2 < min1)
  44. {
  45. return false;
  46. }
  47. // Set dimensions of output coordinate
  48. set<min_corner, Dimension>(box_out, min1 < min2 ? min2 : min1);
  49. set<max_corner, Dimension>(box_out, max1 > max2 ? max2 : max1);
  50. return intersection_box_box<Dimension + 1, DimensionCount>
  51. ::apply(box1, box2, robust_policy, box_out, strategy);
  52. }
  53. };
  54. template <std::size_t DimensionCount>
  55. struct intersection_box_box<DimensionCount, DimensionCount>
  56. {
  57. template
  58. <
  59. typename Box1, typename Box2,
  60. typename RobustPolicy,
  61. typename BoxOut,
  62. typename Strategy
  63. >
  64. static inline bool apply(Box1 const&, Box2 const&,
  65. RobustPolicy const&, BoxOut&, Strategy const&)
  66. {
  67. return true;
  68. }
  69. };
  70. }} // namespace detail::intersection
  71. #endif // DOXYGEN_NO_DETAIL
  72. }} // namespace boost::geometry
  73. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP