00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXVEC2D_H
00022 #define FXVEC2D_H
00023
00024
00025 namespace FX {
00026
00027
00028
00029 class FXAPI FXVec2d {
00030 public:
00031 FXdouble x;
00032 FXdouble y;
00033 public:
00034
00035
00036 FXVec2d(){}
00037
00038
00039 FXVec2d(const FXVec2d& v):x(v.x),y(v.y){}
00040
00041
00042 FXVec2d(const FXdouble v[]):x(v[0]),y(v[1]){}
00043
00044
00045 FXVec2d(FXdouble xx,FXdouble yy):x(xx),y(yy){}
00046
00047
00048 FXdouble& operator[](FXint i){return (&x)[i];}
00049
00050
00051 const FXdouble& operator[](FXint i) const {return (&x)[i];}
00052
00053
00054 FXVec2d& operator=(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00055
00056
00057 FXVec2d& operator=(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00058
00059
00060 FXVec2d& set(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00061
00062
00063 FXVec2d& set(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00064
00065
00066 FXVec2d& set(FXdouble xx,FXdouble yy){x=xx;y=yy;return *this;}
00067
00068
00069 FXVec2d& operator*=(FXdouble n){ return set(x*n,y*n); }
00070 FXVec2d& operator/=(FXdouble n){ return set(x/n,y/n); }
00071 FXVec2d& operator+=(const FXVec2d& v){ return set(x+v.x,y+v.y); }
00072 FXVec2d& operator-=(const FXVec2d& v){ return set(x-v.x,y-v.y); }
00073
00074
00075 operator FXdouble*(){return &x;}
00076 operator const FXdouble*() const {return &x;}
00077
00078
00079 FXbool operator!() const { return x==0.0 && y==0.0;}
00080
00081
00082 FXVec2d operator+() const { return *this; }
00083 FXVec2d operator-() const { return FXVec2d(-x,-y); }
00084
00085
00086 FXdouble length2() const { return x*x+y*y; }
00087 FXdouble length() const { return sqrt(length2()); }
00088
00089
00090 FXVec2d& clamp(FXdouble lo,FXdouble hi){ return set(FXCLAMP(lo,x,hi),FXCLAMP(lo,y,hi)); }
00091 };
00092
00093
00094
00095 inline FXdouble operator*(const FXVec2d& a,const FXVec2d& b){ return a.x*b.x+a.y*b.y; }
00096
00097
00098 inline FXVec2d operator*(const FXVec2d& a,FXdouble n){return FXVec2d(a.x*n,a.y*n);}
00099 inline FXVec2d operator*(FXdouble n,const FXVec2d& a){return FXVec2d(n*a.x,n*a.y);}
00100 inline FXVec2d operator/(const FXVec2d& a,FXdouble n){return FXVec2d(a.x/n,a.y/n);}
00101 inline FXVec2d operator/(FXdouble n,const FXVec2d& a){return FXVec2d(n/a.x,n/a.y);}
00102
00103
00104 inline FXVec2d operator+(const FXVec2d& a,const FXVec2d& b){ return FXVec2d(a.x+b.x,a.y+b.y); }
00105 inline FXVec2d operator-(const FXVec2d& a,const FXVec2d& b){ return FXVec2d(a.x-b.x,a.y-b.y); }
00106
00107
00108 inline FXbool operator==(const FXVec2d& a,FXdouble n){return a.x==n && a.y==n;}
00109 inline FXbool operator!=(const FXVec2d& a,FXdouble n){return a.x!=n || a.y!=n;}
00110 inline FXbool operator==(FXdouble n,const FXVec2d& a){return n==a.x && n==a.y;}
00111 inline FXbool operator!=(FXdouble n,const FXVec2d& a){return n!=a.x || n!=a.y;}
00112
00113
00114 inline FXbool operator==(const FXVec2d& a,const FXVec2d& b){ return a.x==b.x && a.y==b.y; }
00115 inline FXbool operator!=(const FXVec2d& a,const FXVec2d& b){ return a.x!=b.x || a.y!=b.y; }
00116
00117
00118 inline FXbool operator<(const FXVec2d& a,FXdouble n){return a.x<n && a.y<n;}
00119 inline FXbool operator<=(const FXVec2d& a,FXdouble n){return a.x<=n && a.y<=n;}
00120 inline FXbool operator>(const FXVec2d& a,FXdouble n){return a.x>n && a.y>n;}
00121 inline FXbool operator>=(const FXVec2d& a,FXdouble n){return a.x>=n && a.y>=n;}
00122
00123
00124 inline FXbool operator<(FXdouble n,const FXVec2d& a){return n<a.x && n<a.y;}
00125 inline FXbool operator<=(FXdouble n,const FXVec2d& a){return n<=a.x && n<=a.y;}
00126 inline FXbool operator>(FXdouble n,const FXVec2d& a){return n>a.x && n>a.y;}
00127 inline FXbool operator>=(FXdouble n,const FXVec2d& a){return n>=a.x && n>=a.y;}
00128
00129
00130 inline FXbool operator<(const FXVec2d& a,const FXVec2d& b){ return a.x<b.x && a.y<b.y; }
00131 inline FXbool operator<=(const FXVec2d& a,const FXVec2d& b){ return a.x<=b.x && a.y<=b.y; }
00132 inline FXbool operator>(const FXVec2d& a,const FXVec2d& b){ return a.x>b.x && a.y>b.y; }
00133 inline FXbool operator>=(const FXVec2d& a,const FXVec2d& b){ return a.x>=b.x && a.y>=b.y; }
00134
00135
00136 inline FXVec2d lo(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMIN(a.x,b.x),FXMIN(a.y,b.y));}
00137 inline FXVec2d hi(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMAX(a.x,b.x),FXMAX(a.y,b.y));}
00138
00139
00140 extern FXAPI FXVec2d normalize(const FXVec2d& v);
00141
00142
00143 extern FXAPI FXStream& operator<<(FXStream& store,const FXVec2d& v);
00144
00145
00146 extern FXAPI FXStream& operator>>(FXStream& store,FXVec2d& v);
00147
00148 }
00149
00150 #endif