1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
8 // This file was modified by Oracle on 2015-2021.
9 // Modifications copyright (c) 2015-2021 Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
20 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
21 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
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>
34 namespace boost { namespace geometry
37 namespace strategy { namespace centroid
42 \brief Centroid calculation taking average of points
47 typename Ignored1 = void,
48 typename Ignored2 = void
54 /*! subclass to keep state */
55 template <typename GeometryPoint, typename ResultPoint>
59 signed_size_type count;
66 assign_zero(centroid);
71 template <typename GeometryPoint, typename ResultPoint>
74 typedef sum<GeometryPoint, ResultPoint> type;
77 template <typename GeometryPoint, typename ResultPoint>
78 static inline void apply(GeometryPoint const& p,
79 sum<GeometryPoint, ResultPoint>& state)
81 add_point(state.centroid, p);
85 template <typename GeometryPoint, typename ResultPoint>
86 static inline bool result(sum<GeometryPoint, ResultPoint> const& state,
87 ResultPoint& centroid)
89 centroid = state.centroid;
90 if ( state.count > 0 )
92 divide_value(centroid, state.count);
101 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
107 template <typename Point, std::size_t DimensionCount, typename Geometry>
108 struct default_strategy
120 typename point_type<Geometry>::type
124 } // namespace services
129 }} // namespace strategy::centroid
132 }} // namespace boost::geometry
135 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP