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