/* * VectorSet.hpp * * Created on: Jun 2, 2010 * Author: crueger */ #ifndef VECTORSET_HPP_ #define VECTORSET_HPP_ #include #include #include /** * A simple mixin to give any STL conforming structure fast Vector abilities * * TODO: make this work for maps */ #include "vector.hpp" #include // this tests, whether we actually have a Vector template struct is_vector{}; template <> struct is_vector{ typedef void wrong_type; }; template class VectorSet : public Set { // when our set carries something besides a vector this will produce an error typedef typename is_vector::wrong_type check_for_vector; public: // typedefs for STL conforming structure typedef typename Set::iterator iterator; typedef typename Set::const_iterator const_iterator; VectorSet(){} virtual ~VectorSet(){} /** * translate all Vectors within this set by a specified amount */ void translate(const Vector &translater){ // this is needed to allow template lookup transform(this->begin(),this->end(),this->begin(),std::bind1st(std::plus(),translater)); } double minDistSquared(const Vector &point){ if(!this->size()) return std::numeric_limits::infinity(); std::list helper; helper.resize(this->size()); transform(this->begin(),this->end(), helper.begin(), std::bind2nd(std::mem_fun_ref(&Vector::DistanceSquared),point)); return *min_element(helper.begin(),helper.end()); } }; // allows simpler definition of VectorSets #define VECTORSET(container_type) VectorSet > #endif /* VECTORSET_HPP_ */