154 lines
2.8 KiB
C++
154 lines
2.8 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeDscEdge 类
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TPGeDscEdge 定义
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeDscEdge.h"
|
|
#include "TGPoint2D.h"
|
|
|
|
TPGeDscEdge::TPGeDscEdge(TPGeDscPoint *p0, TPGeDscPoint *p1,double len)
|
|
: pPt0(p0),pPt1(p1),pPtFit(NULL),length(len)
|
|
{
|
|
pPt0->AppendEdge(this);
|
|
pPt1->AppendEdge(this);
|
|
}
|
|
|
|
TPGeDscEdge::~TPGeDscEdge()
|
|
{
|
|
|
|
}
|
|
|
|
TPGeDscPoint* TPGeDscEdge::GetNextPoint(TPGeDscPoint*pPt) const
|
|
{
|
|
return pPt0 == pPt ? pPt1 : pPt0;
|
|
}
|
|
|
|
double TPGeDscEdge::GetMinZ()
|
|
{
|
|
return Min2(pPt0->z, pPt1->z);
|
|
}
|
|
|
|
bool TPGeDscEdge::operator > (const TPGeDscEdge&e) const
|
|
{
|
|
return length > e.length;
|
|
}
|
|
|
|
bool TPGeDscEdge::operator < (const TPGeDscEdge&e) const
|
|
{
|
|
return length < e.length;
|
|
}
|
|
|
|
bool TPGeDscEdge::IsCrossWith(TPGeDscEdge*pEdge) const
|
|
{
|
|
TPGeGLineSeg2D seg1(*pPt0,*pPt1),seg2(*(pEdge->pPt0),*(pEdge->pPt1));
|
|
TGObjectList oList;
|
|
if(seg1.Intersect(seg2,oList))
|
|
{
|
|
TGObject*pObj = oList[0];
|
|
if(IS_TYPE(pObj,TGPoint2D))
|
|
{
|
|
const TGPoint2D&pt = (const TGPoint2D&)(*pObj);
|
|
double pa1,pa2;
|
|
seg1.Pt2Pa(pt,pa1);
|
|
if(UP_ZERO(pa1) && DOWN_ZERO(pa1 - 1))
|
|
{
|
|
return true;
|
|
}
|
|
seg2.Pt2Pa(pt,pa2);
|
|
if(UP_ZERO(pa2) && DOWN_ZERO(pa2 - 1))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void TPGeDscEdge::GetExtend2D(TPGeExtend2D&ext)
|
|
{
|
|
TPGeGLineSeg2D*pSeg = CreateEdge();
|
|
pSeg->GetExtend2D(ext);
|
|
delete pSeg;
|
|
}
|
|
|
|
TPGeDscPoint* TPGeDscEdge::GetFitPoint(double z)
|
|
{
|
|
double dz = pPt1->z - pPt0->z;
|
|
if(EQUAL_ZERO(dz))
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
if(pPtFit != NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
double s = (z - pPt0->z) / dz;
|
|
if(DOWN_ZERO(s) || UP_ZERO(s - 1))
|
|
{
|
|
return pPtFit = NULL;
|
|
}
|
|
|
|
double dx = pPt1->x - pPt0->x, dy = pPt1->y - pPt0->y;
|
|
return pPtFit = new TPGeDscPoint(pPt0->x + s * dx, pPt0->y + s * dy, z);
|
|
}
|
|
|
|
void TPGeDscEdge::ConnectPath(TPGeFitPath&path)
|
|
{
|
|
AddFlag(VISITED);
|
|
path << pPt0 << pPt1;
|
|
TPGeDscPoint*pPtFrom = pPt1;
|
|
TPGeDscEdge *pEdge = this;
|
|
while(true)
|
|
{
|
|
TPGeDscPoint*pPt = pPtFrom->FindNext(pEdge);
|
|
if(pPt != NULL)
|
|
{
|
|
if(pPt == pPt0)
|
|
{
|
|
path.SetClosed();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
path << pPt;
|
|
pPtFrom = pPt;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
pPtFrom = pPt0;
|
|
pEdge = this;
|
|
while(true)
|
|
{
|
|
TPGeDscPoint*pPt = pPtFrom->FindNext(pEdge);
|
|
if(pPt != NULL)
|
|
{
|
|
path.InsertHead(pPt);
|
|
pPtFrom = pPt;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
TPGeGLineSeg2D* TPGeDscEdge::CreateEdge()
|
|
{
|
|
return new TPGeGLineSeg2D(*pPt0,*pPt1);
|
|
} |