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