Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:21

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2014-2021.
0009 // Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0012 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0013 
0014 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0015 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0016 
0017 // Use, modification and distribution is subject to the Boost Software License,
0018 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0019 // http://www.boost.org/LICENSE_1_0.txt)
0020 
0021 #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP
0022 #define BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP
0023 
0024 #include <cstddef>
0025 
0026 #include <boost/range/size.hpp>
0027 #include <boost/range/value_type.hpp>
0028 
0029 #include <boost/geometry/algorithms/detail/counting.hpp>
0030 #include <boost/geometry/algorithms/detail/visit.hpp>
0031 #include <boost/geometry/algorithms/not_implemented.hpp>
0032 
0033 #include <boost/geometry/core/closure.hpp>
0034 #include <boost/geometry/core/coordinate_dimension.hpp>
0035 #include <boost/geometry/core/tag_cast.hpp>
0036 #include <boost/geometry/core/tags.hpp>
0037 #include <boost/geometry/core/visit.hpp>
0038 
0039 #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
0040 #include <boost/geometry/geometries/concepts/check.hpp>
0041 
0042 #include <boost/geometry/util/type_traits_std.hpp>
0043 
0044 namespace boost { namespace geometry
0045 {
0046 
0047 // Silence warning C4127: conditional expression is constant
0048 #if defined(_MSC_VER)
0049 #pragma warning(push)
0050 #pragma warning(disable : 4127)
0051 #endif
0052 
0053 
0054 #ifndef DOXYGEN_NO_DETAIL
0055 namespace detail { namespace num_points
0056 {
0057 
0058 
0059 template <bool AddForOpen>
0060 struct range_count
0061 {
0062     template <typename Range>
0063     static inline std::size_t apply(Range const& range)
0064     {
0065         std::size_t n = boost::size(range);
0066         if (AddForOpen
0067             && n > 0
0068             && geometry::closure<Range>::value == open
0069             )
0070         {
0071             return n + 1;
0072         }
0073         return n;
0074     }
0075 };
0076 
0077 }} // namespace detail::num_points
0078 #endif // DOXYGEN_NO_DETAIL
0079 
0080 
0081 #ifndef DOXYGEN_NO_DISPATCH
0082 namespace dispatch
0083 {
0084 
0085 template
0086 <
0087     typename Geometry,
0088     bool AddForOpen,
0089     typename Tag = typename tag_cast
0090         <
0091             typename tag<Geometry>::type, multi_tag
0092         >::type
0093 >
0094 struct num_points: not_implemented<Tag>
0095 {};
0096 
0097 template <typename Geometry, bool AddForOpen>
0098 struct num_points<Geometry, AddForOpen, point_tag>
0099     : detail::counting::other_count<1>
0100 {};
0101 
0102 template <typename Geometry, bool AddForOpen>
0103 struct num_points<Geometry, AddForOpen, box_tag>
0104     : detail::counting::other_count<(1 << geometry::dimension<Geometry>::value)>
0105 {};
0106 
0107 template <typename Geometry, bool AddForOpen>
0108 struct num_points<Geometry, AddForOpen, segment_tag>
0109     : detail::counting::other_count<2>
0110 {};
0111 
0112 template <typename Geometry, bool AddForOpen>
0113 struct num_points<Geometry, AddForOpen, linestring_tag>
0114     : detail::num_points::range_count<AddForOpen>
0115 {};
0116 
0117 template <typename Geometry, bool AddForOpen>
0118 struct num_points<Geometry, AddForOpen, ring_tag>
0119     : detail::num_points::range_count<AddForOpen>
0120 {};
0121 
0122 template <typename Geometry, bool AddForOpen>
0123 struct num_points<Geometry, AddForOpen, polygon_tag>
0124     : detail::counting::polygon_count
0125         <
0126             detail::num_points::range_count<AddForOpen>
0127         >
0128 {};
0129 
0130 template <typename Geometry, bool AddForOpen>
0131 struct num_points<Geometry, AddForOpen, multi_tag>
0132     : detail::counting::multi_count
0133         <
0134             num_points<typename boost::range_value<Geometry>::type, AddForOpen>
0135         >
0136 {};
0137 
0138 } // namespace dispatch
0139 #endif
0140 
0141 
0142 namespace resolve_dynamic
0143 {
0144 
0145 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
0146 struct num_points
0147 {
0148     static inline std::size_t apply(Geometry const& geometry, bool add_for_open)
0149     {
0150         concepts::check<Geometry const>();
0151 
0152         return add_for_open
0153              ? dispatch::num_points<Geometry, true>::apply(geometry)
0154              : dispatch::num_points<Geometry, false>::apply(geometry);
0155     }
0156 };
0157 
0158 template <typename Geometry>
0159 struct num_points<Geometry, dynamic_geometry_tag>
0160 {
0161     static inline std::size_t apply(Geometry const& geometry, bool add_for_open)
0162     {
0163         std::size_t result = 0;
0164         traits::visit<Geometry>::apply([&](auto const& g)
0165         {
0166             result = num_points<util::remove_cref_t<decltype(g)>>::apply(g, add_for_open);
0167         }, geometry);
0168         return result;
0169     }
0170 };
0171 
0172 
0173 template <typename Geometry>
0174 struct num_points<Geometry, geometry_collection_tag>
0175 {
0176     static inline std::size_t apply(Geometry const& geometry, bool add_for_open)
0177     {
0178         std::size_t result = 0;
0179         detail::visit_breadth_first([&](auto const& g)
0180         {
0181             result += num_points<util::remove_cref_t<decltype(g)>>::apply(g, add_for_open);
0182             return true;
0183         }, geometry);
0184         return result;
0185     }
0186 };
0187 
0188 
0189 } // namespace resolve_dynamic
0190 
0191 
0192 /*!
0193 \brief \brief_calc{number of points}
0194 \ingroup num_points
0195 \details \details_calc{num_points, number of points}.
0196 \tparam Geometry \tparam_geometry
0197 \param geometry \param_geometry
0198 \param add_for_open add one for open geometries (i.e. polygon types which are not closed)
0199 \return \return_calc{number of points}
0200 
0201 \qbk{[include reference/algorithms/num_points.qbk]}
0202 */
0203 template <typename Geometry>
0204 inline std::size_t num_points(Geometry const& geometry, bool add_for_open = false)
0205 {
0206     return resolve_dynamic::num_points<Geometry>::apply(geometry, add_for_open);
0207 }
0208 
0209 #if defined(_MSC_VER)
0210 #pragma warning(pop)
0211 #endif
0212 
0213 }} // namespace boost::geometry
0214 
0215 
0216 #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP