annotate DEPENDENCIES/generic/include/boost/geometry/algorithms/num_segments.hpp @ 133:4acb5d8d80b6 tip

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