box_box_implementation.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_INTERSECTION_BOX_BOX_IMPLEMENTATION_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_BOX_BOX_IMPLEMENTATION_HPP
  11. #include <boost/geometry/core/access.hpp>
  12. namespace boost { namespace geometry
  13. {
  14. #ifndef DOXYGEN_NO_DETAIL
  15. namespace detail { namespace intersection
  16. {
  17. template <std::size_t Dimension, std::size_t DimensionCount>
  18. struct intersection_box_box
  19. {
  20. template
  21. <
  22. typename Box1, typename Box2,
  23. typename RobustPolicy,
  24. typename BoxOut,
  25. typename Strategy
  26. >
  27. static inline bool apply(Box1 const& box1,
  28. Box2 const& box2,
  29. RobustPolicy const& robust_policy,
  30. BoxOut& box_out,
  31. Strategy const& strategy)
  32. {
  33. auto max1 = get<max_corner, Dimension>(box1);
  34. auto min2 = get<min_corner, Dimension>(box2);
  35. if (max1 < min2)
  36. {
  37. return false;
  38. }
  39. auto max2 = get<max_corner, Dimension>(box2);
  40. auto min1 = get<min_corner, Dimension>(box1);
  41. if (max2 < min1)
  42. {
  43. return false;
  44. }
  45. // Set dimensions of output coordinate
  46. set<min_corner, Dimension>(box_out, min1 < min2 ? min2 : min1);
  47. set<max_corner, Dimension>(box_out, max1 > max2 ? max2 : max1);
  48. return intersection_box_box<Dimension + 1, DimensionCount>
  49. ::apply(box1, box2, robust_policy, box_out, strategy);
  50. }
  51. };
  52. template <std::size_t DimensionCount>
  53. struct intersection_box_box<DimensionCount, DimensionCount>
  54. {
  55. template
  56. <
  57. typename Box1, typename Box2,
  58. typename RobustPolicy,
  59. typename BoxOut,
  60. typename Strategy
  61. >
  62. static inline bool apply(Box1 const&, Box2 const&,
  63. RobustPolicy const&, BoxOut&, Strategy const&)
  64. {
  65. return true;
  66. }
  67. };
  68. }} // namespace detail::intersection
  69. #endif // DOXYGEN_NO_DETAIL
  70. }} // namespace boost::geometry
  71. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_BOX_BOX_IMPLEMENTATION_HPP