123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
- #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_CENTROID_AVERAGE_HPP
- #include <cstddef>
- #include <boost/geometry/algorithms/assign.hpp>
- #include <boost/geometry/algorithms/detail/signed_size_type.hpp>
- #include <boost/geometry/arithmetic/arithmetic.hpp>
- #include <boost/geometry/core/coordinate_type.hpp>
- #include <boost/geometry/core/point_type.hpp>
- #include <boost/geometry/strategies/centroid.hpp>
- namespace boost { namespace geometry
- {
- namespace strategy { namespace centroid
- {
- template
- <
- typename Ignored1 = void,
- typename Ignored2 = void
- >
- class average
- {
- private :
-
- template <typename GeometryPoint, typename ResultPoint>
- class sum
- {
- friend class average;
- signed_size_type count;
- ResultPoint centroid;
- public :
- inline sum()
- : count(0)
- {
- assign_zero(centroid);
- }
- };
- public :
- template <typename GeometryPoint, typename ResultPoint>
- struct state_type
- {
- typedef sum<GeometryPoint, ResultPoint> type;
- };
- template <typename GeometryPoint, typename ResultPoint>
- static inline void apply(GeometryPoint const& p,
- sum<GeometryPoint, ResultPoint>& state)
- {
- add_point(state.centroid, p);
- state.count++;
- }
- template <typename GeometryPoint, typename ResultPoint>
- static inline bool result(sum<GeometryPoint, ResultPoint> const& state,
- ResultPoint& centroid)
- {
- centroid = state.centroid;
- if ( state.count > 0 )
- {
- using coord_t = typename coordinate_type<ResultPoint>::type;
- divide_value(centroid, static_cast<coord_t>(state.count));
- return true;
- }
- return false;
- }
- };
- #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
- namespace services
- {
- template <typename Point, std::size_t DimensionCount, typename Geometry>
- struct default_strategy
- <
- cartesian_tag,
- pointlike_tag,
- DimensionCount,
- Point,
- Geometry
- >
- {
- typedef average
- <
- Point,
- typename point_type<Geometry>::type
- > type;
- };
- }
- #endif
- }}
- }}
- #endif
|