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
00029 class FXAPI FXVec2d {
00030 public:
00031 FXdouble x;
00032 FXdouble y;
00033 public:
00034
00036 FXVec2d(){}
00037
00039 FXVec2d(const FXVec2d& v):x(v.x),y(v.y){}
00040
00042 FXVec2d(const FXdouble v[]):x(v[0]),y(v[1]){}
00043
00045 FXVec2d(FXdouble xx,FXdouble yy):x(xx),y(yy){}
00046
00048 FXdouble& operator[](FXint i){return (&x)[i];}
00049
00051 const FXdouble& operator[](FXint i) const {return (&x)[i];}
00052
00054 FXVec2d& operator=(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00055
00057 FXVec2d& operator=(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00058
00060 FXVec2d& set(const FXVec2d& v){x=v.x;y=v.y;return *this;}
00061
00063 FXVec2d& set(const FXdouble v[]){x=v[0];y=v[1];return *this;}
00064
00066 FXVec2d& set(FXdouble xx,FXdouble yy){x=xx;y=yy;return *this;}
00067
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
00075 operator FXdouble*(){return &x;}
00076 operator const FXdouble*() const {return &x;}
00077
00079 FXbool operator!() const { return x==0.0 && y==0.0;}
00080
00082 FXVec2d operator+() const { return *this; }
00083 FXVec2d operator-() const { return FXVec2d(-x,-y); }
00084
00086 FXdouble length2() const { return x*x+y*y; }
00087 FXdouble length() const { return sqrt(length2()); }
00088
00090 FXVec2d& clamp(FXdouble lo,FXdouble hi){ return set(FXCLAMP(lo,x,hi),FXCLAMP(lo,y,hi)); }
00091
00093 ~FXVec2d(){}
00094 };
00095
00096
00098 inline FXdouble operator*(const FXVec2d& a,const FXVec2d& b){ return a.x*b.x+a.y*b.y; }
00099
00101 inline FXVec2d operator*(const FXVec2d& a,FXdouble n){return FXVec2d(a.x*n,a.y*n);}
00102 inline FXVec2d operator*(FXdouble n,const FXVec2d& a){return FXVec2d(n*a.x,n*a.y);}
00103 inline FXVec2d operator/(const FXVec2d& a,FXdouble n){return FXVec2d(a.x/n,a.y/n);}
00104 inline FXVec2d operator/(FXdouble n,const FXVec2d& a){return FXVec2d(n/a.x,n/a.y);}
00105
00107 inline FXVec2d operator+(const FXVec2d& a,const FXVec2d& b){ return FXVec2d(a.x+b.x,a.y+b.y); }
00108 inline FXVec2d operator-(const FXVec2d& a,const FXVec2d& b){ return FXVec2d(a.x-b.x,a.y-b.y); }
00109
00111 inline FXbool operator==(const FXVec2d& a,FXdouble n){return a.x==n && a.y==n;}
00112 inline FXbool operator!=(const FXVec2d& a,FXdouble n){return a.x!=n || a.y!=n;}
00113 inline FXbool operator==(FXdouble n,const FXVec2d& a){return n==a.x && n==a.y;}
00114 inline FXbool operator!=(FXdouble n,const FXVec2d& a){return n!=a.x || n!=a.y;}
00115
00117 inline FXbool operator==(const FXVec2d& a,const FXVec2d& b){ return a.x==b.x && a.y==b.y; }
00118 inline FXbool operator!=(const FXVec2d& a,const FXVec2d& b){ return a.x!=b.x || a.y!=b.y; }
00119
00121 inline FXbool operator<(const FXVec2d& a,FXdouble n){return a.x<n && a.y<n;}
00122 inline FXbool operator<=(const FXVec2d& a,FXdouble n){return a.x<=n && a.y<=n;}
00123 inline FXbool operator>(const FXVec2d& a,FXdouble n){return a.x>n && a.y>n;}
00124 inline FXbool operator>=(const FXVec2d& a,FXdouble n){return a.x>=n && a.y>=n;}
00125
00127 inline FXbool operator<(FXdouble n,const FXVec2d& a){return n<a.x && n<a.y;}
00128 inline FXbool operator<=(FXdouble n,const FXVec2d& a){return n<=a.x && n<=a.y;}
00129 inline FXbool operator>(FXdouble n,const FXVec2d& a){return n>a.x && n>a.y;}
00130 inline FXbool operator>=(FXdouble n,const FXVec2d& a){return n>=a.x && n>=a.y;}
00131
00133 inline FXbool operator<(const FXVec2d& a,const FXVec2d& b){ return a.x<b.x && a.y<b.y; }
00134 inline FXbool operator<=(const FXVec2d& a,const FXVec2d& b){ return a.x<=b.x && a.y<=b.y; }
00135 inline FXbool operator>(const FXVec2d& a,const FXVec2d& b){ return a.x>b.x && a.y>b.y; }
00136 inline FXbool operator>=(const FXVec2d& a,const FXVec2d& b){ return a.x>=b.x && a.y>=b.y; }
00137
00139 inline FXVec2d lo(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMIN(a.x,b.x),FXMIN(a.y,b.y));}
00140 inline FXVec2d hi(const FXVec2d& a,const FXVec2d& b){return FXVec2d(FXMAX(a.x,b.x),FXMAX(a.y,b.y));}
00141
00143 extern FXAPI FXVec2d normalize(const FXVec2d& v);
00144
00146 extern FXAPI FXVec2d lerp(const FXVec2d& u,const FXVec2d& v,FXdouble f);
00147
00149 extern FXAPI FXStream& operator<<(FXStream& store,const FXVec2d& v);
00150
00152 extern FXAPI FXStream& operator>>(FXStream& store,FXVec2d& v);
00153
00154 }
00155
00156 #endif