clear.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // This file was modified by Oracle on 2020-2023.
  6. // Modifications copyright (c) 2020-2023, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP
  16. #include <type_traits>
  17. #include <boost/geometry/algorithms/not_implemented.hpp>
  18. #include <boost/geometry/core/exterior_ring.hpp>
  19. #include <boost/geometry/core/interior_rings.hpp>
  20. #include <boost/geometry/core/mutable_range.hpp>
  21. #include <boost/geometry/core/tag_cast.hpp>
  22. #include <boost/geometry/core/tags.hpp>
  23. #include <boost/geometry/core/visit.hpp>
  24. #include <boost/geometry/geometries/adapted/boost_variant.hpp> // for backward compatibility
  25. #include <boost/geometry/geometries/concepts/check.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail { namespace clear
  30. {
  31. template <typename Geometry>
  32. struct collection_clear
  33. {
  34. static inline void apply(Geometry& geometry)
  35. {
  36. traits::clear<Geometry>::apply(geometry);
  37. }
  38. };
  39. template <typename Polygon>
  40. struct polygon_clear
  41. {
  42. static inline void apply(Polygon& polygon)
  43. {
  44. traits::clear
  45. <
  46. typename std::remove_reference
  47. <
  48. typename traits::interior_mutable_type<Polygon>::type
  49. >::type
  50. >::apply(interior_rings(polygon));
  51. traits::clear
  52. <
  53. typename std::remove_reference
  54. <
  55. typename traits::ring_mutable_type<Polygon>::type
  56. >::type
  57. >::apply(exterior_ring(polygon));
  58. }
  59. };
  60. template <typename Geometry>
  61. struct no_action
  62. {
  63. static inline void apply(Geometry& )
  64. {
  65. }
  66. };
  67. }} // namespace detail::clear
  68. #endif // DOXYGEN_NO_DETAIL
  69. #ifndef DOXYGEN_NO_DISPATCH
  70. namespace dispatch
  71. {
  72. template
  73. <
  74. typename Geometry,
  75. typename Tag = typename tag_cast<typename tag<Geometry>::type, multi_tag>::type
  76. >
  77. struct clear: not_implemented<Tag>
  78. {};
  79. // Point/box/segment do not have clear. So specialize to do nothing.
  80. template <typename Geometry>
  81. struct clear<Geometry, point_tag>
  82. : detail::clear::no_action<Geometry>
  83. {};
  84. template <typename Geometry>
  85. struct clear<Geometry, box_tag>
  86. : detail::clear::no_action<Geometry>
  87. {};
  88. template <typename Geometry>
  89. struct clear<Geometry, segment_tag>
  90. : detail::clear::no_action<Geometry>
  91. {};
  92. template <typename Geometry>
  93. struct clear<Geometry, linestring_tag>
  94. : detail::clear::collection_clear<Geometry>
  95. {};
  96. template <typename Geometry>
  97. struct clear<Geometry, ring_tag>
  98. : detail::clear::collection_clear<Geometry>
  99. {};
  100. // Polygon can (indirectly) use std for clear
  101. template <typename Polygon>
  102. struct clear<Polygon, polygon_tag>
  103. : detail::clear::polygon_clear<Polygon>
  104. {};
  105. template <typename Geometry>
  106. struct clear<Geometry, multi_tag>
  107. : detail::clear::collection_clear<Geometry>
  108. {};
  109. template <typename Geometry>
  110. struct clear<Geometry, dynamic_geometry_tag>
  111. {
  112. static void apply(Geometry& geometry)
  113. {
  114. traits::visit<Geometry>::apply([](auto & g)
  115. {
  116. clear<std::remove_reference_t<decltype(g)>>::apply(g);
  117. }, geometry);
  118. }
  119. };
  120. template <typename Geometry>
  121. struct clear<Geometry, geometry_collection_tag>
  122. {
  123. static void apply(Geometry& geometry)
  124. {
  125. traits::clear<Geometry>::apply(geometry);
  126. }
  127. };
  128. } // namespace dispatch
  129. #endif // DOXYGEN_NO_DISPATCH
  130. /*!
  131. \brief Clears a linestring, ring or polygon (exterior+interiors) or multi*
  132. \details Generic function to clear a geometry. All points will be removed from the collection or collections
  133. making up the geometry. In most cases this is equivalent to the .clear() method of a std::vector<...>. In
  134. the case of a polygon, this clear functionality is automatically called for the exterior ring, and for the
  135. interior ring collection. In the case of a point, boxes and segments, nothing will happen.
  136. \ingroup clear
  137. \tparam Geometry \tparam_geometry
  138. \param geometry \param_geometry which will be cleared
  139. \note points and boxes cannot be cleared, instead they can be set to zero by "assign_zero"
  140. \qbk{[include reference/algorithms/clear.qbk]}
  141. */
  142. template <typename Geometry>
  143. inline void clear(Geometry& geometry)
  144. {
  145. concepts::check<Geometry>();
  146. dispatch::clear<Geometry>::apply(geometry);
  147. }
  148. }} // namespace boost::geometry
  149. #endif // BOOST_GEOMETRY_ALGORITHMS_CLEAR_HPP