areal_areal.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2013-2022.
  7. // Modifications copyright (c) 2013-2022, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP
  17. #include <boost/geometry/core/point_type.hpp>
  18. #include <boost/geometry/algorithms/detail/covered_by/implementation.hpp>
  19. #include <boost/geometry/algorithms/detail/for_each_range.hpp>
  20. #include <boost/geometry/algorithms/detail/point_on_border.hpp>
  21. #include <boost/geometry/algorithms/detail/disjoint/linear_linear.hpp>
  22. #include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
  23. #include <boost/geometry/geometries/helper_geometry.hpp>
  24. #include <boost/geometry/algorithms/for_each.hpp>
  25. namespace boost { namespace geometry
  26. {
  27. #ifndef DOXYGEN_NO_DETAIL
  28. namespace detail { namespace disjoint
  29. {
  30. template <typename Geometry1, typename Geometry2, typename Strategy>
  31. inline bool point_on_border_covered_by(Geometry1 const& geometry1,
  32. Geometry2 const& geometry2,
  33. Strategy const& strategy)
  34. {
  35. using point_type = typename geometry::point_type<Geometry1>::type;
  36. typename helper_geometry<point_type>::type pt;
  37. return geometry::point_on_border(pt, geometry1)
  38. && geometry::covered_by(pt, geometry2, strategy);
  39. }
  40. /*!
  41. \tparam Strategy point_in_geometry strategy
  42. */
  43. template <typename Geometry1, typename Geometry2, typename Strategy>
  44. inline bool rings_containing(Geometry1 const& geometry1,
  45. Geometry2 const& geometry2,
  46. Strategy const& strategy)
  47. {
  48. return geometry::detail::any_range_of(geometry2, [&](auto const& range)
  49. {
  50. return point_on_border_covered_by(range, geometry1, strategy);
  51. });
  52. }
  53. template <typename Geometry1, typename Geometry2>
  54. struct areal_areal
  55. {
  56. /*!
  57. \tparam Strategy relate (segments intersection) strategy
  58. */
  59. template <typename Strategy>
  60. static inline bool apply(Geometry1 const& geometry1,
  61. Geometry2 const& geometry2,
  62. Strategy const& strategy)
  63. {
  64. if ( ! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy) )
  65. {
  66. return false;
  67. }
  68. // If there is no intersection of segments, they might located
  69. // inside each other
  70. // We check that using a point on the border (external boundary),
  71. // and see if that is contained in the other geometry. And vice versa.
  72. if ( rings_containing(geometry1, geometry2, strategy)
  73. || rings_containing(geometry2, geometry1, strategy) )
  74. {
  75. return false;
  76. }
  77. return true;
  78. }
  79. };
  80. template <typename Areal, typename Box>
  81. struct areal_box
  82. {
  83. /*!
  84. \tparam Strategy relate (segments intersection) strategy
  85. */
  86. template <typename Strategy>
  87. static inline bool apply(Areal const& areal,
  88. Box const& box,
  89. Strategy const& strategy)
  90. {
  91. if (! geometry::all_segments_of(areal, [&](auto const& s)
  92. {
  93. return disjoint_segment_box::apply(s, box, strategy);
  94. }) )
  95. {
  96. return false;
  97. }
  98. // If there is no intersection of any segment and box,
  99. // the box might be located inside areal geometry
  100. if ( point_on_border_covered_by(box, areal, strategy) )
  101. {
  102. return false;
  103. }
  104. return true;
  105. }
  106. };
  107. }} // namespace detail::disjoint
  108. #endif // DOXYGEN_NO_DETAIL
  109. #ifndef DOXYGEN_NO_DISPATCH
  110. namespace dispatch
  111. {
  112. template <typename Areal1, typename Areal2>
  113. struct disjoint<Areal1, Areal2, 2, areal_tag, areal_tag, false>
  114. : detail::disjoint::areal_areal<Areal1, Areal2>
  115. {};
  116. template <typename Areal, typename Box>
  117. struct disjoint<Areal, Box, 2, areal_tag, box_tag, false>
  118. : detail::disjoint::areal_box<Areal, Box>
  119. {};
  120. } // namespace dispatch
  121. #endif // DOXYGEN_NO_DISPATCH
  122. }} // namespace boost::geometry
  123. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP