00001 #ifndef __VEC2_H__ 00002 #define __VEC2_H__ 00003 00004 #ifndef DOXYGEN_IGNORE_TAG 00005 00026 #endif 00027 00028 #include <iostream> 00029 #include <cmath> 00030 00031 template <typename T> 00032 struct Vec2 00033 { 00034 T x; 00035 T y; 00037 Vec2(void):x(0),y(0) {} 00038 00040 00044 Vec2(const T& x, const T& y):x(x),y(y) {} 00045 00046 bool operator==(const Vec2<T>& v)const 00047 { 00048 if ( v.x == this->x && v.y == this->y ) 00049 { 00050 return true; 00051 } 00052 00053 return false; 00054 } 00055 }; 00056 00057 template <typename T> 00058 std::ostream& operator<< (std::ostream& o, const Vec2<T>& v) 00059 { 00060 o << "Vec2(" << v.x << ";" << v.y << ")"; 00061 00062 return o; 00063 } 00064 00065 template <typename T> 00066 T distance(const Vec2<T>& v1, const Vec2<T>& v2) 00067 { 00068 T dx=0; 00069 T dy=0; 00070 00071 if ( v2.x < v1.x ) 00072 { 00073 dx = v1.x - v2.x; 00074 } 00075 else 00076 { 00077 dx = v2.x - v1.x; 00078 } 00079 00080 if ( v2.y < v1.y ) 00081 { 00082 dy = v1.y - v2.y; 00083 } 00084 else 00085 { 00086 dy = v2.y - v1.y; 00087 } 00088 00089 return dx + dy; 00090 } 00091 00092 typedef Vec2<int> IVec2; 00093 typedef Vec2<unsigned int> UVec2; 00094 00119 #endif