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