File indexing completed on 2025-01-18 09:36:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0043
0044
0045 template
0046 <
0047 typename Ignored1 = void,
0048 typename Ignored2 = void
0049 >
0050 class average
0051 {
0052 private :
0053
0054
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 }
0126
0127 #endif
0128
0129
0130 }}
0131
0132
0133 }}
0134
0135
0136 #endif