diff --git a/point.hpp b/point.hpp index 01e2be12..7929e7a7 100644 --- a/point.hpp +++ b/point.hpp @@ -203,6 +203,26 @@ namespace util { util::point > furthest (util::view*>); + + + /////////////////////////////////////////////////////////////////////////// + /// computes the mean point across a view of points + template + auto + center (util::view points) + { + CHECK_NEZ (points.size ()); + + using point_type = typename std::iterator_traits::value_type; + using value_type = typename point_type::value_type; + + util::vector accum = 0; + + for (auto const &i: points) + accum += i.template as (); + + return (accum / points.size ()).template as (); + } } #endif // __UTIL_POINT_HPP