File indexing completed on 2025-12-15 09:50:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP
0013 #define BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP
0014
0015 #include <boost/range/begin.hpp>
0016 #include <boost/range/empty.hpp>
0017 #include <boost/range/end.hpp>
0018
0019 #include <boost/geometry/algorithms/not_implemented.hpp>
0020 #include <boost/geometry/algorithms/detail/visit.hpp>
0021
0022 #include <boost/geometry/core/exterior_ring.hpp>
0023 #include <boost/geometry/core/interior_rings.hpp>
0024 #include <boost/geometry/core/tag.hpp>
0025 #include <boost/geometry/core/tags.hpp>
0026 #include <boost/geometry/core/visit.hpp>
0027
0028 #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
0029 #include <boost/geometry/geometries/concepts/check.hpp>
0030
0031 #include <boost/geometry/util/type_traits_std.hpp>
0032
0033 namespace boost { namespace geometry
0034 {
0035
0036
0037 #ifndef DOXYGEN_NO_DETAIL
0038 namespace detail { namespace is_empty
0039 {
0040
0041 struct always_not_empty
0042 {
0043 template <typename Geometry>
0044 static inline bool apply(Geometry const&)
0045 {
0046 return false;
0047 }
0048 };
0049
0050 struct range_is_empty
0051 {
0052 template <typename Range>
0053 static inline bool apply(Range const& range)
0054 {
0055 return boost::empty(range);
0056 }
0057 };
0058
0059 class polygon_is_empty
0060 {
0061 template <typename InteriorRings>
0062 static inline bool check_interior_rings(InteriorRings const& interior_rings)
0063 {
0064 return std::all_of(boost::begin(interior_rings), boost::end(interior_rings),
0065 []( auto const& range ){ return boost::empty(range); });
0066 }
0067
0068 public:
0069 template <typename Polygon>
0070 static inline bool apply(Polygon const& polygon)
0071 {
0072 return boost::empty(exterior_ring(polygon))
0073 && check_interior_rings(interior_rings(polygon));
0074 }
0075 };
0076
0077 template <typename Policy = range_is_empty>
0078 struct multi_is_empty
0079 {
0080 template <typename MultiGeometry>
0081 static inline bool apply(MultiGeometry const& multigeometry)
0082 {
0083 return std::all_of(boost::begin(multigeometry),
0084 boost::end(multigeometry),
0085 []( auto const& range ){ return Policy::apply(range); });
0086 }
0087 };
0088
0089 }}
0090 #endif
0091
0092
0093 #ifndef DOXYGEN_NO_DISPATCH
0094 namespace dispatch
0095 {
0096
0097 template <typename Geometry, typename Tag = tag_t<Geometry>>
0098 struct is_empty : not_implemented<Tag>
0099 {};
0100
0101 template <typename Geometry>
0102 struct is_empty<Geometry, point_tag>
0103 : detail::is_empty::always_not_empty
0104 {};
0105
0106 template <typename Geometry>
0107 struct is_empty<Geometry, box_tag>
0108 : detail::is_empty::always_not_empty
0109 {};
0110
0111 template <typename Geometry>
0112 struct is_empty<Geometry, segment_tag>
0113 : detail::is_empty::always_not_empty
0114 {};
0115
0116 template <typename Geometry>
0117 struct is_empty<Geometry, linestring_tag>
0118 : detail::is_empty::range_is_empty
0119 {};
0120
0121 template <typename Geometry>
0122 struct is_empty<Geometry, ring_tag>
0123 : detail::is_empty::range_is_empty
0124 {};
0125
0126 template <typename Geometry>
0127 struct is_empty<Geometry, polygon_tag>
0128 : detail::is_empty::polygon_is_empty
0129 {};
0130
0131 template <typename Geometry>
0132 struct is_empty<Geometry, multi_point_tag>
0133 : detail::is_empty::range_is_empty
0134 {};
0135
0136 template <typename Geometry>
0137 struct is_empty<Geometry, multi_linestring_tag>
0138 : detail::is_empty::multi_is_empty<>
0139 {};
0140
0141 template <typename Geometry>
0142 struct is_empty<Geometry, multi_polygon_tag>
0143 : detail::is_empty::multi_is_empty<detail::is_empty::polygon_is_empty>
0144 {};
0145
0146 }
0147 #endif
0148
0149
0150 namespace resolve_dynamic
0151 {
0152
0153 template <typename Geometry, typename Tag = tag_t<Geometry>>
0154 struct is_empty
0155 {
0156 static inline bool apply(Geometry const& geometry)
0157 {
0158 concepts::check<Geometry const>();
0159
0160 return dispatch::is_empty<Geometry>::apply(geometry);
0161 }
0162 };
0163
0164 template <typename Geometry>
0165 struct is_empty<Geometry, dynamic_geometry_tag>
0166 {
0167 static inline bool apply(Geometry const& geometry)
0168 {
0169 bool result = true;
0170 traits::visit<Geometry>::apply([&](auto const& g)
0171 {
0172 result = is_empty<util::remove_cref_t<decltype(g)>>::apply(g);
0173 }, geometry);
0174 return result;
0175 }
0176 };
0177
0178 template <typename Geometry>
0179 struct is_empty<Geometry, geometry_collection_tag>
0180 {
0181 static inline bool apply(Geometry const& geometry)
0182 {
0183 bool result = true;
0184 detail::visit_breadth_first([&](auto const& g)
0185 {
0186 result = is_empty<util::remove_cref_t<decltype(g)>>::apply(g);
0187 return result;
0188 }, geometry);
0189 return result;
0190 }
0191 };
0192
0193 }
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 template <typename Geometry>
0206 inline bool is_empty(Geometry const& geometry)
0207 {
0208 return resolve_dynamic::is_empty<Geometry>::apply(geometry);
0209 }
0210
0211
0212 }}
0213
0214
0215 #endif