]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/strategies/cartesian/centroid_average.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / strategies / cartesian / centroid_average.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // This file was modified by Oracle on 2015.
8 // Modifications copyright (c) 2015 Oracle and/or its affiliates.
9
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
20 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
21
22
23 #include <cstddef>
24
25 #include <boost/geometry/algorithms/assign.hpp>
26 #include <boost/geometry/arithmetic/arithmetic.hpp>
27 #include <boost/geometry/core/coordinate_type.hpp>
28 #include <boost/geometry/core/point_type.hpp>
29 #include <boost/geometry/strategies/centroid.hpp>
30
31
32 namespace boost { namespace geometry
33 {
34
35 namespace strategy { namespace centroid
36 {
37
38
39 /*!
40 \brief Centroid calculation taking average of points
41 \ingroup strategies
42 */
43 template
44 <
45 typename PointCentroid,
46 typename Point = PointCentroid
47 >
48 class average
49 {
50 private :
51
52 /*! subclass to keep state */
53 class sum
54 {
55 friend class average;
56 std::size_t count;
57 PointCentroid centroid;
58
59 public :
60 inline sum()
61 : count(0)
62 {
63 assign_zero(centroid);
64 }
65 };
66
67 public :
68 typedef sum state_type;
69 typedef PointCentroid centroid_point_type;
70 typedef Point point_type;
71
72 static inline void apply(Point const& p, sum& state)
73 {
74 add_point(state.centroid, p);
75 state.count++;
76 }
77
78 static inline bool result(sum const& state, PointCentroid& centroid)
79 {
80 centroid = state.centroid;
81 if ( state.count > 0 )
82 {
83 divide_value(centroid, state.count);
84 return true;
85 }
86 return false;
87 }
88
89 };
90
91
92 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
93
94
95 namespace services
96 {
97
98 template <typename Point, std::size_t DimensionCount, typename Geometry>
99 struct default_strategy
100 <
101 cartesian_tag,
102 pointlike_tag,
103 DimensionCount,
104 Point,
105 Geometry
106 >
107 {
108 typedef average
109 <
110 Point,
111 typename point_type<Geometry>::type
112 > type;
113 };
114
115 } // namespace services
116
117 #endif
118
119
120 }} // namespace strategy::centroid
121
122
123 }} // namespace boost::geometry
124
125
126 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP