Chris@102: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@102: Chris@102: // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@102: // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. Chris@102: // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. Chris@102: Chris@102: // This file was modified by Oracle on 2015. Chris@102: // Modifications copyright (c) 2015 Oracle and/or its affiliates. Chris@102: Chris@102: // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle Chris@102: Chris@102: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@102: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@102: Chris@102: // Use, modification and distribution is subject to the Boost Software License, Chris@102: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP Chris@102: #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP Chris@102: Chris@102: Chris@102: #include Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: Chris@102: namespace boost { namespace geometry Chris@102: { Chris@102: Chris@102: namespace strategy { namespace centroid Chris@102: { Chris@102: Chris@102: Chris@102: /*! Chris@102: \brief Centroid calculation taking average of points Chris@102: \ingroup strategies Chris@102: */ Chris@102: template Chris@102: < Chris@102: typename PointCentroid, Chris@102: typename Point = PointCentroid Chris@102: > Chris@102: class average Chris@102: { Chris@102: private : Chris@102: Chris@102: /*! subclass to keep state */ Chris@102: class sum Chris@102: { Chris@102: friend class average; Chris@102: std::size_t count; Chris@102: PointCentroid centroid; Chris@102: Chris@102: public : Chris@102: inline sum() Chris@102: : count(0) Chris@102: { Chris@102: assign_zero(centroid); Chris@102: } Chris@102: }; Chris@102: Chris@102: public : Chris@102: typedef sum state_type; Chris@102: typedef PointCentroid centroid_point_type; Chris@102: typedef Point point_type; Chris@102: Chris@102: static inline void apply(Point const& p, sum& state) Chris@102: { Chris@102: add_point(state.centroid, p); Chris@102: state.count++; Chris@102: } Chris@102: Chris@102: static inline bool result(sum const& state, PointCentroid& centroid) Chris@102: { Chris@102: centroid = state.centroid; Chris@102: if ( state.count > 0 ) Chris@102: { Chris@102: divide_value(centroid, state.count); Chris@102: return true; Chris@102: } Chris@102: return false; Chris@102: } Chris@102: Chris@102: }; Chris@102: Chris@102: Chris@102: #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS Chris@102: Chris@102: Chris@102: namespace services Chris@102: { Chris@102: Chris@102: template Chris@102: struct default_strategy Chris@102: < Chris@102: cartesian_tag, Chris@102: pointlike_tag, Chris@102: DimensionCount, Chris@102: Point, Chris@102: Geometry Chris@102: > Chris@102: { Chris@102: typedef average Chris@102: < Chris@102: Point, Chris@102: typename point_type::type Chris@102: > type; Chris@102: }; Chris@102: Chris@102: } // namespace services Chris@102: Chris@102: #endif Chris@102: Chris@102: Chris@102: }} // namespace strategy::centroid Chris@102: Chris@102: Chris@102: }} // namespace boost::geometry Chris@102: Chris@102: Chris@102: #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP