112 lines
2.3 KiB
C++
112 lines
2.3 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
|
// = FileName : XCurveIntersection 类
|
|
// = Version : ver2.0
|
|
// = Author : zjq
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: XCurveIntersection 定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "XCurveIntersection.h"
|
|
#include "XGlobalCurveFunc.h"
|
|
#include "XCurveInline.h"
|
|
|
|
ads_real XCurveIntersection::minLen = 100.0;
|
|
DList<XCurveIntersection> XCurveIntersection::GlobalCurveList;
|
|
|
|
XCurveIntersection::XCurveIntersection(const XCurveSegment &seg)
|
|
: XCurveSegment(seg), segments(seg.GetStartPoint(), seg.GetEndPoint(), seg.GetBulge())
|
|
{
|
|
SetLineFlag(LS_FINITE);
|
|
}
|
|
|
|
XCurveIntersection::~XCurveIntersection()
|
|
{
|
|
|
|
}
|
|
|
|
void XCurveIntersection::DivideToSegments()
|
|
{
|
|
XPoint &ptHead = *segments.Head();
|
|
XPoint &ptTail = *segments.Tail();
|
|
XPoint ptNewHead = ptHead, ptNewTail = ptTail;
|
|
int bHeadOnOtherCurve = 0, bTailOnOtherCurve = 0;
|
|
|
|
for (int i = 0; i < XCurveIntersection::GlobalCurveList.Length(); i++)
|
|
{
|
|
XCurveIntersection *pSeg = XCurveIntersection::GlobalCurveList[i];
|
|
if (this == pSeg)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
XCurveSegment &ln = *pSeg;
|
|
|
|
// 判断当前线的端点是否位于其他线上
|
|
int nPrFlagHead = ptHead & ln;
|
|
int nPrFlagTail = ptTail & ln;
|
|
if (nPrFlagHead == PR_INSIDE || nPrFlagHead == PR_ONPT1 || nPrFlagHead == PR_ONPT2)
|
|
{
|
|
bHeadOnOtherCurve = 1;
|
|
}
|
|
|
|
if (nPrFlagTail == PR_INSIDE || nPrFlagTail == PR_ONPT1 || nPrFlagTail == PR_ONPT2)
|
|
{
|
|
bTailOnOtherCurve = 1;
|
|
}
|
|
|
|
XPoint inPt[2];
|
|
int num = 0;
|
|
{
|
|
num=Intersection(ln, inPt[0], inPt[1]);
|
|
}
|
|
|
|
for (int n = 0; n < num; n++)
|
|
{
|
|
int ins = 0;
|
|
|
|
if (ads_distance(ptHead,inPt[n]) < minLen)
|
|
{
|
|
if (!bHeadOnOtherCurve)
|
|
{
|
|
ptNewHead = inPt[n];
|
|
}
|
|
}
|
|
else if (ads_distance(ptTail,inPt[n]) < minLen)
|
|
{
|
|
if (!bTailOnOtherCurve)
|
|
{
|
|
ptNewTail = inPt[n];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ins = 1; //交点位于中间
|
|
}
|
|
|
|
if (ins)
|
|
{
|
|
segments.Insert(inPt[n]);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!Is(CURVE_CIRCLE))
|
|
{
|
|
if (!bHeadOnOtherCurve)
|
|
{
|
|
ptHead = ptNewHead;
|
|
}
|
|
|
|
if (!bTailOnOtherCurve)
|
|
{
|
|
ptTail = ptNewTail;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|