1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
8 // This file was modified by Oracle on 2014.
9 // Modifications copyright (c) 2014, Oracle and/or its affiliates.
11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
20 #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP
21 #define BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP
25 #include <boost/mpl/size_t.hpp>
27 #include <boost/range.hpp>
29 #include <boost/variant/apply_visitor.hpp>
30 #include <boost/variant/static_visitor.hpp>
31 #include <boost/variant/variant_fwd.hpp>
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>
38 #include <boost/geometry/algorithms/not_implemented.hpp>
40 #include <boost/geometry/algorithms/detail/counting.hpp>
42 #include <boost/geometry/geometries/concepts/check.hpp>
45 namespace boost { namespace geometry
48 // Silence warning C4127: conditional expression is constant
51 #pragma warning(disable : 4127)
55 #ifndef DOXYGEN_NO_DETAIL
56 namespace detail { namespace num_points
60 template <bool AddForOpen>
63 template <typename Range>
64 static inline std::size_t apply(Range const& range)
66 std::size_t n = boost::size(range);
69 && geometry::closure<Range>::value == open
78 }} // namespace detail::num_points
79 #endif // DOXYGEN_NO_DETAIL
82 #ifndef DOXYGEN_NO_DISPATCH
90 typename Tag = typename tag_cast
92 typename tag<Geometry>::type, multi_tag
95 struct num_points: not_implemented<Tag>
98 template <typename Geometry, bool AddForOpen>
99 struct num_points<Geometry, AddForOpen, point_tag>
100 : detail::counting::other_count<1>
103 template <typename Geometry, bool AddForOpen>
104 struct num_points<Geometry, AddForOpen, box_tag>
105 : detail::counting::other_count<(1 << geometry::dimension<Geometry>::value)>
108 template <typename Geometry, bool AddForOpen>
109 struct num_points<Geometry, AddForOpen, segment_tag>
110 : detail::counting::other_count<2>
113 template <typename Geometry, bool AddForOpen>
114 struct num_points<Geometry, AddForOpen, linestring_tag>
115 : detail::num_points::range_count<AddForOpen>
118 template <typename Geometry, bool AddForOpen>
119 struct num_points<Geometry, AddForOpen, ring_tag>
120 : detail::num_points::range_count<AddForOpen>
123 template <typename Geometry, bool AddForOpen>
124 struct num_points<Geometry, AddForOpen, polygon_tag>
125 : detail::counting::polygon_count
127 detail::num_points::range_count<AddForOpen>
131 template <typename Geometry, bool AddForOpen>
132 struct num_points<Geometry, AddForOpen, multi_tag>
133 : detail::counting::multi_count
135 num_points<typename boost::range_value<Geometry>::type, AddForOpen>
139 } // namespace dispatch
143 namespace resolve_variant
146 template <typename Geometry>
149 static inline std::size_t apply(Geometry const& geometry,
152 concepts::check<Geometry const>();
155 ? dispatch::num_points<Geometry, true>::apply(geometry)
156 : dispatch::num_points<Geometry, false>::apply(geometry);
160 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
161 struct num_points<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
163 struct visitor: boost::static_visitor<std::size_t>
167 visitor(bool add_for_open): m_add_for_open(add_for_open) {}
169 template <typename Geometry>
170 inline std::size_t operator()(Geometry const& geometry) const
172 return num_points<Geometry>::apply(geometry, m_add_for_open);
176 static inline std::size_t
177 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
180 return boost::apply_visitor(visitor(add_for_open), geometry);
184 } // namespace resolve_variant
188 \brief \brief_calc{number of 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}
196 \qbk{[include reference/algorithms/num_points.qbk]}
198 template <typename Geometry>
199 inline std::size_t num_points(Geometry const& geometry, bool add_for_open = false)
201 return resolve_variant::num_points<Geometry>::apply(geometry, add_for_open);
204 #if defined(_MSC_VER)
208 }} // namespace boost::geometry
211 #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP