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, 2015. Chris@101: // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates. Chris@101: Chris@101: // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle Chris@101: // Contributed and/or modified by Adam Wulkiewicz, 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_LENGTH_HPP Chris@16: #define BOOST_GEOMETRY_ALGORITHMS_LENGTH_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: // #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: Chris@16: #ifndef DOXYGEN_NO_DETAIL Chris@16: namespace detail { namespace length Chris@16: { Chris@16: Chris@16: Chris@16: template Chris@16: struct segment_length Chris@16: { Chris@16: template Chris@16: static inline typename default_length_result::type apply( Chris@16: Segment const& segment, Strategy const& strategy) Chris@16: { Chris@101: boost::ignore_unused(strategy); Chris@16: typedef typename point_type::type point_type; Chris@16: point_type p1, p2; Chris@16: geometry::detail::assign_point_from_index<0>(segment, p1); Chris@16: geometry::detail::assign_point_from_index<1>(segment, p2); Chris@16: return strategy.apply(p1, p2); Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: \brief Internal, calculates length of a linestring using iterator pairs and Chris@16: specified strategy Chris@16: \note for_each could be used here, now that point_type is changed by boost Chris@16: range iterator Chris@16: */ Chris@16: template Chris@16: struct range_length Chris@16: { Chris@16: typedef typename default_length_result::type return_type; Chris@16: Chris@16: template Chris@16: static inline return_type apply( Chris@16: Range const& range, Strategy const& strategy) Chris@16: { Chris@101: boost::ignore_unused(strategy); Chris@16: typedef typename closeable_view::type view_type; Chris@16: typedef typename boost::range_iterator Chris@16: < Chris@16: view_type const Chris@16: >::type iterator_type; Chris@16: Chris@16: return_type sum = return_type(); Chris@16: view_type view(range); Chris@16: iterator_type it = boost::begin(view), end = boost::end(view); Chris@16: if(it != end) Chris@16: { Chris@16: for(iterator_type previous = it++; Chris@16: it != end; Chris@16: ++previous, ++it) Chris@16: { Chris@16: // Add point-point distance using the return type belonging Chris@16: // to strategy Chris@16: sum += strategy.apply(*previous, *it); Chris@16: } Chris@16: } Chris@16: Chris@16: return sum; Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: }} // namespace detail::length 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: Chris@16: template ::type> Chris@16: struct length : 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: Chris@16: template Chris@16: struct length Chris@16: : detail::length::range_length Chris@16: {}; Chris@16: Chris@16: Chris@16: // RING: length is currently 0; it might be argued that it is the "perimeter" Chris@16: Chris@16: Chris@16: template Chris@16: struct length Chris@16: : detail::length::segment_length Chris@16: {}; Chris@16: Chris@16: Chris@101: template Chris@101: struct length : detail::multi_sum Chris@101: { Chris@101: template Chris@101: static inline typename default_length_result::type Chris@101: apply(MultiLinestring const& multi, Strategy const& strategy) Chris@101: { Chris@101: return multi_sum::apply Chris@101: < Chris@101: typename default_length_result::type, Chris@101: detail::length::range_length Chris@101: < Chris@101: typename boost::range_value::type, Chris@101: closed // no need to close it explicitly Chris@101: > Chris@101: >(multi, strategy); Chris@101: Chris@101: } Chris@101: }; Chris@101: Chris@101: Chris@101: } // namespace dispatch Chris@101: #endif // DOXYGEN_NO_DISPATCH Chris@101: Chris@101: Chris@101: namespace resolve_variant { Chris@101: Chris@16: template Chris@101: struct length Chris@16: { Chris@16: template Chris@101: static inline typename default_length_result::type Chris@101: apply(Geometry const& geometry, Strategy const& strategy) Chris@16: { Chris@101: return dispatch::length::apply(geometry, strategy); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@101: struct length > Chris@16: { Chris@101: typedef typename default_length_result Chris@101: < Chris@101: boost::variant Chris@101: >::type result_type; Chris@16: Chris@16: template Chris@16: struct visitor Chris@16: : static_visitor Chris@16: { Chris@16: Strategy const& m_strategy; Chris@16: Chris@16: visitor(Strategy const& strategy) Chris@16: : m_strategy(strategy) Chris@16: {} Chris@16: Chris@16: template Chris@101: inline typename default_length_result::type Chris@16: operator()(Geometry const& geometry) const Chris@16: { Chris@101: return length::apply(geometry, m_strategy); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: static inline result_type apply( Chris@16: variant const& geometry, Chris@16: Strategy const& strategy Chris@16: ) Chris@16: { Chris@16: return apply_visitor(visitor(strategy), geometry); Chris@16: } Chris@16: }; Chris@16: Chris@101: } // namespace resolve_variant Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief \brief_calc{length} Chris@16: \ingroup length Chris@16: \details \details_calc{length, length (the sum of distances between consecutive points)}. \details_default_strategy Chris@16: \tparam Geometry \tparam_geometry Chris@16: \param geometry \param_geometry Chris@16: \return \return_calc{length} Chris@16: Chris@16: \qbk{[include reference/algorithms/length.qbk]} Chris@16: \qbk{[length] [length_output]} Chris@16: */ Chris@16: template Chris@101: inline typename default_length_result::type Chris@16: length(Geometry const& geometry) Chris@16: { Chris@16: concept::check(); Chris@16: Chris@16: // detail::throw_on_empty_input(geometry); Chris@16: Chris@101: // TODO put this into a resolve_strategy stage Chris@16: typedef typename strategy::distance::services::default_strategy Chris@16: < Chris@101: point_tag, point_tag, typename point_type::type Chris@16: >::type strategy_type; Chris@16: Chris@101: return resolve_variant::length::apply(geometry, strategy_type()); Chris@16: } Chris@16: Chris@16: Chris@16: /*! Chris@16: \brief \brief_calc{length} \brief_strategy Chris@16: \ingroup length Chris@16: \details \details_calc{length, length (the sum of distances between consecutive points)} \brief_strategy. \details_strategy_reasons Chris@16: \tparam Geometry \tparam_geometry Chris@16: \tparam Strategy \tparam_strategy{distance} Chris@16: \param geometry \param_geometry Chris@16: \param strategy \param_strategy{distance} Chris@16: \return \return_calc{length} Chris@16: Chris@16: \qbk{distinguish,with strategy} Chris@16: \qbk{[include reference/algorithms/length.qbk]} Chris@16: \qbk{[length_with_strategy] [length_with_strategy_output]} Chris@16: */ Chris@16: template Chris@101: inline typename default_length_result::type Chris@16: length(Geometry const& geometry, Strategy const& strategy) Chris@16: { Chris@16: concept::check(); Chris@16: Chris@16: // detail::throw_on_empty_input(geometry); Chris@101: Chris@101: return resolve_variant::length::apply(geometry, strategy); Chris@16: } Chris@16: Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: #endif // BOOST_GEOMETRY_ALGORITHMS_LENGTH_HPP