/* * Range.hpp * * Created on: Jul 22, 2010 * Author: crueger */ #ifndef RANGE_HPP_ #define RANGE_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include "LinearAlgebra/Vector.hpp" template struct range { range(const T&,const T&); bool isInRange(const T&) const; bool isBefore(const T&) const; bool isBeyond(const T&) const; T first; T last; }; template inline range::range(const T &_first,const T &_last) : first(_first),last(_last) {} template inline bool range::isInRange(const T &value) const{ return first <= value && value < last; } template inline bool range::isBefore(const T &value) const{ return value < first; } template inline bool range::isBeyond(const T &value) const{ return last <= value; } template inline range makeRange(const T&first, const T&last){ return range(first,last); } template inline bool operator<(const range &x, const range &y){ return (x.first!=y.first)?x.first inline bool operator==(const range &x,const range &y){ return x.first==y.first && x.last==y.last; } template inline bool operator!= (const range& x, const range& y) { return !(x==y); } template inline bool operator> (const range& x, const range& y) { return y inline bool operator<=(const range& x, const range& y) { return !(y inline bool operator>= (const range& x, const range& y) { return !(x std::ostream &operator<< (std::ostream &ost, const range& y) { ost << "[" << y.first << ";" << y.last << "]"; return ost; } /******************************** Vector ********************************/ /* template specialization for Vector */ /************************************************************************/ class Vector; template <> inline bool range::isInRange(const Vector &value) const{ return first[0] <= value[0] && value[0] < last[0] && first[1] <= value[1] && value[1] < last[1] && first[2] <= value[2] && value[2] < last[2]; } template <> inline bool range::isBefore(const Vector &value) const{ return value[0] < first[0] || value[1] < first[1] || value[2] < first[2]; } template <> inline bool range::isBeyond(const Vector &value) const{ return last[0] <= value[0] || last[1] <= value[1] || last[2] <= value[2]; } #endif /* RANGE_HPP_ */