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
00032 class FXAPI FXVec2d {
00033 public:
00034 FXdouble x;
00035 FXdouble y;
00036 public:
00037
00038
00039 FXVec2d(){}
00040
00041
00042 FXVec2d(const FXVec2d& v){x=v.x;y=v.y;}
00043
00044
00045 FXVec2d(const FXdouble v[]){x=v[0];y=v[1];}
00046
00047
00048 FXVec2d(FXdouble xx,FXdouble yy){x=xx;y=yy;}
00049
00050
00051 FXdouble& operator[](FXint i){return (&x)[i];}
00052
00053
00054 const FXdouble& operator[](FXint i) const {return (&x)[i];}
00055
00056
00057 FXVec2d& operator=(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00058
00059
00060 FXVec2d& operator=(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00061
00062
00063 FXVec2d& operator*=(FXdouble n){x*=n;y*=n;return *this;}
00064 FXVec2d& operator/=(FXdouble n){x/=n;y/=n;return *this;}
00065 FXVec2d& operator+=(const FXVec2d& v){x+=v.x;y+=v.y;return *this;}
00066 FXVec2d& operator-=(const FXVec2d& v){x-=v.x;y-=v.y;return *this;}
00067
00068
00069 operator FXdouble*(){return &x;}
00070 operator const FXdouble*() const {return &x;}
00071
00072
00073 friend FXAPI FXVec2d operator+(const FXVec2d& v){return v;}
00074 friend FXAPI FXVec2d operator-(const FXVec2d& v){return FXVec2d(-v.x,-v.y);}
00075
00076
00077 friend FXAPI FXVec2d operator+(const FXVec2d& a,const FXVec2d& b){return FXVec2d(a.x+b.x,a.y+b.y);}
00078 friend FXAPI FXVec2d operator-(const FXVec2d& a,const FXVec2d& b){return FXVec2d(a.x-b.x,a.y-b.y);}
00079
00080
00081 friend FXAPI FXVec2d operator*(const FXVec2d& a,FXdouble n){return FXVec2d(a.x*n,a.y*n);}
00082 friend FXAPI FXVec2d operator*(FXdouble n,const FXVec2d& a){return FXVec2d(n*a.x,n*a.y);}
00083 friend FXAPI FXVec2d operator/(const FXVec2d& a,FXdouble n){return FXVec2d(a.x/n,a.y/n);}
00084 friend FXAPI FXVec2d operator/(FXdouble n,const FXVec2d& a){return FXVec2d(n/a.x,n/a.y);}
00085
00086
00087 friend FXAPI FXdouble operator*(const FXVec2d& a,const FXVec2d& b){return a.x*b.x+a.y*b.y;}
00088
00089
00090 friend FXAPI int operator!(const FXVec2d& a){return a.x==0.0 && a.y==0.0;}
00091
00092
00093 friend FXAPI int operator==(const FXVec2d& a,const FXVec2d& b){return a.x==b.x && a.y==b.y;}
00094 friend FXAPI int operator!=(const FXVec2d& a,const FXVec2d& b){return a.x!=b.x || a.y!=b.y;}
00095
00096 friend FXAPI int operator==(const FXVec2d& a,FXdouble n){return a.x==n && a.y==n;}
00097 friend FXAPI int operator!=(const FXVec2d& a,FXdouble n){return a.x!=n || a.y!=n;}
00098
00099 friend FXAPI int operator==(FXdouble n,const FXVec2d& a){return n==a.x && n==a.y;}
00100 friend FXAPI int operator!=(FXdouble n,const FXVec2d& a){return n!=a.x || n!=a.y;}
00101
00102
00103 friend FXAPI int operator<(const FXVec2d& a,const FXVec2d& b){return a.x<b.x && a.y<b.y;}
00104 friend FXAPI int operator<=(const FXVec2d& a,const FXVec2d& b){return a.x<=b.x && a.y<=b.y;}
00105 friend FXAPI int operator>(const FXVec2d& a,const FXVec2d& b){return a.x>b.x && a.y>b.y;}
00106 friend FXAPI int operator>=(const FXVec2d& a,const FXVec2d& b){return a.x>=b.x && a.y>=b.y;}
00107
00108 friend FXAPI int operator<(const FXVec2d& a,FXdouble n){return a.x<n && a.y<n;}
00109 friend FXAPI int operator<=(const FXVec2d& a,FXdouble n){return a.x<=n && a.y<=n;}
00110 friend FXAPI int operator>(const FXVec2d& a,FXdouble n){return a.x>n && a.y>n;}
00111 friend FXAPI int operator>=(const FXVec2d& a,FXdouble n){return a.x>=n && a.y>=n;}
00112
00113 friend FXAPI int operator<(FXdouble n,const FXVec2d& a){return n<a.x && n<a.y;}
00114 friend FXAPI int operator<=(FXdouble n,const FXVec2d& a){return n<=a.x && n<=a.y;}
00115 friend FXAPI int operator>(FXdouble n,const FXVec2d& a){return n>a.x && n>a.y;}
00116 friend FXAPI int operator>=(FXdouble n,const FXVec2d& a){return n>=a.x && n>=a.y;}
00117
00118
00119 friend FXAPI FXdouble len2(const FXVec2d& a){ return a.x*a.x+a.y*a.y; }
00120 friend FXAPI FXdouble len(const FXVec2d& a){ return sqrt(len2(a)); }
00121
00122
00123 friend FXAPI FXVec2d normalize(const FXVec2d& a);
00124
00125
00126 friend FXAPI FXVec2d lo(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMIN(a.x,b.x),FXMIN(a.y,b.y));}
00127 friend FXAPI FXVec2d hi(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMAX(a.x,b.x),FXMAX(a.y,b.y));}
00128
00129
00130 friend FXAPI FXStream& operator<<(FXStream& store,const FXVec2d& v);
00131
00132
00133 friend FXAPI FXStream& operator>>(FXStream& store,FXVec2d& v);
00134 };
00135
00136 }
00137
00138 #endif