170 lines
4.0 KiB
C++
170 lines
4.0 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
|
// = FileName : XSortSideOnVertex 类
|
|
// = Version : ver2.0
|
|
// = Author : zjq
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: XSortSideOnVertex 定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "XSortSideOnVertex.h"
|
|
#include "XRegionSide.h"
|
|
#include "XGlobalFunc.h"
|
|
|
|
// 经过一点所有边的排序
|
|
XSortSideOnVertex::XSortSideOnVertex(const XPoint &ptLoc)
|
|
: DList<XSideVector>(1), m_ptLoc(ptLoc)
|
|
{
|
|
// Z modify on 2001/12/29
|
|
// _DIST_SNAP 改为 _DIST_SNAP/2
|
|
m_ptMin.x = m_ptLoc.x - _DIST_SNAP;
|
|
m_ptMin.y = m_ptLoc.y - _DIST_SNAP;
|
|
m_ptMax.x = m_ptLoc.x + _DIST_SNAP;
|
|
m_ptMax.y = m_ptLoc.y + _DIST_SNAP;
|
|
}
|
|
|
|
XSortSideOnVertex::~XSortSideOnVertex()
|
|
{
|
|
|
|
}
|
|
|
|
// 判断节点是否包含某一点
|
|
// 忽略 z 坐标
|
|
BOOL XSortSideOnVertex::Include(const XPoint &pt) const
|
|
{
|
|
return (pt.x >= m_ptMin.x && pt.y >= m_ptMin.y &&
|
|
pt.x <= m_ptMax.x && pt.y <= m_ptMax.y);
|
|
}
|
|
|
|
// 得到第nCur边的前一边
|
|
XSideVector * XSortSideOnVertex::GetPrevSide(int nCur) const
|
|
{
|
|
int nCount = Length();
|
|
|
|
// 只做nCount-1次循环
|
|
for (int i = nCur - 1, n = 0; n < nCount - 1; i--)
|
|
{
|
|
int idx = DePeriod(nCount, i);
|
|
const XSideVector &wall = (*this)[idx];
|
|
return (XSideVector *)&wall;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
// 得到第nCur个边的后一个边
|
|
XSideVector * XSortSideOnVertex::GetNextSide(int nCur) const
|
|
{
|
|
int nCount = Length();
|
|
|
|
// 只做nCount-1次循环
|
|
for (int i = nCur + 1, n = 0; n < nCount - 1; i++)
|
|
{
|
|
int idx = DePeriod(nCount, i);
|
|
const XSideVector &wall = (*this)[idx];
|
|
return (XSideVector *)&wall;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
// 按序插入一墙
|
|
// 同时设置连接信息
|
|
int XSortSideOnVertex::Insert(XRegionSide *pSide)
|
|
{
|
|
XPoint ptLocTemp = m_ptLoc;
|
|
XPoint &ptStart = pSide->StartPoint();
|
|
XPoint &ptEnd = pSide->EndPoint();
|
|
|
|
ads_real dDrt=0; // 矢量方向
|
|
BOOL bIncludeStart = Include(ptStart);
|
|
BOOL bIncludeEnd = Include(ptEnd);
|
|
|
|
if (bIncludeStart && bIncludeEnd) //当前节点包含边的起点和终点
|
|
{
|
|
XGeLib::adsout << _T("\n发现不正确的短线! 长度=") << pSide->GetLength();
|
|
|
|
throw pSide;
|
|
}
|
|
|
|
if (bIncludeStart)
|
|
{
|
|
dDrt = pSide->IDirection(0);
|
|
pSide->SetStartNode(this);
|
|
}
|
|
else if (bIncludeEnd)
|
|
{
|
|
dDrt = pSide->IDirection(1);
|
|
pSide->SetEndNode(this);
|
|
}
|
|
else
|
|
{
|
|
ASSERT(0);
|
|
throw this;
|
|
return RTERROR;
|
|
}
|
|
|
|
for (int i = 0; i < Length(); i++)
|
|
{
|
|
XSideVector &vtSide = *(*this)[i];
|
|
if (CT_IsExactSameDrt(dDrt, vtSide.m_nDirection, _angSnap))
|
|
{
|
|
XCurveSegment segOld = *vtSide.m_pSide;
|
|
XCurveSegment segNew = *pSide;
|
|
|
|
double dDrtOld, dDrtNew;
|
|
double nDistPolar = min(segOld.GetLength(), segNew.GetLength()) / 4.0;
|
|
|
|
if (bIncludeStart)
|
|
{
|
|
XPointDir2d ptDirS;
|
|
segNew.Polar(nDistPolar, ptDirS);
|
|
dDrtNew = ptDirS.nDirection;
|
|
}
|
|
else
|
|
{
|
|
XPointDir2d ptDirE;
|
|
segNew.Polar(nDistPolar, ptDirE, FALSE);
|
|
dDrtNew = ptDirE.nDirection;
|
|
}
|
|
|
|
if (vtSide.m_pSide->GetStartNode() == this)
|
|
{
|
|
XPointDir2d ptDirS;
|
|
segOld.Polar(nDistPolar, ptDirS);
|
|
dDrtOld = ptDirS.nDirection;
|
|
}
|
|
else
|
|
{
|
|
XPointDir2d ptDirE;
|
|
segOld.Polar(nDistPolar, ptDirE, FALSE);
|
|
dDrtOld = ptDirE.nDirection;
|
|
}
|
|
|
|
if (CT_IsExactSameDrt(dDrtNew, dDrtOld, _angSnap))
|
|
{
|
|
|
|
#if !defined(NDEBUG)
|
|
XGeLib::adsout << _T("\n发现重合的边 方向e=") << dDrt << _T("; vtSide=") << vtSide.m_nDirection;
|
|
#endif
|
|
}
|
|
|
|
if (dDrtNew < dDrtOld)
|
|
{
|
|
DList<XSideVector>::Insert(new XSideVector(pSide,dDrt));
|
|
return RTNORM;
|
|
}
|
|
}
|
|
else if (dDrt < vtSide.m_nDirection)
|
|
{
|
|
DList<XSideVector>::Insert(new XSideVector(pSide, dDrt));
|
|
return RTNORM;
|
|
}
|
|
}
|
|
|
|
DList<XSideVector>::Append(new XSideVector(pSide,dDrt));
|
|
return RTNORM;
|
|
}
|