#ifndef _XYZ_TYPE_H #define _XYZ_TYPE_H #include #include #include template struct xyz_type { T x; T y; T z; xyz_type(void) : x(T()), y(T()), z(T()) { } xyz_type(const T& val) : x(val), y(val), z(val) { } xyz_type(const T& xx, const T& yy, const T& zz) : x(xx), y(yy), z(zz) { } xyz_type& operator=(const xyz_type other) { this->x = other.x; this->y = other.y; this->z = other.z; return *this; } xyz_type& operator=(const T& val) { this->x = this->y = this->z = val; return *this; } }; template inline std::ostream& operator<<(std::ostream& s, const xyz_type& val) { return s << std::setprecision(9) << std::setw(15) << val.x << " " << std::setw(15) << val.y << " " << std::setw(15) << val.z; } template inline xyz_type operator+(const xyz_type& u, const xyz_type& v) { return (xyz_type(u.x + v.x, u.y + v.y, u.z + v.z)); } template inline xyz_type operator-(const xyz_type& u, const xyz_type& v) { return (xyz_type(u.x - v.x, u.y - v.y, u.z - v.z)); } template inline xyz_type operator+(const xyz_type& u, const T& v) { return (xyz_type(u.x + v, u.y + v, u.z + v)); } template inline xyz_type operator*(const xyz_type& u, const xyz_type& v) { return (xyz_type(u.x * v.x, u.y * v.y, u.z * v.z)); } template inline xyz_type operator*(const T& u, const xyz_type& v) { return (xyz_type(u * v.x, u * v.y, u * v.z)); } template inline xyz_type operator*(const xyz_type& u, const T& v) { return (xyz_type(u.x * v, u.y * v, u.z * v)); } template inline xyz_type operator/(const xyz_type& u, const xyz_type& v) { return (xyz_type(u.x / v.x, u.y / v.y, u.z / v.z)); } template inline xyz_type operator/(const xyz_type& u, const T& v) { return (xyz_type(u.x / v, u.y / v, u.z / v)); } template inline bool operator==(const xyz_type& u, const xyz_type& v) { return(u.x == v.x && u.y == v.y && u.z == v.z); } template inline bool operator<(const xyz_type& u, const xyz_type& v) { return(u.x < v.x || (!(u.x < v.x) && (u.y < v.y || (!(v.y < u.y) && u.z < v.z)))); } template inline bool operator!=(const xyz_type& x, const xyz_type& y) { return(!(x == y)); } template inline bool operator>(const xyz_type& x, const xyz_type& y) { return(y < x); } template inline bool operator<=(const xyz_type& x, const xyz_type& y) { return(!(y < x)); } template inline bool operator>=(const xyz_type& x, const xyz_type& y) { return(!(x < y)); } //Boost-Fu to make the above operators work with lambda transparently (no return type specification) namespace boost { namespace lambda { template struct plain_return_type_2, xyz_type, xyz_type > { typedef xyz_type type; }; template struct plain_return_type_2, T, xyz_type > { typedef xyz_type type; }; } } #endif