00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_VECTOR2_H__
00021 #define __CS_VECTOR2_H__
00022
00026 class csVector2
00027 {
00028 public:
00030 float x;
00032 float y;
00033
00035 csVector2 () {}
00036
00038 csVector2 (float x, float y) { csVector2::x = x; csVector2::y = y; }
00039
00041 inline void Set (float ix, float iy)
00042 { x = ix; y = iy; }
00043
00045 inline void Set (const csVector2& v)
00046 { x = v.x; y = v.y; }
00047
00049 static float Norm (const csVector2& v);
00050
00052 float Norm () const;
00053
00055 float SquaredNorm () const
00056 { return x * x + y * y; }
00057
00059 void Rotate (float angle);
00060
00062 csVector2& operator+= (const csVector2& v)
00063 { x += v.x; y += v.y; return *this; }
00064
00066 csVector2& operator-= (const csVector2& v)
00067 { x -= v.x; y -= v.y; return *this; }
00068
00070 csVector2& operator*= (float f) { x *= f; y *= f; return *this; }
00071
00073 csVector2& operator/= (float f) { x /= f; y /= f; return *this; }
00074
00076 inline csVector2 operator+ () const { return *this; }
00077
00079 inline csVector2 operator- () const { return csVector2(-x,-y); }
00080
00082 friend csVector2 operator+ (const csVector2& v1, const csVector2& v2);
00084 friend csVector2 operator- (const csVector2& v1, const csVector2& v2);
00086 friend float operator* (const csVector2& v1, const csVector2& v2);
00088 friend csVector2 operator* (const csVector2& v, float f);
00090 friend csVector2 operator* (float f, const csVector2& v);
00092 friend csVector2 operator/ (const csVector2& v, float f);
00094 friend bool operator== (const csVector2& v1, const csVector2& v2);
00096 friend bool operator!= (const csVector2& v1, const csVector2& v2);
00097
00099 inline friend bool operator< (const csVector2& v, float f)
00100 { return ABS(v.x)<f && ABS(v.y)<f; }
00101
00103 inline friend bool operator> (float f, const csVector2& v)
00104 { return ABS(v.x)<f && ABS(v.y)<f; }
00105 };
00106
00107 #endif // __CS_VECTOR2_H__