]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/algorithms/num_segments.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / num_segments.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
20effc67 3// Copyright (c) 2014-2020, Oracle and/or its affiliates.
7c673cae
FG
4
5// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
20effc67 6// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7c673cae
FG
7
8// Licensed under the Boost Software License version 1.0.
9// http://www.boost.org/users/license.html
10
11#ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_SEGMENTS_HPP
12#define BOOST_GEOMETRY_ALGORITHMS_NUM_SEGMENTS_HPP
13
14#include <cstddef>
15
20effc67
TL
16#include <boost/range/size.hpp>
17#include <boost/range/value_type.hpp>
7c673cae
FG
18
19#include <boost/variant/apply_visitor.hpp>
20#include <boost/variant/static_visitor.hpp>
21#include <boost/variant/variant_fwd.hpp>
22
23#include <boost/geometry/core/closure.hpp>
24#include <boost/geometry/core/tag.hpp>
25#include <boost/geometry/core/tags.hpp>
26
27#include <boost/geometry/util/range.hpp>
28
29#include <boost/geometry/geometries/concepts/check.hpp>
30
31#include <boost/geometry/algorithms/not_implemented.hpp>
32
33#include <boost/geometry/algorithms/detail/counting.hpp>
34
35
36namespace boost { namespace geometry
37{
38
39#ifndef DOXYGEN_NO_DETAIL
40namespace detail { namespace num_segments
41{
42
43
44struct range_count
45{
46 template <typename Range>
47 static inline std::size_t apply(Range const& range)
48 {
49 std::size_t n = boost::size(range);
50 if ( n <= 1 )
51 {
52 return 0;
53 }
54
55 return
56 geometry::closure<Range>::value == open
57 ?
58 n
59 :
60 static_cast<std::size_t>(n - 1);
61 }
62};
63
64}} // namespace detail::num_segments
65#endif // DOXYGEN_NO_DETAIL
66
67
68
69#ifndef DOXYGEN_NO_DISPATCH
70namespace dispatch
71{
72
73template <typename Geometry, typename Tag = typename tag<Geometry>::type>
74struct num_segments
75 : not_implemented<Tag>
76{};
77
78template <typename Geometry>
79struct num_segments<Geometry, point_tag>
80 : detail::counting::other_count<0>
81{};
82
83// the number of segments (1-dimensional faces) of the hypercube is
84// given by the formula: d * 2^(d-1), where d is the dimension of the
85// hypercube; see also:
86// http://en.wikipedia.org/wiki/Hypercube
87template <typename Geometry>
88struct num_segments<Geometry, box_tag>
89 : detail::counting::other_count
90 <
91 geometry::dimension<Geometry>::value
92 * (1 << (geometry::dimension<Geometry>::value - 1))
93 >
94{};
95
96template <typename Geometry>
97struct num_segments<Geometry, segment_tag>
98 : detail::counting::other_count<1>
99{};
100
101template <typename Geometry>
102struct num_segments<Geometry, linestring_tag>
103 : detail::num_segments::range_count
104{};
105
106template <typename Geometry>
107struct num_segments<Geometry, ring_tag>
108 : detail::num_segments::range_count
109{};
110
111template <typename Geometry>
112struct num_segments<Geometry, polygon_tag>
113 : detail::counting::polygon_count<detail::num_segments::range_count>
114{};
115
116template <typename Geometry>
117struct num_segments<Geometry, multi_point_tag>
118 : detail::counting::other_count<0>
119{};
120
121template <typename Geometry>
122struct num_segments<Geometry, multi_linestring_tag>
123 : detail::counting::multi_count
124 <
125 num_segments< typename boost::range_value<Geometry>::type>
126 >
127{};
128
129template <typename Geometry>
130struct num_segments<Geometry, multi_polygon_tag>
131 : detail::counting::multi_count
132 <
133 num_segments< typename boost::range_value<Geometry>::type>
134 >
135{};
136
137
138} // namespace dispatch
139#endif // DOXYGEN_NO_DISPATCH
140
141
142
143namespace resolve_variant
144{
145
146
147template <typename Geometry>
148struct num_segments
149{
150 static inline std::size_t apply(Geometry const& geometry)
151 {
152 concepts::check<Geometry const>();
153
154 return dispatch::num_segments<Geometry>::apply(geometry);
155 }
156};
157
158
159template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
160struct num_segments<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
161{
162 struct visitor: boost::static_visitor<std::size_t>
163 {
164 template <typename Geometry>
165 inline std::size_t operator()(Geometry const& geometry) const
166 {
167 return num_segments<Geometry>::apply(geometry);
168 }
169 };
170
171 static inline std::size_t
172 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
173 {
174 return boost::apply_visitor(visitor(), geometry);
175 }
176};
177
178
179} // namespace resolve_variant
180
181
182
183/*!
184\brief \brief_calc{number of segments}
185\ingroup num_segments
186\details \details_calc{num_segments, number of segments}.
187\tparam Geometry \tparam_geometry
188\param geometry \param_geometry
189\return \return_calc{number of segments}
190
191\qbk{[include reference/algorithms/num_segments.qbk]}
192*/
193template <typename Geometry>
194inline std::size_t num_segments(Geometry const& geometry)
195{
196 return resolve_variant::num_segments<Geometry>::apply(geometry);
197}
198
199
200
201}} // namespace boost::geometry
202
203#endif // BOOST_GEOMETRY_ALGORITHMS_NUM_SEGMENTS_HPP