point.cpp
Go to the documentation of this file.
00001 #include "hexagon_map/point.h"
00002 #include <math.h>
00003 
00006 CPoint2d::CPoint2d(void)
00007 :x(0.0),y(0.0),pointangle(0.0)
00008 {
00009 }
00010 
00011 CPoint2d::CPoint2d(float x,float y)
00012 {
00013         this->x = x;
00014         this->y = y;
00015 }
00016 
00017 // 析构函数
00018 CPoint2d::~CPoint2d(void)
00019 {
00020 }
00021 
00022 // 复制构造函数
00023 CPoint2d::CPoint2d(const CPoint2d& tmpP)
00024 {
00025         this->x = tmpP.x;
00026         this->y = tmpP.y;
00027         this->pointangle = tmpP.pointangle;     
00028 }
00029 
00032 CPoint2d & CPoint2d::operator += ( const CPoint2d & p)
00033 {
00034         this->x += p.x;
00035         this->y += p.y;
00036         return *this;
00037 }
00038 CPoint2d & CPoint2d::operator -= (const CPoint2d & p)
00039 {
00040         this->x -= p.x;
00041         this->y -= p.y;
00042         return *this;
00043 }
00044 CPoint2d & CPoint2d::operator *= (float s )
00045 {
00046         this->x *= s;
00047         this->y *= s;
00048         return *this;
00049 }
00050 CPoint2d & CPoint2d::operator /= (float s )
00051 {
00052         this->x /= s;
00053         this->y /= s;
00054         return *this;
00055 }
00056 
00057 // 重载运算符为友元函数
00058 CPoint2d operator + (const CPoint2d &p1 ,const CPoint2d &p2)    // 相加
00059 {       
00060         CPoint2d po;
00061         po.x = p1.x + p2.x;
00062         po.y = p1.y + p2.y;
00063         return po;
00064 }
00065 CPoint2d operator - (const CPoint2d &p1 ,const CPoint2d &p2)    // 
00066 {       
00067         CPoint2d po;
00068         po.x = p1.x - p2.x;
00069         po.y = p1.y - p2.y;
00070         return po;
00071 }
00072 CPoint2d operator * ( const CPoint2d &p , float s )
00073 {
00074         CPoint2d po;
00075         po.x = p.x * s;
00076         po.y = p.y * s;
00077         return po;
00078 }
00079 double operator * ( const CPoint2d &p1 ,const CPoint2d &p2 )
00080 {
00081         return ( p1.x*p2.x + p1.y*p2.y );
00082 }
00083 CPoint2d operator / (const CPoint2d &p ,float num)                      // 除以一个整数
00084 {               
00085         if(num != 0)
00086         {   
00087                 CPoint2d po;
00088                 po.x = p.x / num;
00089                 po.y = p.y / num;
00090                 return po;
00091         }
00092         else 
00093         {
00094                 return CPoint2d(0,0);
00095         }
00096 }
00097 
00098 bool operator == (const CPoint2d &p1,const CPoint2d &p2)        // 相等
00099 {
00100         if(p1.x==p2.x && p1.y==p2.y )
00101                 return true;
00102         else 
00103                 return false;
00104 }
00105 bool operator != (const CPoint2d &p1,const CPoint2d &p2)        // 不等
00106 {
00107         if(p1.x==p2.x && p1.y==p2.y)
00108                 return false;
00109         else 
00110                 return true;
00111 }
00112 
00114 // 点到原点的距离
00115 //double CPoint2d::Dist(void)
00116 //{
00117 //      return sqrt(x*x+y*y);
00118 //}
00119 
00120 // 点到另一个点的距离
00121 float CPoint2d::Dist(const CPoint2d &p)
00122 {
00123         return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
00124 }
00125 


hexagon_map
Author(s):
autogenerated on Thu Jun 6 2019 18:38:28