diff --git a/inc/hgl/type/Vertex2.cpp b/inc/hgl/type/Vertex2.cpp deleted file mode 100644 index a63d7c4..0000000 --- a/inc/hgl/type/Vertex2.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef HGL_VERTEX_2_CPP -#define HGL_VERTEX_2_CPP - -#include -#include - -namespace hgl -{ - template - void Vertex2::Scale(double vx,double vy,double scale) - { - x=vx+(x-vx)*scale; - y=vy+(y-vy)*scale; - } - - template - void Vertex2::Scale(double vx,double vy,double sx,double sy) - { - x=vx+(x-vx)*sx; - y=vy+(y-vy)*sy; - } - - template template - void Vertex2::Scale(const Vertex2 &v,double scale) - { - x=v.x+(x-v.x)*scale; - y=v.y+(y-v.y)*scale; - } - - template template - void Vertex2::Scale(const Vertex2 &v,double sx,double sy) - { - x=v.x+(x-v.x)*sx; - y=v.y+(y-v.y)*sy; - } - - template - void Vertex2::Rotate(double vx,double vy,double ang) - { - double as,ac; - double nx,ny; - - as=sin(ang*HGL_PI/180.0f); - ac=cos(ang*HGL_PI/180.0f); - - nx=vx+((x-vx)*ac-(y-vy)*as); - ny=vy+((x-vx)*as+(y-vy)*ac); - - x=nx;y=ny; - } - - template - float Vertex2::Length() const - { - return sqrt(x*x+y*y); - } - - template - float Vertex2::Length(float vx,float vy) const - { - float w=x-vx; - float h=y-vy; - - return float(sqrt(double(w*w+h*h))); - } - - template - float Vertex2::Angle(float vx,float vy) const - { - if(vx==x) - { - if(vy>y)return(90); - else return(270); - } - - if(vy==y) - { - if(vx>x)return(0); - else return(180); - } - - // asin 参数范围必须在 -1 到 +1 之间,否则会报错 - // - - double xx=vx-x; - double yy=vy-y; - - double ang = atan(yy/xx)/HGL_PI*180.0f; - - if(xx<0) - return(ang+180); - else - { - if(yy<0) - return(ang+360); - else - return(ang); - } - } - - template template - Vertex2 Vertex2::To(const Vertex2 &target,double pos)const - { - if(pos==0)return(*this);else - if(pos==1)return(target);else - { - Vertex2 result; - - result.x=x+(target.x-x)*pos; - result.y=y+(target.y-y)*pos; - - return(result); - } - } - - template - void Vertex2::Normalize() - { - double size=sqrt(x*x+y*y); - - if(size>0) - { - x/=size; - y/=size; - } - - x=0;y=0; - } - - template template - Vertex2 Vertex2::ResizeLength(const Vertex2 &target,double scale)const - { - Vertex2 result; - - result.x=target.x+(x-target.x)*scale; - result.y=target.y+(y-target.y)*scale; - - return(result); - } - - template template - Vertex2 Vertex2::ToLength(const Vertex2 &target,double new_length)const - { - return ResizeLength(target,new_length/Length(target)); - } -}//namespace hgl -#endif//HGL_VERTEX_2_CPP diff --git a/inc/hgl/type/Vertex2.h b/inc/hgl/type/Vertex2.h deleted file mode 100644 index 1c5ce34..0000000 --- a/inc/hgl/type/Vertex2.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef HGL_VERTEX_2_INCLUDE -#define HGL_VERTEX_2_INCLUDE - -#include -#include -namespace hgl -{ - /** - * 2D顶点坐标类模板 - */ - template class Vertex2 ///XY 2D顶点坐标类模板 - { - public: - - T x,y; ///<坐标值 - - public: - - Vertex2(){x=y=0;} ///<本类构造函数 - Vertex2(T nx,T ny){x=nx,y=ny;} ///<本类构造函数 - template - Vertex2(const Vertex2 &v){x=v.x,y=v.y;} ///<本类构造函数 - - void Zero(){x=0,y=0;} ///<将x和y全清为0 - void One(){x=1,y=1;} ///<将x和y全清为1 - - void Set(float nx,float ny){x=nx,y=ny;} ///<设置坐标值为nx,ny - - void Flip(float vx,float vy){FlipX(vy);FlipY(vx);} ///<对应vx,vy做翻转 - template void Flip(const Vertex2 &v){Flip(v.x,v.y);} ///<对应v做翻转 - - void FlipX(){y=-y;} ///<对应X轴翻转 - void FlipY(){x=-x;} ///<对应Y轴翻转 - void FlipX(float v){y=v-(y-v);} ///<对应指定X轴做翻转 - void FlipY(float v){x=v-(x-v);} ///<对应指定Y轴做翻转 - - void Scale(double,double,double); ///<相对某一点做缩放 - void Scale(double,double,double,double); ///<相对某一点做缩放 - template void Scale(const Vertex2 &,double); ///<相对某一点做缩放 - template void Scale(const Vertex2 &,double,double); ///<相对某一点做指定比例的缩放 - - void Rotate(double,double,double); ///<绕指定坐标旋转指定角度 - template void Rotate(const Vertex2 &v,double ang){Rotate(v.x,v.y,ang);} ///<绕指定坐标旋转指定角度 - - void Move(float vx,float vy){x+=vx;y+=vy;} ///<移动 - template - void Scale(const Vertex2 &v,const Vertex2 &l){Scale(v,l.x,l.y);} ///<相对某一点做指定比例的缩放 - - float Length()const; ///<计算当前点与零点之间的距离 - float Length(float vx,float vy)const; ///<计算当前点与指定点之间的距离 - float Angle(float vx,float vy)const; ///<计算当前点与指定点之间的角度 - - template float Length(const Vertex2 &v)const{return(Length(v.x,v.y));} ///<计算当前点与指定点之间的距离 - template float Angle(const Vertex2 &v)const{return(Angle(v.x,v.y));} ///<计算当前点与指定点之间的角度 - void Normalize(); - - template Vertex2 ResizeLength(const Vertex2 &,double)const; ///<调整这个方向上两点的距离 - template Vertex2 ToLength(const Vertex2 &,double)const; ///<按这个方向将两点的距离调到指定长度 - - template Vertex2 To(const Vertex2 &,double)const; - - public: //操作符重载 - - template bool operator == (const Vertex2 &v)const - { - if(x!=v.x)return(false); - if(y!=v.y)return(false); - return(true); - } - - template bool operator != (const Vertex2 &v)const - { - if(x!=v.x)return(true); - if(y!=v.y)return(true); - return(false); - } - - Vertex2 &operator = (const float *v){x=*v++;y=*v;return *this;} - - template Vertex2 &operator +=(const Vertex2 &v){x+=v.x;y+=v.y;return *this;} - template Vertex2 &operator -=(const Vertex2 &v){x-=v.x;y-=v.y;return *this;} - template Vertex2 &operator *=(const Vertex2 &v){x*=v.x;y*=v.y;return *this;} - template Vertex2 &operator /=(const Vertex2 &v){x/=v.x;y/=v.y;return *this;} - - Vertex2 &operator *=(const float v){x*=v;y*=v;return *this;} - Vertex2 &operator /=(const float v){x/=v;y/=v;return *this;} - - template Vertex2 operator + (const Vertex2 &v)const{return(Vertex2(x+v.x,y+v.y));} - template Vertex2 operator - (const Vertex2 &v)const{return(Vertex2(x-v.x,y-v.y));} - template Vertex2 operator * (const Vertex2 &v)const{return(Vertex2(x*v.x,y*v.y));} - template Vertex2 operator / (const Vertex2 &v)const{return(Vertex2(x/v.x,y/v.y));} - - Vertex2 operator * (const float v)const{return(Vertex2(x*v,y*v));} - Vertex2 operator / (const float v)const{return(Vertex2(x/v,y/v));} - - Vertex2 operator - () const {return(Vertex2(-x,-y));} - - operator T *() const {return(( T *)this);} ///<使得本类可以直接当做T *使用 - operator const T *() const {return((const T *)this);} ///<使得本类可以直接当做const T *使用 - };//class Vertex2 - - typedef Vertex2 Vertex2i; - typedef Vertex2 Vertex2ui; - typedef Vertex2 Vertex2f; - typedef Vertex2 Vertex2d; - - typedef Vertex2 Vertex2b; - typedef Vertex2 Vertex2ub; - typedef Vertex2 Vertex2s; - typedef Vertex2 Vertex2us; -}//namespace hgl -#include -#endif//HGL_VERTEX_2_INCLUDE