00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FXVEC2D_H
00025 #define FXVEC2D_H
00026
00027
00028 namespace FX {
00029
00030
00031 class FXMat3d;
00032
00033
00035 class FXAPI FXVec2d {
00036 public:
00037 FXdouble x;
00038 FXdouble y;
00039 public:
00040
00042 FXVec2d(){}
00043
00045 FXVec2d(const FXVec2d& v){x=v.x;y=v.y;}
00046
00048 FXVec2d(const FXdouble v[]){x=v[0];y=v[1];}
00049
00051 FXVec2d(FXdouble xx,FXdouble yy){x=xx;y=yy;}
00052
00054 FXdouble& operator[](FXint i){return (&x)[i];}
00055
00057 const FXdouble& operator[](FXint i) const {return (&x)[i];}
00058
00060 FXVec2d& operator=(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00061
00063 FXVec2d& operator=(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00064
00066 FXVec2d& set(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00067
00069 FXVec2d& set(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00070
00072 FXVec2d& set(FXdouble xx,FXdouble yy){x=xx;y=yy;return *this;}
00073
00075 FXVec2d& operator*=(FXdouble n){x*=n;y*=n;return *this;}
00076 FXVec2d& operator/=(FXdouble n){x/=n;y/=n;return *this;}
00077 FXVec2d& operator+=(const FXVec2d& v){x+=v.x;y+=v.y;return *this;}
00078 FXVec2d& operator-=(const FXVec2d& v){x-=v.x;y-=v.y;return *this;}
00079
00081 operator FXdouble*(){return &x;}
00082 operator const FXdouble*() const {return &x;}
00083
00085 FXVec2d operator+() const { return *this; }
00086 FXVec2d operator-() const { return FXVec2d(-x,-y); }
00087
00089 FXVec2d operator+(const FXVec2d& v) const { return FXVec2d(x+v.x,y+v.y); }
00090 FXVec2d operator-(const FXVec2d& v) const { return FXVec2d(x-v.x,y-v.y); }
00091
00093 FXVec2d operator*(const FXMat3d& m) const;
00094
00096 friend inline FXVec2d operator*(const FXVec2d& a,FXdouble n);
00097 friend inline FXVec2d operator*(FXdouble n,const FXVec2d& a);
00098 friend inline FXVec2d operator/(const FXVec2d& a,FXdouble n);
00099 friend inline FXVec2d operator/(FXdouble n,const FXVec2d& a);
00100
00102 FXdouble operator*(const FXVec2d& v) const { return x*v.x+y*v.y; }
00103
00105 bool operator!() const { return x==0.0 && y==0.0;}
00106
00108 bool operator==(const FXVec2d& v) const { return x==v.x && y==v.y; }
00109 bool operator!=(const FXVec2d& v) const { return x!=v.x || y!=v.y; }
00110
00111 friend inline bool operator==(const FXVec2d& a,FXdouble n);
00112 friend inline bool operator!=(const FXVec2d& a,FXdouble n);
00113 friend inline bool operator==(FXdouble n,const FXVec2d& a);
00114 friend inline bool operator!=(FXdouble n,const FXVec2d& a);
00115
00117 bool operator<(const FXVec2d& v) const { return x<v.x && y<v.y; }
00118 bool operator<=(const FXVec2d& v) const { return x<=v.x && y<=v.y; }
00119 bool operator>(const FXVec2d& v) const { return x>v.x && y>v.y; }
00120 bool operator>=(const FXVec2d& v) const { return x>=v.x && y>=v.y; }
00121
00122 friend inline bool operator<(const FXVec2d& a,FXdouble n);
00123 friend inline bool operator<=(const FXVec2d& a,FXdouble n);
00124 friend inline bool operator>(const FXVec2d& a,FXdouble n);
00125 friend inline bool operator>=(const FXVec2d& a,FXdouble n);
00126
00127 friend inline bool operator<(FXdouble n,const FXVec2d& a);
00128 friend inline bool operator<=(FXdouble n,const FXVec2d& a);
00129 friend inline bool operator>(FXdouble n,const FXVec2d& a);
00130 friend inline bool operator>=(FXdouble n,const FXVec2d& a);
00131
00133 FXdouble length2() const { return x*x+y*y; }
00134 FXdouble length() const { return sqrt(length2()); }
00135
00137 FXVec2d& clamp(FXdouble lo,FXdouble hi){x=FXCLAMP(lo,x,hi);y=FXCLAMP(lo,y,hi);return *this;}
00138
00140 friend inline FXVec2d veclo(const FXVec2d& a,const FXVec2d& b);
00141 friend inline FXVec2d vechi(const FXVec2d& a,const FXVec2d& b);
00142
00144 friend FXAPI FXVec2d vecnormalize(const FXVec2d& v);
00145
00147 friend FXAPI FXStream& operator<<(FXStream& store,const FXVec2d& v);
00148
00150 friend FXAPI FXStream& operator>>(FXStream& store,FXVec2d& v);
00151 };
00152
00153
00154 inline FXVec2d operator*(const FXVec2d& a,FXdouble n){return FXVec2d(a.x*n,a.y*n);}
00155 inline FXVec2d operator*(FXdouble n,const FXVec2d& a){return FXVec2d(n*a.x,n*a.y);}
00156 inline FXVec2d operator/(const FXVec2d& a,FXdouble n){return FXVec2d(a.x/n,a.y/n);}
00157 inline FXVec2d operator/(FXdouble n,const FXVec2d& a){return FXVec2d(n/a.x,n/a.y);}
00158
00159 inline bool operator==(const FXVec2d& a,FXdouble n){return a.x==n && a.y==n;}
00160 inline bool operator!=(const FXVec2d& a,FXdouble n){return a.x!=n || a.y!=n;}
00161 inline bool operator==(FXdouble n,const FXVec2d& a){return n==a.x && n==a.y;}
00162 inline bool operator!=(FXdouble n,const FXVec2d& a){return n!=a.x || n!=a.y;}
00163
00164 inline bool operator<(const FXVec2d& a,FXdouble n){return a.x<n && a.y<n;}
00165 inline bool operator<=(const FXVec2d& a,FXdouble n){return a.x<=n && a.y<=n;}
00166 inline bool operator>(const FXVec2d& a,FXdouble n){return a.x>n && a.y>n;}
00167 inline bool operator>=(const FXVec2d& a,FXdouble n){return a.x>=n && a.y>=n;}
00168
00169 inline bool operator<(FXdouble n,const FXVec2d& a){return n<a.x && n<a.y;}
00170 inline bool operator<=(FXdouble n,const FXVec2d& a){return n<=a.x && n<=a.y;}
00171 inline bool operator>(FXdouble n,const FXVec2d& a){return n>a.x && n>a.y;}
00172 inline bool operator>=(FXdouble n,const FXVec2d& a){return n>=a.x && n>=a.y;}
00173
00174 inline FXVec2d veclo(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMIN(a.x,b.x),FXMIN(a.y,b.y));}
00175 inline FXVec2d vechi(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMAX(a.x,b.x),FXMAX(a.y,b.y));}
00176
00177 extern FXAPI FXVec2d vecnormalize(const FXVec2d& v);
00178
00179 extern FXAPI FXStream& operator<<(FXStream& store,const FXVec2d& v);
00180 extern FXAPI FXStream& operator>>(FXStream& store,FXVec2d& v);
00181
00182 }
00183
00184 #endif