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.
7 // This file was modified by Oracle on 2015.
8 // Modifications copyright (c) 2015 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
19 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
20 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
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>
32 namespace boost { namespace geometry
35 namespace strategy { namespace centroid
40 \brief Centroid calculation taking average of points
45 typename PointCentroid,
46 typename Point = PointCentroid
52 /*! subclass to keep state */
57 PointCentroid centroid;
63 assign_zero(centroid);
68 typedef sum state_type;
69 typedef PointCentroid centroid_point_type;
70 typedef Point point_type;
72 static inline void apply(Point const& p, sum& state)
74 add_point(state.centroid, p);
78 static inline bool result(sum const& state, PointCentroid& centroid)
80 centroid = state.centroid;
81 if ( state.count > 0 )
83 divide_value(centroid, state.count);
92 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
98 template <typename Point, std::size_t DimensionCount, typename Geometry>
99 struct default_strategy
111 typename point_type<Geometry>::type
115 } // namespace services
120 }} // namespace strategy::centroid
123 }} // namespace boost::geometry
126 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP