00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __VEC2I_H__
00031 #define __VEC2I_H__
00032
00034
00035 template <typename T>
00036 class Vec2T
00037 {
00038 public:
00039 Vec2T() : x(0), y(0) {}
00040 Vec2T(T x, T y) : x(x), y(y) {}
00041 public:
00042 T x;
00043 T y;
00044 };
00045
00046
00047 template <typename T>
00048 inline bool operator == (const Vec2T<T> &lhs, const Vec2T<T> &rhs)
00049 {
00050 return lhs.x == rhs.x && lhs.y == rhs.y;
00051 }
00052
00053 template <typename T>
00054 inline bool operator != (const Vec2T<T> &lhs, const Vec2T<T> &rhs)
00055 {
00056 return !(lhs == rhs);
00057 }
00058
00059 template <typename T>
00060 inline const Vec2T<T> &operator += (Vec2T<T> &lhs, const Vec2T<T> &rhs)
00061 {
00062 lhs.x += rhs.x;
00063 lhs.y += rhs.y;
00064 return lhs;
00065 }
00066
00067 template <typename T>
00068 inline const Vec2T<T> &operator -= (Vec2T<T> &lhs, const Vec2T<T> &rhs)
00069 {
00070 lhs.x -= rhs.x;
00071 lhs.y -= rhs.y;
00072 return lhs;
00073 }
00074
00075 template <typename T>
00076 inline const Vec2T<T> &operator *= (Vec2T<T> &lhs, int rhs)
00077 {
00078 lhs.x *= rhs;
00079 lhs.y *= rhs;
00080 return lhs;
00081 }
00082
00083 template <typename T>
00084 inline const Vec2T<T> &operator /= (Vec2T<T> &lhs, int rhs)
00085 {
00086 lhs.x /= rhs;
00087 lhs.y /= rhs;
00088 return lhs;
00089 }
00090
00091 template <typename T>
00092 inline Vec2T<T> operator + (const Vec2T<T> &lhs, const Vec2T<T> &rhs)
00093 {
00094 Vec2T<T> res(lhs);
00095
00096 res += rhs;
00097 return res;
00098 }
00099
00100 template <typename T>
00101 inline Vec2T<T> operator - (const Vec2T<T> &lhs, const Vec2T<T> &rhs)
00102 {
00103 Vec2T<T> res(lhs);
00104
00105 res -= rhs;
00106 return res;
00107 }
00108
00109 template <typename T>
00110 inline Vec2T<T> operator * (const Vec2T<T> &lhs, int rhs)
00111 {
00112 Vec2T<T> res(lhs);
00113
00114 res *= rhs;
00115 return res;
00116 }
00117
00118 template <typename T>
00119 inline Vec2T<T> operator * (int lhs, const Vec2T<T> &rhs)
00120 {
00121 Vec2T<T> res(rhs);
00122
00123 res *= lhs;
00124 return res;
00125 }
00126
00127 template <typename T>
00128 inline Vec2T<T> operator / (const Vec2T<T> &lhs, int rhs)
00129 {
00130 Vec2T<T> res(lhs);
00131
00132 res /= rhs;
00133 return res;
00134 }
00135
00136 template <typename T>
00137 inline int SquareDistance(const Vec2T<T> &pos1, const Vec2T<T> &pos2)
00138 {
00139 const Vec2T<T> diff = pos2 - pos1;
00140
00141 return diff.x * diff.x + diff.y * diff.y;
00142 }
00143
00144 template <typename T>
00145 inline int Distance(const Vec2T<T> &pos1, const Vec2T<T> &pos2)
00146 {
00147 return isqrt(SquareDistance(pos1, pos2));
00148 }
00149
00150 typedef Vec2T<short int> Vec2i;
00151 typedef Vec2T<int> PixelPos;
00152 typedef Vec2T<int> PixelDiff;
00153 typedef Vec2T<int> PixelSize;
00154
00156
00157 #endif // !__VEC2I_H__