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