#ifndef POINT_H #define POINT_H #include "types.h" #include #include template class TSize; template class TPoint { public: TPoint() : x(0), y(0) {}; TPoint(T x, T y) : x(x), y(y) { }; TPoint(const TPoint& other) : x(other.x), y(other.y) { }; bool isNull() const { return x==0 && y==0; } TSize toSize() const { return TSize(x, y); } TPoint operator-() const { return TPoint(-x, -y); } TPoint operator+(const TPoint& other) const { return TPoint(x + other.x, y + other.y); } TPoint& operator+=(const TPoint& other) { x+=other.x; y+=other.y; return *this; } TPoint operator-(const TPoint& other) const { return TPoint(x - other.x, y - other.y); } TPoint& operator-=(const TPoint& other) { x-=other.x; y-=other.y; return *this; } TPoint operator*(const TPoint& other) const { return TPoint(x * other.x, y * other.y); } TPoint& operator*=(const TPoint& other) { x*=other.x; y*=other.y; return *this; } TPoint operator*(const T v) const { return TPoint(x * v, y * v); } TPoint& operator*=(const T v) { x*=v; y*=v; return *this; } TPoint operator/(const TPoint& other) const { return TPoint(x/other.x, y/other.y); } TPoint& operator/=(const TPoint& other) { x/=other.x; y/=other.y; return *this; } TPoint operator/(const T v) const { return TPoint(x/v, y/v); } TPoint& operator/=(const T v) { x/=v; y/=v; return *this; } bool operator<=(const TPoint&other) const { return x<=other.x && y<=other.y; } bool operator>=(const TPoint&other) const { return x>=other.x && y>=other.y; } bool operator<(const TPoint&other) const { return x(const TPoint&other) const { return x>other.x && y>other.y; } TPoint& operator=(const TPoint& other) { x = other.x; y = other.y; return *this; } bool operator==(const TPoint& other) const { return other.x==x && other.y==y; } bool operator!=(const TPoint& other) const { return other.x!=x || other.y!=y; } float length() const { return sqrt((float)(x*x + y*y)); } T manhattanLength() const { return std::abs(x) + std::abs(y); } float distanceFrom(const TPoint& other) const { return TPoint(x - other.x, y - other.y).getLength(); } T x, y; }; typedef TPoint Point; typedef TPoint PointF; template std::ostream& operator<<(std::ostream& out, const TPoint& point) { out << point.x << " " << point.y; return out; } template std::istream& operator>>(std::istream& in, TPoint& point) { in >> point.x; in >> point.y; return in; } #endif