areal.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
  9. #include <boost/range/begin.hpp>
  10. #include <boost/range/empty.hpp>
  11. #include <boost/range/end.hpp>
  12. #include <boost/range/value_type.hpp>
  13. #include <boost/geometry/core/closure.hpp>
  14. #include <boost/geometry/core/exterior_ring.hpp>
  15. #include <boost/geometry/core/interior_rings.hpp>
  16. #include <boost/geometry/core/ring_type.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #include <boost/geometry/algorithms/detail/is_simple/failure_policy.hpp>
  19. #include <boost/geometry/algorithms/detail/is_valid/has_duplicates.hpp>
  20. #include <boost/geometry/algorithms/dispatch/is_simple.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. #ifndef DOXYGEN_NO_DETAIL
  24. namespace detail { namespace is_simple
  25. {
  26. template <typename Ring, typename Strategy>
  27. inline bool is_simple_ring(Ring const& ring, Strategy const& strategy)
  28. {
  29. simplicity_failure_policy policy;
  30. return ! boost::empty(ring)
  31. && ! detail::is_valid::has_duplicates<Ring>::apply(ring, policy, strategy);
  32. }
  33. template <typename InteriorRings, typename Strategy>
  34. inline bool are_simple_interior_rings(InteriorRings const& interior_rings,
  35. Strategy const& strategy)
  36. {
  37. return std::all_of(boost::begin(interior_rings),
  38. boost::end(interior_rings),
  39. [&](auto const& r)
  40. {
  41. return is_simple_ring(r, strategy);
  42. }); // non-simple ring not found
  43. // allow empty ring
  44. }
  45. template <typename Polygon, typename Strategy>
  46. inline bool is_simple_polygon(Polygon const& polygon, Strategy const& strategy)
  47. {
  48. return is_simple_ring(geometry::exterior_ring(polygon), strategy)
  49. && are_simple_interior_rings(geometry::interior_rings(polygon), strategy);
  50. }
  51. }} // namespace detail::is_simple
  52. #endif // DOXYGEN_NO_DETAIL
  53. #ifndef DOXYGEN_NO_DISPATCH
  54. namespace dispatch
  55. {
  56. // A Ring is a Polygon.
  57. // A Polygon is always a simple geometric object provided that it is valid.
  58. //
  59. // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1)
  60. template <typename Ring>
  61. struct is_simple<Ring, ring_tag>
  62. {
  63. template <typename Strategy>
  64. static inline bool apply(Ring const& ring, Strategy const& strategy)
  65. {
  66. return detail::is_simple::is_simple_ring(ring, strategy);
  67. }
  68. };
  69. // A Polygon is always a simple geometric object provided that it is valid.
  70. //
  71. // Reference (for validity of Polygons): OGC 06-103r4 (6.1.11.1)
  72. template <typename Polygon>
  73. struct is_simple<Polygon, polygon_tag>
  74. {
  75. template <typename Strategy>
  76. static inline bool apply(Polygon const& polygon, Strategy const& strategy)
  77. {
  78. return detail::is_simple::is_simple_polygon(polygon, strategy);
  79. }
  80. };
  81. // Not clear what the definition is.
  82. // Right now we consider a MultiPolygon as simple if it is valid.
  83. //
  84. // Reference (for validity of MultiPolygons): OGC 06-103r4 (6.1.14)
  85. template <typename MultiPolygon>
  86. struct is_simple<MultiPolygon, multi_polygon_tag>
  87. {
  88. template <typename Strategy>
  89. static inline bool apply(MultiPolygon const& multipolygon, Strategy const& strategy)
  90. {
  91. return std::none_of(boost::begin(multipolygon), boost::end(multipolygon),
  92. [&](auto const& po) {
  93. return ! detail::is_simple::is_simple_polygon(po, strategy);
  94. }); // non-simple polygon not found
  95. // allow empty multi-polygon
  96. }
  97. };
  98. } // namespace dispatch
  99. #endif // DOXYGEN_NO_DISPATCH
  100. }} // namespace boost::geometry
  101. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP