Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@101: // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands. Chris@101: // Copyright (c) 2008-2014 Bruno Lalande, Paris, France. Chris@101: // Copyright (c) 2009-2014 Mateusz Loskot, London, UK. Chris@101: // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. Chris@101: Chris@101: // This file was modified by Oracle on 2014. Chris@101: // Modifications copyright (c) 2014, Oracle and/or its affiliates. Chris@101: Chris@101: // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle Chris@16: Chris@16: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@16: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP Chris@16: #define BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP Chris@16: Chris@16: #include Chris@16: Chris@101: #include Chris@101: Chris@16: #include Chris@101: Chris@101: #include Chris@101: #include Chris@101: #include Chris@16: Chris@16: #include Chris@101: #include Chris@16: #include Chris@101: #include Chris@101: Chris@16: #include Chris@101: Chris@101: #include Chris@101: Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: // Silence warning C4127: conditional expression is constant Chris@16: #if defined(_MSC_VER) Chris@101: #pragma warning(push) Chris@16: #pragma warning(disable : 4127) Chris@16: #endif Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_DETAIL Chris@16: namespace detail { namespace num_points Chris@16: { Chris@16: Chris@16: Chris@101: template Chris@16: struct range_count Chris@16: { Chris@16: template Chris@101: static inline std::size_t apply(Range const& range) Chris@16: { Chris@16: std::size_t n = boost::size(range); Chris@101: if (AddForOpen Chris@101: && n > 0 Chris@101: && geometry::closure::value == open Chris@101: ) Chris@16: { Chris@101: return n + 1; Chris@16: } Chris@16: return n; Chris@16: } Chris@16: }; Chris@16: Chris@16: }} // namespace detail::num_points Chris@16: #endif // DOXYGEN_NO_DETAIL Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_DISPATCH Chris@16: namespace dispatch Chris@16: { Chris@16: Chris@16: template Chris@16: < Chris@16: typename Geometry, Chris@101: bool AddForOpen, Chris@101: typename Tag = typename tag_cast Chris@101: < Chris@101: typename tag::type, multi_tag Chris@101: >::type Chris@16: > Chris@16: struct num_points: not_implemented Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::counting::other_count<1> Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::counting::other_count<(1 << geometry::dimension::value)> Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::counting::other_count<2> Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::num_points::range_count Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::num_points::range_count Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::counting::polygon_count Chris@101: < Chris@101: detail::num_points::range_count Chris@101: > Chris@16: {}; Chris@16: Chris@101: template Chris@101: struct num_points Chris@101: : detail::counting::multi_count Chris@101: < Chris@101: num_points::type, AddForOpen> Chris@101: > Chris@101: {}; Chris@101: Chris@101: } // namespace dispatch Chris@101: #endif Chris@101: Chris@101: Chris@101: namespace resolve_variant Chris@101: { Chris@101: Chris@16: template Chris@101: struct num_points Chris@16: { Chris@16: static inline std::size_t apply(Geometry const& geometry, Chris@16: bool add_for_open) Chris@16: { Chris@101: concept::check(); Chris@101: Chris@101: return add_for_open Chris@101: ? dispatch::num_points::apply(geometry) Chris@101: : dispatch::num_points::apply(geometry); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@101: struct num_points > Chris@16: { Chris@16: struct visitor: boost::static_visitor Chris@16: { Chris@16: bool m_add_for_open; Chris@16: Chris@16: visitor(bool add_for_open): m_add_for_open(add_for_open) {} Chris@16: Chris@16: template Chris@101: inline std::size_t operator()(Geometry const& geometry) const Chris@16: { Chris@101: return num_points::apply(geometry, m_add_for_open); Chris@16: } Chris@16: }; Chris@16: Chris@16: static inline std::size_t Chris@16: apply(boost::variant const& geometry, Chris@16: bool add_for_open) Chris@16: { Chris@16: return boost::apply_visitor(visitor(add_for_open), geometry); Chris@16: } Chris@16: }; Chris@16: Chris@101: } // namespace resolve_variant Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief \brief_calc{number of points} Chris@16: \ingroup num_points Chris@16: \details \details_calc{num_points, number of points}. Chris@16: \tparam Geometry \tparam_geometry Chris@16: \param geometry \param_geometry Chris@16: \param add_for_open add one for open geometries (i.e. polygon types which are not closed) Chris@16: \return \return_calc{number of points} Chris@16: Chris@16: \qbk{[include reference/algorithms/num_points.qbk]} Chris@16: */ Chris@16: template Chris@16: inline std::size_t num_points(Geometry const& geometry, bool add_for_open = false) Chris@16: { Chris@101: return resolve_variant::num_points::apply(geometry, add_for_open); Chris@16: } Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: Chris@16: #endif // BOOST_GEOMETRY_ALGORITHMS_NUM_POINTS_HPP