Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:42

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2017-2023 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2015-2021.
0009 // Modifications copyright (c) 2015-2021 Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 
0013 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0014 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0015 
0016 // Use, modification and distribution is subject to the Boost Software License,
0017 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 
0020 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
0021 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
0022 
0023 
0024 #include <cstddef>
0025 
0026 #include <boost/geometry/algorithms/assign.hpp>
0027 #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
0028 #include <boost/geometry/arithmetic/arithmetic.hpp>
0029 #include <boost/geometry/core/coordinate_type.hpp>
0030 #include <boost/geometry/core/point_type.hpp>
0031 #include <boost/geometry/strategies/centroid.hpp>
0032 
0033 
0034 namespace boost { namespace geometry
0035 {
0036 
0037 namespace strategy { namespace centroid
0038 {
0039 
0040 
0041 /*!
0042 \brief Centroid calculation taking average of points
0043 \ingroup strategies
0044 */
0045 template
0046 <
0047     typename Ignored1 = void,
0048     typename Ignored2 = void
0049 >
0050 class average
0051 {
0052 private :
0053 
0054     /*! subclass to keep state */
0055     template <typename GeometryPoint, typename ResultPoint>
0056     class sum
0057     {
0058         friend class average;
0059         signed_size_type count;
0060         ResultPoint centroid;
0061 
0062     public :
0063         inline sum()
0064             : count(0)
0065         {
0066             assign_zero(centroid);
0067         }
0068     };
0069 
0070 public :
0071     template <typename GeometryPoint, typename ResultPoint>
0072     struct state_type
0073     {
0074         typedef sum<GeometryPoint, ResultPoint> type;
0075     };
0076 
0077     template <typename GeometryPoint, typename ResultPoint>
0078     static inline void apply(GeometryPoint const& p,
0079                              sum<GeometryPoint, ResultPoint>& state)
0080     {
0081         add_point(state.centroid, p);
0082         state.count++;
0083     }
0084 
0085     template <typename GeometryPoint, typename ResultPoint>
0086     static inline bool result(sum<GeometryPoint, ResultPoint> const& state,
0087                               ResultPoint& centroid)
0088     {
0089         centroid = state.centroid;
0090         if ( state.count > 0 )
0091         {
0092             using coord_t = typename coordinate_type<ResultPoint>::type;
0093             divide_value(centroid, static_cast<coord_t>(state.count));
0094             return true;
0095         }
0096         return false;
0097     }
0098 
0099 };
0100 
0101 
0102 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0103 
0104 
0105 namespace services
0106 {
0107 
0108 template <typename Point, std::size_t DimensionCount, typename Geometry>
0109 struct default_strategy
0110 <
0111     cartesian_tag,
0112     pointlike_tag,
0113     DimensionCount,
0114     Point,
0115     Geometry
0116 >
0117 {
0118     typedef average
0119         <
0120             Point,
0121             typename point_type<Geometry>::type
0122         > type;
0123 };
0124 
0125 } // namespace services
0126 
0127 #endif
0128 
0129 
0130 }} // namespace strategy::centroid
0131 
0132 
0133 }} // namespace boost::geometry
0134 
0135 
0136 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP