// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2014, Oracle and/or its affiliates. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_SEGMENTS_HPP #define BOOST_GEOMETRY_ALGORITHMS_NUM_SEGMENTS_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace num_segments { struct range_count { template static inline std::size_t apply(Range const& range) { std::size_t n = boost::size(range); if ( n <= 1 ) { return 0; } return geometry::closure::value == open ? n : static_cast(n - 1); } }; }} // namespace detail::num_segments #endif // DOXYGEN_NO_DETAIL #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { template ::type> struct num_segments : not_implemented {}; template struct num_segments : detail::counting::other_count<0> {}; // the number of segments (1-dimensional faces) of the hypercube is // given by the formula: d * 2^(d-1), where d is the dimension of the // hypercube; see also: // http://en.wikipedia.org/wiki/Hypercube template struct num_segments : detail::counting::other_count < geometry::dimension::value * (1 << (geometry::dimension::value - 1)) > {}; template struct num_segments : detail::counting::other_count<1> {}; template struct num_segments : detail::num_segments::range_count {}; template struct num_segments : detail::num_segments::range_count {}; template struct num_segments : detail::counting::polygon_count {}; template struct num_segments : detail::counting::other_count<0> {}; template struct num_segments : detail::counting::multi_count < num_segments< typename boost::range_value::type> > {}; template struct num_segments : detail::counting::multi_count < num_segments< typename boost::range_value::type> > {}; } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH namespace resolve_variant { template struct num_segments { static inline std::size_t apply(Geometry const& geometry) { concepts::check(); return dispatch::num_segments::apply(geometry); } }; template struct num_segments > { struct visitor: boost::static_visitor { template inline std::size_t operator()(Geometry const& geometry) const { return num_segments::apply(geometry); } }; static inline std::size_t apply(boost::variant const& geometry) { return boost::apply_visitor(visitor(), geometry); } }; } // namespace resolve_variant /*! \brief \brief_calc{number of segments} \ingroup num_segments \details \details_calc{num_segments, number of segments}. \tparam Geometry \tparam_geometry \param geometry \param_geometry \return \return_calc{number of segments} \qbk{[include reference/algorithms/num_segments.qbk]} */ template inline std::size_t num_segments(Geometry const& geometry) { return resolve_variant::num_segments::apply(geometry); } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_SEGMENTS_HPP