186 lines
3.2 KiB
C++
186 lines
3.2 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
|
// = FileName : XPointList 点列表类
|
|
// = Version : ver2.0
|
|
// = Author : zjq
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: XPointList 类定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "XPointList.h"
|
|
#include "XPrivateGlobalFunc.h"
|
|
|
|
using namespace XPrivate;
|
|
XPointList::XPointList()
|
|
{
|
|
|
|
}
|
|
|
|
XPointList::XPointList(const XPointList &src)
|
|
{
|
|
*this = src;
|
|
}
|
|
|
|
XPointList::~XPointList()
|
|
{
|
|
|
|
}
|
|
|
|
XPointList &XPointList::operator = (const XPointList &src)
|
|
{
|
|
Reset();
|
|
|
|
for (int i = 0; i < src.Length(); i++)
|
|
{
|
|
Append(new XPoint(src[i]));
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
void XPointList::TransUCS(const resbuf *pFrom, const resbuf *pTo)
|
|
{
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
XPoint pt = *(*this)[i];
|
|
ads_trans(pt, pFrom, pTo, 0, *(*this)[i]);
|
|
}
|
|
}
|
|
|
|
void XPointList::TransUCS(ads_matrix mat)
|
|
{
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
XPoint pt = *(*this)[i];
|
|
AT_xformpt(mat, pt, *(*this)[i]);
|
|
}
|
|
}
|
|
|
|
int XPointList::GetExtend(ads_point ptMin, ads_point ptMax)
|
|
{
|
|
if (!(*this))
|
|
{
|
|
return RTNONE;
|
|
}
|
|
|
|
XPoint ptLow, ptUp;
|
|
XPointList &lstPoints = *this;
|
|
ptLow = ptUp = *lstPoints[0];
|
|
|
|
for (int i = 1; i < lstPoints.Length(); i++)
|
|
{
|
|
XPoint &ptCur = *lstPoints[i];
|
|
ptLow = Min(ptLow, ptCur);
|
|
ptUp = Max(ptUp, ptCur);
|
|
}
|
|
|
|
*(XPoint *)ptMin = ptLow;
|
|
*(XPoint *)ptMax = ptUp;
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
|
|
int XPointList::GetExtend(ads_point ptMin, ads_point ptMax) const
|
|
{
|
|
if (!(*this))
|
|
{
|
|
return RTNONE;
|
|
}
|
|
|
|
XPoint ptLow, ptUp;
|
|
const XPointList &lstPoints = *this;
|
|
|
|
//ptLow = ptUp = *lstPoints[0];
|
|
ptLow = ptUp = lstPoints[0];
|
|
|
|
for (int i = 1; i < lstPoints.Length(); i++)
|
|
{
|
|
//const XPoint &ptCur = *lstPoints[i];
|
|
const XPoint &ptCur = lstPoints[i];
|
|
|
|
ptLow = Min(ptLow, ptCur);
|
|
ptUp = Max(ptUp, ptCur);
|
|
}
|
|
|
|
*(XPoint *)ptMin = ptLow;
|
|
*(XPoint *)ptMax = ptUp;
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
|
|
XPoint* XPointList::FindPoint(const XPoint &ptSrc)
|
|
{
|
|
XPointList &lstPoints = *this;
|
|
for (int i = 0; i < lstPoints.Length(); i++)
|
|
{
|
|
XPoint &ptCur = *lstPoints[i];
|
|
if(ptCur == ptSrc)
|
|
{
|
|
return &ptCur;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void XPointList::AppendNode(const XPoint &pt, ads_real dBulge)
|
|
{
|
|
Append(new XPoint(pt));
|
|
}
|
|
|
|
void XPointList::AsPoly2D(XPointList &poly) const
|
|
{
|
|
for (int n = 0; n < Length(); n++)
|
|
{
|
|
poly.AppendNode((*this)[n]);
|
|
}
|
|
}
|
|
|
|
void XPointList::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 XPointList::SetElevation(ads_real dElev)
|
|
{
|
|
int nLen = Length();
|
|
for (int i = 0; i < nLen; i++)
|
|
{
|
|
(*this)[i]->z = dElev;
|
|
}
|
|
}
|
|
|
|
int XPointList::NewAppend(const XPoint &ptSrc)
|
|
{
|
|
int nPos;
|
|
if (!FindPoint(ptSrc))
|
|
{
|
|
Append(new XPoint(ptSrc));
|
|
nPos = Length() - 1;
|
|
}
|
|
else
|
|
{
|
|
nPos = CurPosition();
|
|
}
|
|
|
|
return nPos;
|
|
}
|