]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/num_points.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / num_points.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
7
8 // This file was modified by Oracle on 2014-2021.
9 // Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
20
21 #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP
22 #define BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP
23
24 #include <cstddef>
25
26 #include <boost/range/size.hpp>
27 #include <boost/range/value_type.hpp>
28
29 #include <boost/geometry/algorithms/detail/counting.hpp>
30 #include <boost/geometry/algorithms/detail/visit.hpp>
31 #include <boost/geometry/algorithms/not_implemented.hpp>
32
33 #include <boost/geometry/core/closure.hpp>
34 #include <boost/geometry/core/coordinate_dimension.hpp>
35 #include <boost/geometry/core/tag_cast.hpp>
36 #include <boost/geometry/core/tags.hpp>
37 #include <boost/geometry/core/visit.hpp>
38
39 #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
40 #include <boost/geometry/geometries/concepts/check.hpp>
41
42 #include <boost/geometry/util/type_traits_std.hpp>
43
44 namespace boost { namespace geometry
45 {
46
47 // Silence warning C4127: conditional expression is constant
48 #if defined(_MSC_VER)
49 #pragma warning(push)
50 #pragma warning(disable : 4127)
51 #endif
52
53
54 #ifndef DOXYGEN_NO_DETAIL
55 namespace detail { namespace num_points
56 {
57
58
59 template <bool AddForOpen>
60 struct range_count
61 {
62 template <typename Range>
63 static inline std::size_t apply(Range const& range)
64 {
65 std::size_t n = boost::size(range);
66 if (AddForOpen
67 && n > 0
68 && geometry::closure<Range>::value == open
69 )
70 {
71 return n + 1;
72 }
73 return n;
74 }
75 };
76
77 }} // namespace detail::num_points
78 #endif // DOXYGEN_NO_DETAIL
79
80
81 #ifndef DOXYGEN_NO_DISPATCH
82 namespace dispatch
83 {
84
85 template
86 <
87 typename Geometry,
88 bool AddForOpen,
89 typename Tag = typename tag_cast
90 <
91 typename tag<Geometry>::type, multi_tag
92 >::type
93 >
94 struct num_points: not_implemented<Tag>
95 {};
96
97 template <typename Geometry, bool AddForOpen>
98 struct num_points<Geometry, AddForOpen, point_tag>
99 : detail::counting::other_count<1>
100 {};
101
102 template <typename Geometry, bool AddForOpen>
103 struct num_points<Geometry, AddForOpen, box_tag>
104 : detail::counting::other_count<(1 << geometry::dimension<Geometry>::value)>
105 {};
106
107 template <typename Geometry, bool AddForOpen>
108 struct num_points<Geometry, AddForOpen, segment_tag>
109 : detail::counting::other_count<2>
110 {};
111
112 template <typename Geometry, bool AddForOpen>
113 struct num_points<Geometry, AddForOpen, linestring_tag>
114 : detail::num_points::range_count<AddForOpen>
115 {};
116
117 template <typename Geometry, bool AddForOpen>
118 struct num_points<Geometry, AddForOpen, ring_tag>
119 : detail::num_points::range_count<AddForOpen>
120 {};
121
122 template <typename Geometry, bool AddForOpen>
123 struct num_points<Geometry, AddForOpen, polygon_tag>
124 : detail::counting::polygon_count
125 <
126 detail::num_points::range_count<AddForOpen>
127 >
128 {};
129
130 template <typename Geometry, bool AddForOpen>
131 struct num_points<Geometry, AddForOpen, multi_tag>
132 : detail::counting::multi_count
133 <
134 num_points<typename boost::range_value<Geometry>::type, AddForOpen>
135 >
136 {};
137
138 } // namespace dispatch
139 #endif
140
141
142 namespace resolve_dynamic
143 {
144
145 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
146 struct num_points
147 {
148 static inline std::size_t apply(Geometry const& geometry, bool add_for_open)
149 {
150 concepts::check<Geometry const>();
151
152 return add_for_open
153 ? dispatch::num_points<Geometry, true>::apply(geometry)
154 : dispatch::num_points<Geometry, false>::apply(geometry);
155 }
156 };
157
158 template <typename Geometry>
159 struct num_points<Geometry, dynamic_geometry_tag>
160 {
161 static inline std::size_t apply(Geometry const& geometry, bool add_for_open)
162 {
163 std::size_t result = 0;
164 traits::visit<Geometry>::apply([&](auto const& g)
165 {
166 result = num_points<util::remove_cref_t<decltype(g)>>::apply(g, add_for_open);
167 }, geometry);
168 return result;
169 }
170 };
171
172
173 template <typename Geometry>
174 struct num_points<Geometry, geometry_collection_tag>
175 {
176 static inline std::size_t apply(Geometry const& geometry, bool add_for_open)
177 {
178 std::size_t result = 0;
179 detail::visit_breadth_first([&](auto const& g)
180 {
181 result += num_points<util::remove_cref_t<decltype(g)>>::apply(g, add_for_open);
182 return true;
183 }, geometry);
184 return result;
185 }
186 };
187
188
189 } // namespace resolve_dynamic
190
191
192 /*!
193 \brief \brief_calc{number of points}
194 \ingroup num_points
195 \details \details_calc{num_points, number of points}.
196 \tparam Geometry \tparam_geometry
197 \param geometry \param_geometry
198 \param add_for_open add one for open geometries (i.e. polygon types which are not closed)
199 \return \return_calc{number of points}
200
201 \qbk{[include reference/algorithms/num_points.qbk]}
202 */
203 template <typename Geometry>
204 inline std::size_t num_points(Geometry const& geometry, bool add_for_open = false)
205 {
206 return resolve_dynamic::num_points<Geometry>::apply(geometry, add_for_open);
207 }
208
209 #if defined(_MSC_VER)
210 #pragma warning(pop)
211 #endif
212
213 }} // namespace boost::geometry
214
215
216 #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP