annotate DEPENDENCIES/generic/include/boost/geometry/algorithms/length.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@16 2
Chris@101 3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
Chris@101 4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
Chris@101 5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
Chris@101 6
Chris@101 7 // This file was modified by Oracle on 2014, 2015.
Chris@101 8 // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
Chris@101 9
Chris@101 10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
Chris@101 11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
Chris@16 12
Chris@16 13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
Chris@16 14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
Chris@16 15
Chris@16 16 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 18 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 19
Chris@16 20 #ifndef BOOST_GEOMETRY_ALGORITHMS_LENGTH_HPP
Chris@16 21 #define BOOST_GEOMETRY_ALGORITHMS_LENGTH_HPP
Chris@16 22
Chris@16 23 #include <iterator>
Chris@16 24
Chris@16 25 #include <boost/concept_check.hpp>
Chris@101 26 #include <boost/core/ignore_unused.hpp>
Chris@16 27 #include <boost/range.hpp>
Chris@16 28
Chris@16 29 #include <boost/mpl/fold.hpp>
Chris@16 30 #include <boost/mpl/greater.hpp>
Chris@16 31 #include <boost/mpl/if.hpp>
Chris@16 32 #include <boost/mpl/insert.hpp>
Chris@16 33 #include <boost/mpl/int.hpp>
Chris@16 34 #include <boost/mpl/set.hpp>
Chris@16 35 #include <boost/mpl/size.hpp>
Chris@16 36 #include <boost/mpl/transform.hpp>
Chris@16 37 #include <boost/type_traits.hpp>
Chris@16 38
Chris@101 39 #include <boost/variant/apply_visitor.hpp>
Chris@101 40 #include <boost/variant/static_visitor.hpp>
Chris@101 41 #include <boost/variant/variant_fwd.hpp>
Chris@101 42
Chris@16 43 #include <boost/geometry/core/cs.hpp>
Chris@16 44 #include <boost/geometry/core/closure.hpp>
Chris@101 45 #include <boost/geometry/core/tags.hpp>
Chris@16 46
Chris@16 47 #include <boost/geometry/geometries/concepts/check.hpp>
Chris@16 48
Chris@16 49 #include <boost/geometry/algorithms/assign.hpp>
Chris@16 50 #include <boost/geometry/algorithms/detail/calculate_null.hpp>
Chris@101 51 #include <boost/geometry/algorithms/detail/multi_sum.hpp>
Chris@16 52 // #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
Chris@16 53 #include <boost/geometry/views/closeable_view.hpp>
Chris@16 54 #include <boost/geometry/strategies/distance.hpp>
Chris@16 55 #include <boost/geometry/strategies/default_length_result.hpp>
Chris@16 56
Chris@16 57
Chris@16 58 namespace boost { namespace geometry
Chris@16 59 {
Chris@16 60
Chris@16 61
Chris@16 62 #ifndef DOXYGEN_NO_DETAIL
Chris@16 63 namespace detail { namespace length
Chris@16 64 {
Chris@16 65
Chris@16 66
Chris@16 67 template<typename Segment>
Chris@16 68 struct segment_length
Chris@16 69 {
Chris@16 70 template <typename Strategy>
Chris@16 71 static inline typename default_length_result<Segment>::type apply(
Chris@16 72 Segment const& segment, Strategy const& strategy)
Chris@16 73 {
Chris@101 74 boost::ignore_unused(strategy);
Chris@16 75 typedef typename point_type<Segment>::type point_type;
Chris@16 76 point_type p1, p2;
Chris@16 77 geometry::detail::assign_point_from_index<0>(segment, p1);
Chris@16 78 geometry::detail::assign_point_from_index<1>(segment, p2);
Chris@16 79 return strategy.apply(p1, p2);
Chris@16 80 }
Chris@16 81 };
Chris@16 82
Chris@16 83 /*!
Chris@16 84 \brief Internal, calculates length of a linestring using iterator pairs and
Chris@16 85 specified strategy
Chris@16 86 \note for_each could be used here, now that point_type is changed by boost
Chris@16 87 range iterator
Chris@16 88 */
Chris@16 89 template<typename Range, closure_selector Closure>
Chris@16 90 struct range_length
Chris@16 91 {
Chris@16 92 typedef typename default_length_result<Range>::type return_type;
Chris@16 93
Chris@16 94 template <typename Strategy>
Chris@16 95 static inline return_type apply(
Chris@16 96 Range const& range, Strategy const& strategy)
Chris@16 97 {
Chris@101 98 boost::ignore_unused(strategy);
Chris@16 99 typedef typename closeable_view<Range const, Closure>::type view_type;
Chris@16 100 typedef typename boost::range_iterator
Chris@16 101 <
Chris@16 102 view_type const
Chris@16 103 >::type iterator_type;
Chris@16 104
Chris@16 105 return_type sum = return_type();
Chris@16 106 view_type view(range);
Chris@16 107 iterator_type it = boost::begin(view), end = boost::end(view);
Chris@16 108 if(it != end)
Chris@16 109 {
Chris@16 110 for(iterator_type previous = it++;
Chris@16 111 it != end;
Chris@16 112 ++previous, ++it)
Chris@16 113 {
Chris@16 114 // Add point-point distance using the return type belonging
Chris@16 115 // to strategy
Chris@16 116 sum += strategy.apply(*previous, *it);
Chris@16 117 }
Chris@16 118 }
Chris@16 119
Chris@16 120 return sum;
Chris@16 121 }
Chris@16 122 };
Chris@16 123
Chris@16 124
Chris@16 125 }} // namespace detail::length
Chris@16 126 #endif // DOXYGEN_NO_DETAIL
Chris@16 127
Chris@16 128
Chris@16 129 #ifndef DOXYGEN_NO_DISPATCH
Chris@16 130 namespace dispatch
Chris@16 131 {
Chris@16 132
Chris@16 133
Chris@16 134 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
Chris@16 135 struct length : detail::calculate_null
Chris@16 136 {
Chris@16 137 typedef typename default_length_result<Geometry>::type return_type;
Chris@16 138
Chris@16 139 template <typename Strategy>
Chris@16 140 static inline return_type apply(Geometry const& geometry, Strategy const& strategy)
Chris@16 141 {
Chris@16 142 return calculate_null::apply<return_type>(geometry, strategy);
Chris@16 143 }
Chris@16 144 };
Chris@16 145
Chris@16 146
Chris@16 147 template <typename Geometry>
Chris@16 148 struct length<Geometry, linestring_tag>
Chris@16 149 : detail::length::range_length<Geometry, closed>
Chris@16 150 {};
Chris@16 151
Chris@16 152
Chris@16 153 // RING: length is currently 0; it might be argued that it is the "perimeter"
Chris@16 154
Chris@16 155
Chris@16 156 template <typename Geometry>
Chris@16 157 struct length<Geometry, segment_tag>
Chris@16 158 : detail::length::segment_length<Geometry>
Chris@16 159 {};
Chris@16 160
Chris@16 161
Chris@101 162 template <typename MultiLinestring>
Chris@101 163 struct length<MultiLinestring, multi_linestring_tag> : detail::multi_sum
Chris@101 164 {
Chris@101 165 template <typename Strategy>
Chris@101 166 static inline typename default_length_result<MultiLinestring>::type
Chris@101 167 apply(MultiLinestring const& multi, Strategy const& strategy)
Chris@101 168 {
Chris@101 169 return multi_sum::apply
Chris@101 170 <
Chris@101 171 typename default_length_result<MultiLinestring>::type,
Chris@101 172 detail::length::range_length
Chris@101 173 <
Chris@101 174 typename boost::range_value<MultiLinestring>::type,
Chris@101 175 closed // no need to close it explicitly
Chris@101 176 >
Chris@101 177 >(multi, strategy);
Chris@101 178
Chris@101 179 }
Chris@101 180 };
Chris@101 181
Chris@101 182
Chris@101 183 } // namespace dispatch
Chris@101 184 #endif // DOXYGEN_NO_DISPATCH
Chris@101 185
Chris@101 186
Chris@101 187 namespace resolve_variant {
Chris@101 188
Chris@16 189 template <typename Geometry>
Chris@101 190 struct length
Chris@16 191 {
Chris@16 192 template <typename Strategy>
Chris@101 193 static inline typename default_length_result<Geometry>::type
Chris@101 194 apply(Geometry const& geometry, Strategy const& strategy)
Chris@16 195 {
Chris@101 196 return dispatch::length<Geometry>::apply(geometry, strategy);
Chris@16 197 }
Chris@16 198 };
Chris@16 199
Chris@16 200 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
Chris@101 201 struct length<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
Chris@16 202 {
Chris@101 203 typedef typename default_length_result
Chris@101 204 <
Chris@101 205 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>
Chris@101 206 >::type result_type;
Chris@16 207
Chris@16 208 template <typename Strategy>
Chris@16 209 struct visitor
Chris@16 210 : static_visitor<result_type>
Chris@16 211 {
Chris@16 212 Strategy const& m_strategy;
Chris@16 213
Chris@16 214 visitor(Strategy const& strategy)
Chris@16 215 : m_strategy(strategy)
Chris@16 216 {}
Chris@16 217
Chris@16 218 template <typename Geometry>
Chris@101 219 inline typename default_length_result<Geometry>::type
Chris@16 220 operator()(Geometry const& geometry) const
Chris@16 221 {
Chris@101 222 return length<Geometry>::apply(geometry, m_strategy);
Chris@16 223 }
Chris@16 224 };
Chris@16 225
Chris@16 226 template <typename Strategy>
Chris@16 227 static inline result_type apply(
Chris@16 228 variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
Chris@16 229 Strategy const& strategy
Chris@16 230 )
Chris@16 231 {
Chris@16 232 return apply_visitor(visitor<Strategy>(strategy), geometry);
Chris@16 233 }
Chris@16 234 };
Chris@16 235
Chris@101 236 } // namespace resolve_variant
Chris@16 237
Chris@16 238
Chris@16 239 /*!
Chris@16 240 \brief \brief_calc{length}
Chris@16 241 \ingroup length
Chris@16 242 \details \details_calc{length, length (the sum of distances between consecutive points)}. \details_default_strategy
Chris@16 243 \tparam Geometry \tparam_geometry
Chris@16 244 \param geometry \param_geometry
Chris@16 245 \return \return_calc{length}
Chris@16 246
Chris@16 247 \qbk{[include reference/algorithms/length.qbk]}
Chris@16 248 \qbk{[length] [length_output]}
Chris@16 249 */
Chris@16 250 template<typename Geometry>
Chris@101 251 inline typename default_length_result<Geometry>::type
Chris@16 252 length(Geometry const& geometry)
Chris@16 253 {
Chris@16 254 concept::check<Geometry const>();
Chris@16 255
Chris@16 256 // detail::throw_on_empty_input(geometry);
Chris@16 257
Chris@101 258 // TODO put this into a resolve_strategy stage
Chris@16 259 typedef typename strategy::distance::services::default_strategy
Chris@16 260 <
Chris@101 261 point_tag, point_tag, typename point_type<Geometry>::type
Chris@16 262 >::type strategy_type;
Chris@16 263
Chris@101 264 return resolve_variant::length<Geometry>::apply(geometry, strategy_type());
Chris@16 265 }
Chris@16 266
Chris@16 267
Chris@16 268 /*!
Chris@16 269 \brief \brief_calc{length} \brief_strategy
Chris@16 270 \ingroup length
Chris@16 271 \details \details_calc{length, length (the sum of distances between consecutive points)} \brief_strategy. \details_strategy_reasons
Chris@16 272 \tparam Geometry \tparam_geometry
Chris@16 273 \tparam Strategy \tparam_strategy{distance}
Chris@16 274 \param geometry \param_geometry
Chris@16 275 \param strategy \param_strategy{distance}
Chris@16 276 \return \return_calc{length}
Chris@16 277
Chris@16 278 \qbk{distinguish,with strategy}
Chris@16 279 \qbk{[include reference/algorithms/length.qbk]}
Chris@16 280 \qbk{[length_with_strategy] [length_with_strategy_output]}
Chris@16 281 */
Chris@16 282 template<typename Geometry, typename Strategy>
Chris@101 283 inline typename default_length_result<Geometry>::type
Chris@16 284 length(Geometry const& geometry, Strategy const& strategy)
Chris@16 285 {
Chris@16 286 concept::check<Geometry const>();
Chris@16 287
Chris@16 288 // detail::throw_on_empty_input(geometry);
Chris@101 289
Chris@101 290 return resolve_variant::length<Geometry>::apply(geometry, strategy);
Chris@16 291 }
Chris@16 292
Chris@16 293
Chris@16 294 }} // namespace boost::geometry
Chris@16 295
Chris@16 296 #endif // BOOST_GEOMETRY_ALGORITHMS_LENGTH_HPP