#ifndef COORDT_H #define COORDT_H #include namespace NICE { /** * A simple 2D coordinate. * * @author Frank Mattern */ template class CoordT { public: T x; T y; public: /** * Create an zero coordinate. */ CoordT() { x = 0; y = 0; } /** * Create a coordinate with given parameters. * @param _x * @param _y */ CoordT(const T _x, const T _y) { x = _x; y = _y; } /** * Copy-constructor. * @param other Original coordinate. */ CoordT(const CoordT& other) { x = other.x; y = other.y; } ~CoordT() { } //! Assignment operator /*! \param ex class to copy * \return a reference to this class */ CoordT& operator=(const CoordT& ex) { x=ex.x; y=ex.y; return *this; } //! Compare operator /*! \param ex class to compare * \return true if class content is equal */ bool operator==(const CoordT& ex) const { if(ex.x==x && ex.y == y) return true; else return false; } CoordT &operator+=(const CoordT& ex) { x += ex.x; y += ex.y; return *this; } CoordT &operator-=(const CoordT& ex) { x -= ex.x; y -= ex.y; return *this; } CoordT &operator*=(const T& v) { x *= v; y *= v; return *this; } CoordT &operator/=(const T& v) { x /= v; y /= v; return *this; } CoordT operator+(const CoordT& ex) const { CoordT result(x,y); result+=ex; return result; } CoordT operator-(const CoordT& ex) const { CoordT result(x,y); result-=ex; return result; } CoordT operator*(const T& v) const { CoordT result(x,y); result*=v; return result; } CoordT operator/(const T& v) const { CoordT result(x,y); result/=v; return result; } }; template inline std::ostream& operator<< (std::ostream& out, const CoordT& coord) { out << coord.x << " " << coord.y; return out; } typedef CoordT Coord; } // namespace #endif // COORDT_H