//Cpp文件中定义静态变量
static double ComparePoint3d采用Tol;
//定义比较函数
static bool IsEqual(double a, double b, double tol = 1.0E-7)
{
return (fabs(a - b) < tol);
}
static bool lessPt(const AcGePoint3d& pt1,const AcGePoint3d& pt2)
{
if(IsEqual(pt1.x,pt2.x,ComparePoint3d采用Tol))
{
if(IsEqual(pt1.y,pt2.y,ComparePoint3d采用Tol))
{
return pt1.z < pt2.z;
}
return pt1.y < pt2.y;
}
return pt1.x < pt2.x;
}
static bool equalPt(const AcGePoint3d& pt1,const AcGePoint3d& pt2)
{
AcGeTol geTol;
geTol.setEqualPoint(ComparePoint3d采用Tol);
return pt1.isEqualTo(pt2,geTol);
}
函数主体
//去除重复的点
// ----- ads采用delsamept symbol (do not rename)
static int ads采用delsamept(void)
{
//----- Remove the following line if you do not expect any argument for this ADS function
struct resbuf *rb =acedGetArgs();
ComparePoint3d采用Tol = 0.001;
std::vector<AcGePoint3d> pts;
if (rb== NULL)
{
return acedRetNil();
}
else
{
if(rb->restype!=RTLB)
{
return acedRetNil();
}
else
{
rb = rb->rbnext;
while(true)
{
if (rb->restype == RTPOINT)
{
pts.push采用back(AcGePoint3d(rb->resval.rpoint[0],rb->resval.rpoint[1],0));
rb = rb->rbnext;
}
else if (rb->restype == RT3DPOINT)
{
pts.push采用back(AcGePoint3d(rb->resval.rpoint[0],rb->resval.rpoint[1],rb->resval.rpoint[2]));
rb = rb->rbnext;
}
else if (rb->restype == 10)
{
pts.push采用back(AcGePoint3d(rb->resval.rpoint[0],rb->resval.rpoint[1],rb->resval.rpoint[2]));
rb = rb->rbnext;
}
else if(rb->restype==RTLE)
{
break;
}
else
{
return acedRetNil();
}
}
if (rb->rbnext == NULL)
{
return acedRetNil();
}
rb = rb->rbnext;
if (rb->restype == RTSHORT)
{
ComparePoint3d采用Tol = rb->resval.rint;
}
else if (rb->restype == RTREAL)
{
ComparePoint3d采用Tol = rb->resval.rreal;
}
else if (rb->restype == RTLONG)
{
ComparePoint3d采用Tol = rb->resval.rlong;
}
if (rb->rbnext != NULL)
{
return acedRetNil();
}
}
}
std::sort(pts.begin(),pts.end(),lessPt);
pts.erase(std::unique(pts.begin(),pts.end(),equalPt),pts.end());
struct resbuf *bufList=NULL;
for (int i = 0 ;i < pts.size(); i++)
{
if (bufList == NULL)
bufList=acutBuildList(RT3DPOINT,pts.at(i),RTNONE);
else
bufList=acutBuildList(RTRESBUF,bufList,RT3DPOINT,pts.at(i),RTNONE);
}
return acedRetList(bufList);
}
(delsamept (list (list 0 0) (list 10 10) (list 0 10)) 0.001)
(delsamept (list (list 0 0) (list 10 10) (list 0 10)) 0.11)
(delsamept (list (list 0 0) (list 0 0.002) (list 0 10)) 0.11)
(delsamept (list (list 0 0) (list 0 10) (list 0 0.002)) 0.11)
(delsamept (list (list 0 0) (list 0 10) T ) 0.11)
(delsamept (list (list 0 0 0 0) (list 0 10) (list 0 0.002)) 0.11)
(delsamept (list (list 0 0 0) (list 0 10 0) (list 0 0.002 0)) 0.11)
((0.0 0.0 0.0) (10.0 10.0 0.0) (0.0 10.0 0.0))
((0.0 0.0 0.0) (10.0 10.0 0.0) (0.0 10.0 0.0))
((0.0 0.002 0.0) (0.0 10.0 0.0))
((0.0 0.002 0.0) (0.0 10.0 0.0))
nil
nil
((0.0 0.002 0.0) (0.0 10.0 0.0))
((0.0 0.002 0.0) (0.0 10.0 0.0))
采用$