Compare.h
GEOMETRIC_BEGIN
/*! \fn
* 函数功能:判断字符串是否一个合法的数字(包括科学记数法形式) \n
* 输入参数:const CString &numStr, int* pStatus = NULL \n
* 输出参数:int* pStatu \n
* 返 回 值:int型变量 0,表示是一个数字;非0 为出错位置 ;\n
*/
GEOMETRIC_EXT int IsNotLegalNum(const CString &numStr, int* pStatus = NULL);
/*! \fn
* 函数功能:不区分大小写比较2字符串
* 输入参数:lhs,rhs-需比较的字符串
* 输出参数:void
* 返 回 值:2字符完全相同,返回0;如果lhs中有字符在rhs的前面,则返回-1,否则返回1
*/
GEOMETRIC_EXT inline int Cmp_NoCase(const CString& lhs,const CString& rhs);
/*! \fn
* 函数功能:判断矢量是否在-pi与pi之间 \n
* 输入参数:double x, double y, double startAng, double endAng (要求startAng, endAng在(-PI, PI]之间) \n
* 输出参数:无 \n
* 返 回 值:TRUE or FALSE \n
*/
GEOMETRIC_EXT bool IsVectorBetweenRadAngs(double x, double y, double startAng, double endAng);
/*! \fn
* 函数功能:判断角度是否落在一个扇形区域内 \n
* 输入参数:angle:需判断的角度, startAng:扇区起始角度,
* sweepAng:扫过的角度(-2PI~2PI,正时为逆时针, 为负时表示顺时针)\n
* 要求angle,startAng在[-PI,PI]之间
* 输出参数:无 \n
* 返 回 值:TRUE or FASLE \n
*/
GEOMETRIC_EXT bool IsAngleInSector(double angle, double startAng, double sweepAng);
/*!<把角度规范化到[0,2PI)之间*/
GEOMETRIC_EXT double NormalizeAngle(double angle);
/*!< 和自己比较取小值*/
template<class _Ty> inline void MinSelf(_Ty &self,const _Ty &comp) { self = min(self,comp); }
/*!<和自己比较取大值*/
template<class _Ty> inline void MaxSelf(_Ty &self,const _Ty &comp) { self = max(self,comp); }
//////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// 浮点数比较 /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
template<typename Real> inline bool Compare(const Real val1, const Real val2) { return fabs(val2-val1) < FLT_MIN_VALUE; }
// a==b
GEOMETRIC_EXT inline bool Equal2Dbl(double val1,double val2=0) { return fabs(val2-val1) < MIN_VALUE; }
// a==b with precision
GEOMETRIC_EXT inline bool Equal2DblEx(double val1,double val2,double dEps=MIN_VALUE) { return fabs(val2-val1) < dEps; }
// a!=b
GEOMETRIC_EXT inline bool DblNotEqual(double a,double b,double dEps=MIN_VALUE) { return !Equal2DblEx(a, b, dEps); }
// a<b
GEOMETRIC_EXT inline bool DblLT(double a,double b,double dEps=MIN_VALUE) { return DblNotEqual(a, b,dEps) && (a<b);}
// a<=b
GEOMETRIC_EXT inline bool DblLE(double a,double b,double dEps=MIN_VALUE) { return Equal2DblEx(a, b,dEps)||DblLT(a, b);}
// a>b
GEOMETRIC_EXT inline bool DblGT(double a,double b,double dEps=MIN_VALUE) { return DblNotEqual(a, b,dEps) && (a>b);}
// a>=b
GEOMETRIC_EXT inline bool DblGE(double a,double b,double dEps=MIN_VALUE) { return Equal2DblEx(a, b,dEps) || DblGT(a, b);}
GEOMETRIC_EXT inline bool EqualToPairDbl(const pair<double,double> &pairobj1,const pair<double,double> &pairobj2)
{
return (Equal2Dbl(pairobj1.first,pairobj2.first) && Equal2Dbl(pairobj1.second,pairobj2.second));
}
GEOMETRIC_EXT inline bool EqualToPairCStr(const pair<CString,CString> &pairobj1,const pair<CString,CString> &pairobj2)
{
return (pairobj1.first == pairobj2.first) && (pairobj1.second == pairobj2.second);
}
GEOMETRIC_EXT inline bool EqualToPairDword(const pair<DWORD,DWORD> &pairobj1,const pair<DWORD,DWORD> &pairobj2)
{
return (pairobj1.first == pairobj2.first) && (pairobj1.second == pairobj2.second);
}
GEOMETRIC_EXT inline bool EqualToPairIntDbl(const pair<int,double> &pairobj1,const pair<int,double> &pairobj2)
{
return (pairobj1.first != pairobj2.first && Equal2Dbl(pairobj1.second,pairobj2.second));
}
GEOMETRIC_EXT inline bool Equal2vctDbl(const vctDbl& val1,const vctDbl& val2)
{
if(val1.size()!=val2.size()) return false;
bool bRst=equal(val1.begin(),val1.end(),val2.begin(),Equal2Dbl);
return bRst;
}
GEOMETRIC_EXT inline bool EqualToVectorPairDbl(const std::vector<pair<double,double>>& vctobj1,const vector<pair<double,double>>& vctobj2)
{
std::vector<pair<double,double>>::const_iterator vit1 = vctobj1.begin();
std::vector<pair<double,double>>::const_iterator vit2 = vctobj2.begin();
while(vit1 != vctobj1.end() && vit2 != vctobj2.end())
{
if(!EqualToPairDbl(*(vit1),*(vit2)))
break;
++vit1;
++vit2;
}
return (vit1==vctobj1.end() && vit2==vctobj2.end());
}
GEOMETRIC_EXT inline bool EqualToVectorPairCStr(const std::vector<pair<CString,CString>>& vctobj1,const vector<pair<CString,CString>>& vctobj2)
{
std::vector<pair<CString,CString>>::const_iterator vit1 = vctobj1.begin();
std::vector<pair<CString,CString>>::const_iterator vit2 = vctobj2.begin();
while(vit1 != vctobj1.end() && vit2 != vctobj2.end())
{
if(!EqualToPairCStr(*(vit1),*(vit2)))
break;
++vit1;
++vit2;
}
return (vit1==vctobj1.end() && vit2==vctobj2.end());
}
GEOMETRIC_EXT inline bool EqualToVectorIntDbl(const std::vector<pair<int,double>>& vctobj1,const vector<pair<int,double>>& vctobj2)
{
std::vector<pair<int,double>>::const_iterator vit1 = vctobj1.begin();
std::vector<pair<int,double>>::const_iterator vit2 = vctobj2.begin();
while(vit1 != vctobj1.end() && vit2 != vctobj2.end())
{
if(!EqualToPairIntDbl(*(vit1),*(vit2)))
break;
++vit1;
++vit2;
}
return (vit1==vctobj1.end() && vit2==vctobj2.end());
}
GEOMETRIC_EXT inline bool EqualToMapPairDbl(const map<UINT,pair<double,double>>& mapobj1,const map<UINT,pair<double,double>>& mapobj2)
{
std::map<UINT,pair<double,double>>::const_iterator mit1 = mapobj1.begin();
std::map<UINT,pair<double,double>>::const_iterator mit2 = mapobj2.begin();
while(mit1 != mapobj1.end() && mit2 != mapobj2.end())
{
if(!(mit1->first == mit2->first))
break;
if(!EqualToPairDbl(mit1->second,mit2->second))
break;
++mit1;
++mit2;
}
return (mit1==mapobj1.end() && mit2==mapobj2.end());
}
GEOMETRIC_EXT inline bool EqualToMapPairCStr(const map<CString,pair<CString,CString>>& mapobj1,const map<CString,pair<CString,CString>>& mapobj2)
{
std::map<CString,pair<CString,CString>>::const_iterator mit1 = mapobj1.begin();
std::map<CString,pair<CString,CString>>::const_iterator mit2 = mapobj2.begin();
while(mit1 != mapobj1.end() && mit2 != mapobj2.end())
{
if(!(mit1->first == mit2->first))
break;
if(!EqualToPairCStr(mit1->second,mit2->second))
break;
++mit1;
++mit2;
}
return (mit1==mapobj1.end() && mit2==mapobj2.end());
}
GEOMETRIC_EXT inline bool EqualToMapPairDword(const map<UINT,std::pair<DWORD,DWORD>>& mapobj1,const map<UINT,std::pair<DWORD,DWORD>>& mapobj2)
{
std::map<UINT,std::pair<DWORD,DWORD>>::const_iterator mit1 = mapobj1.begin();
std::map<UINT,std::pair<DWORD,DWORD>>::const_iterator mit2 = mapobj2.begin();
while(mit1 != mapobj1.end() && mit2 != mapobj2.end())
{
if(!(mit1->first == mit2->first))
break;
if(!(EqualToPairDword(mit1->second,mit2->second)))
break;
++mit1;
++mit2;
}
return (mit1==mapobj1.end() && mit2==mapobj2.end());
}
GEOMETRIC_EXT inline bool EqualToMapVectorPairDbl(const map<int,vector<pair<double,double>>>& mapobj1,const map<int,vector<pair<double,double>>>& mapobj2)
{
std::map<int,vector<pair<double,double>>>::const_iterator mit1 = mapobj1.begin();
std::map<int,vector<pair<double,double>>>::const_iterator mit2 = mapobj2.begin();
while(mit1 != mapobj1.end() && mit2 != mapobj2.end())
{
if(!(mit1->first == mit2->first))
break;
if(!EqualToVectorPairDbl(mit1->second,mit2->second))
break;
++mit1;
++mit2;
}
return (mit1==mapobj1.end() && mit2==mapobj2.end());
}
/*!<比较两个vector类对象指针形式存在时是否相等*/
template<class T> inline bool EqualToVectorEX(const std::vector<T>& vctobj1,const std::vector<T>& vctobj2)
{
vector<T>::const_iterator vit1 = vctobj1.begin();
vector<T>::const_iterator vit2 = vctobj2.begin();
while(vit1 != vctobj1.end() && vit2 != vctobj2.end())
{
if(!(*(*vit1) == *(*vit2)))
break;
++vit1;
++vit2;
}
return (vit1==vctobj1.end() && vit2==vctobj2.end());
}
inline bool EqualToVectorDbl(const std::vector<double>& vctobj1,const std::vector<double>& vctobj2)
{
vector<double>::const_iterator vit1 = vctobj1.begin();
vector<double>::const_iterator vit2 = vctobj2.begin();
while(vit1 != vctobj1.end() && vit2 != vctobj2.end())
{
if(!Equal2Dbl(*(vit1),*(vit2)))
break;
++vit1;
++vit2;
}
return (vit1==vctobj1.end() && vit2==vctobj2.end());
}
/*!<比较两个list类对象指针形式存在时是否相等*/
template<class T> inline bool EqualToListEX(const std::list<T>& lstobj1,const std::list<T>& lstobj2)
{
list<T>::const_iterator lit1 = lstobj1.begin();
list<T>::const_iterator lit2 = lstobj2.begin();
while(lit1 != lstobj1.end() && lit2 != lstobj2.end())
{
if(!(*(*lit1) == *(*lit2)))
break;
++lit1;
++lit2;
}
return (lit1==lstobj1.end() && lit2==lstobj2.end());
}
//!map<UINT,Class T> 类型判断相等
template<typename _Ty,class T> inline bool EqualToMapEX(const std::map<_Ty,T>& mapobj1,const std::map<_Ty,T>& mapobj2)
{
std::map<_Ty,T>::const_iterator vit1 = mapobj1.begin();
std::map<_Ty,T>::const_iterator vit2 = mapobj2.begin();
while(vit1 != mapobj1.end() && vit2 != mapobj2.end())
{
if(!(vit1->first == vit2->first))
break;
if(!(*(vit1->second) == *(vit2->second)))
break;
++vit1;
++vit2;
}
return (vit1==mapobj1.end() && vit2==mapobj2.end());
}
template<typename _Tx,class _Ty> inline bool EqualToMap(const std::map<_Tx,_Ty>& mapobj1,const std::map<_Tx,_Ty>& mapobj2)
{
std::map<_Tx,_Ty>::const_iterator vit1 = mapobj1.begin();
std::map<_Tx,_Ty>::const_iterator vit2 = mapobj2.begin();
while(vit1 != mapobj1.end() && vit2 != mapobj2.end())
{
if(!(vit1->first == vit2->first))
break;
if(!(vit1->second == vit2->second))
break;
++vit1;
++vit2;
}
return (vit1==mapobj1.end() && vit2==mapobj2.end());
}
template<class _Ty> inline bool EqualToVector(const std::vector<_Ty>& vctobj1,const std::vector<_Ty>& vctobj2)
{
if(vctobj1.size()!=vctobj2.size())
return false;
std::vector<_Ty>::const_iterator vit1 = vctobj1.begin();
std::vector<_Ty>::const_iterator vit2 = vctobj2.begin();
while(vit1 != vctobj1.end() && vit2 != vctobj2.end())
{
if(!(*vit1 == *vit2))
break;
++vit1;
++vit2;
}
return (vit1==vctobj1.end() && vit2==vctobj2.end());
}
template<typename _Kty,typename _Ty> inline bool EqualToMapVetorEx(const std::map<_Kty, std::vector<_Ty*> >& mapTs1,const std::map<_Kty, std::vector<_Ty*> >& mapTs2)
{
std::map<_Kty, std::vector<_Ty*> >::const_iterator vit1 = mapTs1.begin();
std::map<_Kty, std::vector<_Ty*> >::const_iterator vit2 = mapTs2.begin();
while(vit1 != mapTs1.end() && vit2 != mapTs2.end())
{
if(!(vit1->first == vit2->first))
break;
if(!EqualToVectorEX(vit1->second,vit2->second))
break;
++vit1;
++vit2;
}
return (vit1==mapTs1.end() && vit2==mapTs2.end());
}
template<typename _Kty,typename _Ty> inline bool EqualToMapVetorEx(const std::map<_Kty, std::vector<_Ty> >& mapTs1,const std::map<_Kty, std::vector<_Ty> >& mapTs2)
{
std::map<_Kty, std::vector<_Ty> >::const_iterator vit1 = mapTs1.begin();
std::map<_Kty, std::vector<_Ty> >::const_iterator vit2 = mapTs2.begin();
while(vit1 != mapTs1.end() && vit2 != mapTs2.end())
{
if(!(vit1->first == vit2->first))
break;
if(!EqualToVector(vit1->second,vit2->second))
break;
++vit1;
++vit2;
}
return (vit1==mapTs1.end() && vit2==mapTs2.end());
}
/*! \fn
* 函数功能:判断两个点是否相同 \n
* 输入参数:const McGePoint2d& val1,const McGePoint2d& val2 \n
* 输出参数:bool型变量 \n
* 返 回 值:TRUEorFALSE \n
*/
GEOMETRIC_EXT inline bool Equal2Point(const McGePoint2d& val1,const McGePoint2d& val2)
{
return val1==val2;
}
GEOMETRIC_EXT bool Equal2vctPoints(const vctMcGePoint2ds& points1, const vctMcGePoint2ds& points2);
/*! \fn
* 函数功能:判断两个点是否相同 可以设置精度 \n
* 输入参数:const McGePoint2d& val1,const McGePoint2d& val2 \n
* 输出参数:bool型变量 \n
* 返 回 值:TRUEorFALSE \n
*/
GEOMETRIC_EXT inline bool Equal2PointEx(const McGePoint2d& val1,const McGePoint2d& val2,double dEps=MIN_VALUE)
{
if (!Equal2DblEx(val1.GetX(), val2.GetX(), dEps))
return false;
if (!Equal2DblEx(val1.GetY(), val2.GetY(), dEps))
return false;
return true;
}
/*! \fn
* 函数功能:判断两个点组是否相同 \n
* 输入参数:const vctMcGePoint2ds& val1,const vctMcGePoint2ds& val2 \n
* 输出参数:bool型变量 \n
* 返 回 值:TRUEorFALSE \n
*/
GEOMETRIC_EXT inline bool Equal2vctPoint(const vctMcGePoint2ds& val1,const vctMcGePoint2ds& val2)
{
if(val1.size()!=val2.size())
return false;
bool bRst=equal(val1.begin(),val1.end(),val2.begin(),Equal2Point);
return bRst;
}
GEOMETRIC_EXT inline bool Equal2Polyline(const McGePolyline2d& val1,const McGePolyline2d& val2)
{
return val1==val2;
}
GEOMETRIC_EXT inline bool Equal2vctPolyline(const vector<McGePolyline2d>& val1,const vector<McGePolyline2d>& val2)
{
if(val1.size()!=val2.size())
return false;
bool bRst=equal(val1.begin(),val1.end(),val2.begin(),Equal2Polyline);
return bRst;
}
/*! \class: McGePoint2d_LessX
* 功能说明:用于排序点,按X坐标从小到大\n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:44:04 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class GEOMETRIC_EXT McGePoint2d_LessX //用于排序点,按X坐标从小到大
:public binary_function<McGePoint2d,McGePoint2d,bool>
{
public:
bool operator ()(const McGePoint2d& pt1,const McGePoint2d& pt2) const
{
if(Equal2Dbl(pt1.x,pt2.x))
{
if(pt1.y<pt2.y)
return true;
else
return false;
}
else
{
if(pt1.x < pt2.x)
return pt1.x < pt2.x;
else
return false;
}
}
~McGePoint2d_LessX(void){};
McGePoint2d_LessX(void){};
};
class GEOMETRIC_EXT McGePoint2d_LessXGreatY //用于排序点,按X坐标从小到大,Y从大到小
:public binary_function<McGePoint2d,McGePoint2d,bool>
{
public:
bool operator ()(const McGePoint2d& pt1,const McGePoint2d& pt2) const
{
if(Equal2Dbl(pt1.x,pt2.x))
{
if(DblGT(pt1.y,pt2.y))
return true;
else
return false;
}
else
{
if(DblLT(pt1.x,pt2.x))
return true;
else
return false;
}
}
~McGePoint2d_LessXGreatY(void){};
McGePoint2d_LessXGreatY(void){};
};
/*! \class: McGePoint2d_LessY
* 功能说明:用于排序点,按Y坐标从小到大 \n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:44:41 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class GEOMETRIC_EXT McGePoint2d_LessY //用于排序点,按Y坐标从小到大
:public binary_function<McGePoint2d,McGePoint2d,bool>
{
public:
bool operator ()(const McGePoint2d& pt1,const McGePoint2d& pt2) const
{
if(Equal2Dbl(pt1.y,pt2.y)) //相等
{
if(pt1.x<pt2.x)
return true;
else
return false;
}
else
{
if(pt1.y < pt2.y)
return true;
else
return false;
}
}
~McGePoint2d_LessY(void){};
McGePoint2d_LessY(void){};
};
class /* GEOMETRIC_EXT*/ McGePoint2d_GreaterX //用于排序点,按X坐标从大到小
{
public:
bool operator ()(const McGePoint2d& pt1,const McGePoint2d& pt2) const
{
if(Equal2Dbl(pt1.x,pt2.x))
{
return pt1.y > pt2.y;
}
else
{
return pt1.x > pt2.x;
}
}
~McGePoint2d_GreaterX(void){};
McGePoint2d_GreaterX(void){};
};
/*! \class: McGePoint2d_LessY()
* 功能说明:用于排序点,按Y坐标从大到小 \n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:44:41 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class /* GEOMETRIC_EXT*/ McGePoint2d_GreaterVertexY //用于排序点,按Y坐标从大到小
{
public:
bool operator ()(const CVertex2d& pt1,const CVertex2d& pt2) const
{
if(Equal2Dbl(pt1.m_pt.y,pt2.m_pt.y)) //相等
{
return (pt1.m_pt.x > pt2.m_pt.x);
}
else
{
return(pt1.m_pt.y > pt2.m_pt.y);
}
}
~McGePoint2d_GreaterVertexY(void){};
McGePoint2d_GreaterVertexY(void){};
};
/*! \class: McGePoint2d_LessY()
* 功能说明:用于排序点,按Y坐标从大到小 \n
* 编 制 者:hbq 完 成 日 期: 2014年3月10日11:36:28 \n
* 修 改 者:hbq 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class /* GEOMETRIC_EXT*/ McGePoint2d_GreaterY //用于排序点,按Y坐标从大到小
{
public:
bool operator ()(const McGePoint2d& pt1,const McGePoint2d& pt2) const
{
if(Equal2Dbl(pt1.y,pt2.y)) //相等
{
return (pt1.x > pt2.x);
}
else
{
return(pt1.y > pt2.y);
}
}
~McGePoint2d_GreaterY(void){};
McGePoint2d_GreaterY(void){};
};
/*! \class: McGePoint2d_EQ
* 功能说明:用于比较点是否相等 \n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:45:00 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class GEOMETRIC_EXT McGePoint2d_EQ //用于比较点是否相等
{
public:
explicit McGePoint2d_EQ(const McGePoint2d& pt1,double dPrecision=MIN_VALUE):m_pt(pt1),m_dPrecision(dPrecision){}
bool operator()(const McGePoint2d& pt2)
{
double dDist=(pt2.x-m_pt.x)*(pt2.x-m_pt.x)+(pt2.y-m_pt.y)*(pt2.y-m_pt.y);
if(dDist<=m_dPrecision*m_dPrecision)
return true;
else
return false;
}
~McGePoint2d_EQ(void){};
private:
McGePoint2d_EQ(void){};
McGePoint2d m_pt;
double m_dPrecision;
};
class GEOMETRIC_EXT McGePoint2d_EQ_X //用于比较点X坐标是否相等
{
public:
explicit McGePoint2d_EQ_X(const McGePoint2d& pt1,double dPrecision=MIN_VALUE):m_pt(pt1),m_dPrecision(dPrecision){}
bool operator()(const McGePoint2d& pt2)
{
return Equal2DblEx(m_pt.x, pt2.x, m_dPrecision);
}
~McGePoint2d_EQ_X(void){};
private:
McGePoint2d_EQ_X(void){};
McGePoint2d m_pt;
double m_dPrecision;
};
/*! \class: McGePoint2d_LessX
* 功能说明:用于排序点,按X坐标从小到大\n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:44:04 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class GEOMETRIC_EXT McGePoint2d_UNIQUE_EQ_X //用于排序点,按X坐标从小到大
:public binary_function<McGePoint2d,McGePoint2d,bool>
{
public:
bool operator ()(const McGePoint2d& pt1,const McGePoint2d& pt2) const
{
if(Equal2Dbl(pt1.x,pt2.x))
{
return true;
}
else
{
return false;
}
}
~McGePoint2d_UNIQUE_EQ_X(void){};
McGePoint2d_UNIQUE_EQ_X(void){};
};
class GEOMETRIC_EXT McGePoint2d_EQ_Y //用于比较点Y坐标是否相等
{
public:
explicit McGePoint2d_EQ_Y(const McGePoint2d& pt1,double dPrecision=MIN_VALUE):m_pt(pt1),m_dPrecision(dPrecision){}
bool operator()(const McGePoint2d& pt2)
{
return Equal2DblEx(m_pt.y, pt2.y, m_dPrecision);
}
~McGePoint2d_EQ_Y(void){};
private:
McGePoint2d_EQ_Y(void){};
McGePoint2d m_pt;
double m_dPrecision;
};
/*! \class: McGePoint2d_assignX
* 功能说明:改变点的X坐标 \n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:45:15 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class GEOMETRIC_EXT McGePoint2d_assignX //! 改变点的X坐标
{
public:
explicit McGePoint2d_assignX(double x) : m_x(x){}
McGePoint2d operator() (const McGePoint2d &pt)
{
return McGePoint2d(m_x,pt.y);
}
private:
double m_x;
};
/*! \class: McGePoint2d_assignY
* 功能说明:改变点的Y坐标 \n
* 编 制 者:echo 完 成 日 期: 2007-7-17 16:45:36 \n
* 修 改 者:echo 最后修改日期: - - \n
* 历史记录:V 00.00.00 (每次修改升级最后一个数字) \n
*/
class GEOMETRIC_EXT McGePoint2d_assignY //! 改变点的Y坐标
{
public:
explicit McGePoint2d_assignY(double y) : m_y(y){}
McGePoint2d operator() (const McGePoint2d &pt)
{
return McGePoint2d(pt.x,m_y);
}
private:
double m_y;
};
class GEOMETRIC_EXT CDouble_EQ //用于比较点是否相等
{
public:
explicit CDouble_EQ(double dSrc,double dPrecision=MIN_VALUE):m_dSrc(dSrc),m_dPrecision(dPrecision){}
bool operator()(double dDect)
{
return Equal2Dbl(dDect,m_dSrc);
}
~CDouble_EQ(void){};
private:
CDouble_EQ(void){};
double m_dSrc;
double m_dPrecision;
};
_ GEOMETRIC_END
Compare.cpp
double NormalizeAngle(double angle)
{
if(angle > 2*M_PI) {
angle -= 2*M_PI;
} else if(angle < 0) {
angle += 2*M_PI;
}
return angle;
}
// 把angle,startAng化到[0, 2*pi)之间
bool IsAngleInSector(double angle, double startAng, double sweepAng)
{
startAng = NormalizeAngle(startAng);
double endAng = NormalizeAngle(startAng + sweepAng);
angle = NormalizeAngle(angle);
bool bInSector = angle>startAng && angle<endAng ;
//! 扫描角度为负时
if(sweepAng < 0) bInSector = !bInSector;
//! 当角度等于起始角度时
if(Equal2Dbl(angle, startAng) || Equal2Dbl(angle, endAng))
bInSector = true;
return bInSector;
}
bool Equal2vctPoints(const vctMcGePoint2ds& points1, const vctMcGePoint2ds& points2)
{
if(points1.size()!=points2.size())
return false;
vector<McGePoint2d>::const_iterator pIter;
for(vector<McGePoint2d>::const_iterator pIt=points1.begin();pIt!=points1.end();++pIt)
{
pIter=find_if(points2.begin(),points2.end(),McGePoint2d_EQ(*pIt));
if(pIter==points2.end())
return false;
}
for(vector<McGePoint2d>::const_iterator pIt=points2.begin();pIt!=points2.end();++pIt)
{
pIter=find_if(points1.begin(),points1.end(),McGePoint2d_EQ(*pIt));
if(pIter==points1.end())
return false;
}
return true;
}
////要求startAng, endAng在(-180, 180]之间
//bool IsVectorBetweenDegAngs(double x, double y, double startAng, double endAng)
//{
// double angle = atan2(y, x);
// angle *= 180. / M_PI;
// if((angle >= startAng && angle <= endAng) ||
// startAng > endAng && (angle >= startAng || angle <= endAng))
// return TRUE;
// return FALSE;
//}
GEOMETRIC_END