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: 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_PERIMETER_HPP Chris@16: #define BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP Chris@16: Chris@101: #include Chris@16: Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: // #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: #ifndef DOXYGEN_NO_DISPATCH Chris@16: namespace dispatch Chris@16: { Chris@16: Chris@16: // Default perimeter is 0.0, specializations implement calculated values Chris@16: template ::type> Chris@16: struct perimeter : detail::calculate_null Chris@16: { Chris@16: typedef typename default_length_result::type return_type; Chris@16: Chris@16: template Chris@16: static inline return_type apply(Geometry const& geometry, Strategy const& strategy) Chris@16: { Chris@16: return calculate_null::apply(geometry, strategy); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct perimeter Chris@16: : detail::length::range_length Chris@16: < Chris@16: Geometry, Chris@16: closure::value Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct perimeter : detail::calculate_polygon_sum Chris@16: { Chris@16: typedef typename default_length_result::type return_type; Chris@16: typedef detail::length::range_length Chris@16: < Chris@16: typename ring_type::type, Chris@16: closure::value Chris@16: > policy; Chris@16: Chris@16: template Chris@16: static inline return_type apply(Polygon const& polygon, Strategy const& strategy) Chris@16: { Chris@16: return calculate_polygon_sum::apply(polygon, strategy); Chris@16: } Chris@16: }; Chris@16: Chris@101: template Chris@101: struct perimeter : detail::multi_sum Chris@101: { Chris@101: typedef typename default_length_result::type return_type; Chris@101: Chris@101: template Chris@101: static inline return_type apply(MultiPolygon const& multi, Strategy const& strategy) Chris@101: { Chris@101: return multi_sum::apply Chris@101: < Chris@101: return_type, Chris@101: perimeter::type> Chris@101: >(multi, strategy); Chris@101: } Chris@101: }; Chris@101: Chris@16: Chris@16: // box,n-sphere: to be implemented Chris@16: Chris@16: } // namespace dispatch Chris@16: #endif // DOXYGEN_NO_DISPATCH Chris@16: Chris@16: Chris@101: namespace resolve_strategy { Chris@101: Chris@101: struct perimeter Chris@101: { Chris@101: template Chris@101: static inline typename default_length_result::type Chris@101: apply(Geometry const& geometry, Strategy const& strategy) Chris@101: { Chris@101: return dispatch::perimeter::apply(geometry, strategy); Chris@101: } Chris@101: Chris@101: template Chris@101: static inline typename default_length_result::type Chris@101: apply(Geometry const& geometry, default_strategy) Chris@101: { Chris@101: typedef typename strategy::distance::services::default_strategy Chris@101: < Chris@101: point_tag, point_tag, typename point_type::type Chris@101: >::type strategy_type; Chris@101: Chris@101: return dispatch::perimeter::apply(geometry, strategy_type()); Chris@101: } Chris@101: }; Chris@101: Chris@101: } // namespace resolve_strategy Chris@101: Chris@101: Chris@101: namespace resolve_variant { Chris@101: Chris@101: template Chris@101: struct perimeter Chris@101: { Chris@101: template Chris@101: static inline typename default_length_result::type Chris@101: apply(Geometry const& geometry, Strategy const& strategy) Chris@101: { Chris@101: concept::check(); Chris@101: return resolve_strategy::perimeter::apply(geometry, strategy); Chris@101: } Chris@101: }; Chris@101: Chris@101: template Chris@101: struct perimeter > Chris@101: { Chris@101: typedef typename default_length_result Chris@101: < Chris@101: boost::variant Chris@101: >::type result_type; Chris@101: Chris@101: template Chris@101: struct visitor: boost::static_visitor Chris@101: { Chris@101: Strategy const& m_strategy; Chris@101: Chris@101: visitor(Strategy const& strategy): m_strategy(strategy) {} Chris@101: Chris@101: template Chris@101: typename default_length_result::type Chris@101: operator()(Geometry const& geometry) const Chris@101: { Chris@101: return perimeter::apply(geometry, m_strategy); Chris@101: } Chris@101: }; Chris@101: Chris@101: template Chris@101: static inline result_type Chris@101: apply(boost::variant const& geometry, Chris@101: Strategy const& strategy) Chris@101: { Chris@101: return boost::apply_visitor(visitor(strategy), geometry); Chris@101: } Chris@101: }; Chris@101: Chris@101: } // namespace resolve_variant Chris@101: Chris@101: Chris@16: /*! Chris@16: \brief \brief_calc{perimeter} Chris@16: \ingroup perimeter Chris@16: \details The function perimeter returns the perimeter of a geometry, Chris@16: using the default distance-calculation-strategy Chris@16: \tparam Geometry \tparam_geometry Chris@16: \param geometry \param_geometry Chris@16: \return \return_calc{perimeter} Chris@16: Chris@16: \qbk{[include reference/algorithms/perimeter.qbk]} Chris@16: */ Chris@16: template Chris@16: inline typename default_length_result::type perimeter( Chris@16: Geometry const& geometry) Chris@16: { Chris@16: // detail::throw_on_empty_input(geometry); Chris@101: return resolve_variant::perimeter::apply(geometry, default_strategy()); Chris@16: } Chris@16: Chris@16: /*! Chris@16: \brief \brief_calc{perimeter} \brief_strategy Chris@16: \ingroup perimeter Chris@16: \details The function perimeter returns the perimeter of a geometry, Chris@16: using specified strategy Chris@16: \tparam Geometry \tparam_geometry Chris@16: \tparam Strategy \tparam_strategy{distance} Chris@16: \param geometry \param_geometry Chris@16: \param strategy strategy to be used for distance calculations. Chris@16: \return \return_calc{perimeter} Chris@16: Chris@16: \qbk{distinguish,with strategy} Chris@16: \qbk{[include reference/algorithms/perimeter.qbk]} Chris@16: */ Chris@16: template Chris@16: inline typename default_length_result::type perimeter( Chris@16: Geometry const& geometry, Strategy const& strategy) Chris@16: { Chris@16: // detail::throw_on_empty_input(geometry); Chris@101: return resolve_variant::perimeter::apply(geometry, strategy); Chris@16: } Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: #endif // BOOST_GEOMETRY_ALGORITHMS_PERIMETER_HPP Chris@16: