clear.hpp 5.2 KB

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