174 lines
3.0 KiB
C++
174 lines
3.0 KiB
C++
#include "StdAfx.h"
|
|
#include "ADSGePointList.h"
|
|
#include "globalFunc.h"
|
|
|
|
ADSGePointList::ADSGePointList()
|
|
{
|
|
|
|
}
|
|
|
|
ADSGePointList::ADSGePointList(const ADSGePointList &src)
|
|
{
|
|
*this = src;
|
|
}
|
|
|
|
ADSGePointList::~ADSGePointList()
|
|
{
|
|
|
|
}
|
|
|
|
ADSGePointList &ADSGePointList::operator = (const ADSGePointList &src)
|
|
{
|
|
Reset();
|
|
|
|
for (int i = 0; i < src.Length(); i++)
|
|
{
|
|
Append(new ADSGePoint3d(src[i]));
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
void ADSGePointList::TransUCS(const resbuf *pFrom, const resbuf *pTo)
|
|
{
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
ADSGePoint3d pt = *(*this)[i];
|
|
ads_trans(pt, pFrom, pTo, 0, *(*this)[i]);
|
|
}
|
|
}
|
|
|
|
void ADSGePointList::TransUCS(ads_matrix mat)
|
|
{
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
ADSGePoint3d pt = *(*this)[i];
|
|
GlobalFunc::PointTransformBy(mat, pt, *(*this)[i]);
|
|
}
|
|
}
|
|
|
|
int ADSGePointList::GetExtend(ads_point ptMin, ads_point ptMax)
|
|
{
|
|
if (!(*this))
|
|
{
|
|
return RTNONE;
|
|
}
|
|
|
|
ADSGePoint3d ptLow, ptUp;
|
|
ADSGePointList &lstPoints = *this;
|
|
ptLow = ptUp = *lstPoints[0];
|
|
|
|
for (int i = 1; i < lstPoints.Length(); i++)
|
|
{
|
|
ADSGePoint3d &ptCur = *lstPoints[i];
|
|
ptLow = Min(ptLow, ptCur);
|
|
ptUp = Max(ptUp, ptCur);
|
|
}
|
|
|
|
*(ADSGePoint3d *)ptMin = ptLow;
|
|
*(ADSGePoint3d *)ptMax = ptUp;
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
|
|
int ADSGePointList::GetExtend(ads_point ptMin, ads_point ptMax) const
|
|
{
|
|
if (!(*this))
|
|
{
|
|
return RTNONE;
|
|
}
|
|
|
|
ADSGePoint3d ptLow, ptUp;
|
|
const ADSGePointList &lstPoints = *this;
|
|
|
|
//ptLow = ptUp = *lstPoints[0];
|
|
ptLow = ptUp = lstPoints[0];
|
|
|
|
for (int i = 1; i < lstPoints.Length(); i++)
|
|
{
|
|
//const ADSGePoint3d &ptCur = *lstPoints[i];
|
|
const ADSGePoint3d &ptCur = lstPoints[i];
|
|
|
|
ptLow = Min(ptLow, ptCur);
|
|
ptUp = Max(ptUp, ptCur);
|
|
}
|
|
|
|
*(ADSGePoint3d *)ptMin = ptLow;
|
|
*(ADSGePoint3d *)ptMax = ptUp;
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
|
|
ADSGePoint3d* ADSGePointList::FindPoint(const ADSGePoint3d &ptSrc)
|
|
{
|
|
ADSGePointList &lstPoints = *this;
|
|
for (int i = 0; i < lstPoints.Length(); i++)
|
|
{
|
|
ADSGePoint3d &ptCur = *lstPoints[i];
|
|
if(ptCur == ptSrc)
|
|
{
|
|
return &ptCur;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void ADSGePointList::AppendNode(const ADSGePoint3d &pt, ads_real dBulge, AcDb::Visibility eVal)
|
|
{
|
|
Append(new ADSGePoint3d(pt));
|
|
}
|
|
|
|
void ADSGePointList::AsPoly2D(ADSGePointList &poly) const
|
|
{
|
|
for (int n = 0; n < Length(); n++)
|
|
{
|
|
poly.AppendNode((*this)[n]);
|
|
}
|
|
}
|
|
|
|
void ADSGePointList::Center(ads_point ptCen)
|
|
{
|
|
ads_real dTotalX = 0.0, dTotalY = 0.0, dTotalZ = 0.0;
|
|
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
dTotalX += (*this)[i]->x;
|
|
dTotalY += (*this)[i]->y;
|
|
dTotalZ += (*this)[i]->z;
|
|
}
|
|
|
|
ptCen[X] = dTotalX / nLen;
|
|
ptCen[Y] = dTotalY / nLen;
|
|
ptCen[Z] = dTotalZ / nLen;
|
|
}
|
|
|
|
void ADSGePointList::SetElevation(ads_real dElev)
|
|
{
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
(*this)[i]->z = dElev;
|
|
}
|
|
}
|
|
|
|
int ADSGePointList::NewAppend(const ADSGePoint3d &ptSrc)
|
|
{
|
|
int nPos;
|
|
if (!FindPoint(ptSrc))
|
|
{
|
|
Append(new ADSGePoint3d(ptSrc));
|
|
nPos = Length() - 1;
|
|
}
|
|
else
|
|
{
|
|
nPos = CurPosition();
|
|
}
|
|
|
|
return nPos;
|
|
} |