clear.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2024 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2020-2023.
  7. // Modifications copyright (c) 2020-2023, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  9. // Contributed and/or modified by Adam Wulkiewicz, 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_CLEAR_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
  17. #include <type_traits>
  18. #include <boost/geometry/algorithms/not_implemented.hpp>
  19. #include <boost/geometry/core/exterior_ring.hpp>
  20. #include <boost/geometry/core/interior_rings.hpp>
  21. #include <boost/geometry/core/mutable_range.hpp>
  22. #include <boost/geometry/core/tag_cast.hpp>
  23. #include <boost/geometry/core/tags.hpp>
  24. #include <boost/geometry/core/visit.hpp>
  25. #include <boost/geometry/geometries/adapted/boost_variant.hpp> // for backward compatibility
  26. #include <boost/geometry/geometries/concepts/check.hpp>
  27. namespace boost { namespace geometry
  28. {
  29. #ifndef DOXYGEN_NO_DETAIL
  30. namespace detail { namespace clear
  31. {
  32. template <typename Geometry>
  33. struct collection_clear
  34. {
  35. static inline void apply(Geometry& geometry)
  36. {
  37. traits::clear<Geometry>::apply(geometry);
  38. }
  39. };
  40. template <typename Polygon>
  41. struct polygon_clear
  42. {
  43. static inline void apply(Polygon& polygon)
  44. {
  45. traits::clear
  46. <
  47. std::remove_reference_t
  48. <
  49. typename traits::interior_mutable_type<Polygon>::type
  50. >
  51. >::apply(interior_rings(polygon));
  52. traits::clear
  53. <
  54. std::remove_reference_t
  55. <
  56. typename traits::ring_mutable_type<Polygon>::type
  57. >
  58. >::apply(exterior_ring(polygon));
  59. }
  60. };
  61. template <typename PolyhedralSurface>
  62. struct polyhedral_surface_clear
  63. {
  64. static inline void apply(PolyhedralSurface& polyhedral_surface)
  65. {
  66. traits::clear
  67. <
  68. typename std::remove_reference<PolyhedralSurface>::type
  69. >::apply(polyhedral_surface);
  70. }
  71. };
  72. template <typename Geometry>
  73. struct no_action
  74. {
  75. static inline void apply(Geometry& )
  76. {
  77. }
  78. };
  79. }} // namespace detail::clear
  80. #endif // DOXYGEN_NO_DETAIL
  81. #ifndef DOXYGEN_NO_DISPATCH
  82. namespace dispatch
  83. {
  84. template
  85. <
  86. typename Geometry,
  87. typename Tag = tag_cast_t<tag_t<Geometry>, multi_tag>
  88. >
  89. struct clear: not_implemented<Tag>
  90. {};
  91. // Point/box/segment do not have clear. So specialize to do nothing.
  92. template <typename Geometry>
  93. struct clear<Geometry, point_tag>
  94. : detail::clear::no_action<Geometry>
  95. {};
  96. template <typename Geometry>
  97. struct clear<Geometry, box_tag>
  98. : detail::clear::no_action<Geometry>
  99. {};
  100. template <typename Geometry>
  101. struct clear<Geometry, segment_tag>
  102. : detail::clear::no_action<Geometry>
  103. {};
  104. template <typename Geometry>
  105. struct clear<Geometry, linestring_tag>
  106. : detail::clear::collection_clear<Geometry>
  107. {};
  108. template <typename Geometry>
  109. struct clear<Geometry, ring_tag>
  110. : detail::clear::collection_clear<Geometry>
  111. {};
  112. // Clear for Polyhedral surface
  113. template <typename Geometry>
  114. struct clear<Geometry, polyhedral_surface_tag>
  115. : detail::clear::polyhedral_surface_clear<Geometry>
  116. {};
  117. // Polygon can (indirectly) use std for clear
  118. template <typename Polygon>
  119. struct clear<Polygon, polygon_tag>
  120. : detail::clear::polygon_clear<Polygon>
  121. {};
  122. template <typename Geometry>
  123. struct clear<Geometry, multi_tag>
  124. : detail::clear::collection_clear<Geometry>
  125. {};
  126. template <typename Geometry>
  127. struct clear<Geometry, dynamic_geometry_tag>
  128. {
  129. static void apply(Geometry& geometry)
  130. {
  131. traits::visit<Geometry>::apply([](auto & g)
  132. {
  133. clear<std::remove_reference_t<decltype(g)>>::apply(g);
  134. }, geometry);
  135. }
  136. };
  137. template <typename Geometry>
  138. struct clear<Geometry, geometry_collection_tag>
  139. {
  140. static void apply(Geometry& geometry)
  141. {
  142. traits::clear<Geometry>::apply(geometry);
  143. }
  144. };
  145. } // namespace dispatch
  146. #endif // DOXYGEN_NO_DISPATCH
  147. /*!
  148. \brief Clears a linestring, ring or polygon (exterior+interiors) or multi*
  149. \details Generic function to clear a geometry. All points will be removed from the collection or collections
  150. making up the geometry. In most cases this is equivalent to the .clear() method of a std::vector<...>. In
  151. the case of a polygon, this clear functionality is automatically called for the exterior ring, and for the
  152. interior ring collection. In the case of a point, boxes and segments, nothing will happen.
  153. \ingroup clear
  154. \tparam Geometry \tparam_geometry
  155. \param geometry \param_geometry which will be cleared
  156. \note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
  157. \qbk{[include reference/algorithms/clear.qbk]}
  158. */
  159. template <typename Geometry>
  160. inline void clear(Geometry& geometry)
  161. {
  162. concepts::check<Geometry>();
  163. dispatch::clear<Geometry>::apply(geometry);
  164. }
  165. }} // namespace boost::geometry
  166. #endif // BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP