|
[code]
inline bool is_curve_selfcrossing(AcDbCurve *pCurv, double fuzz)
{
AcDbMPolygon mpol;
AcDbPolyline *pPoly = AcDbPolyline::cast(pCurv);
AcDb2dPolyline *p2Poly = AcDb2dPolyline::cast(pCurv);
AcDbCircle *pCircle = AcDbCircle::cast(pCurv);
Acad::ErrorStatus es = Acad::eNotApplicable;
if (pPoly) es = mpol.appendLoopFromBoundary(pPoly,true,fuzz);
else if (p2Poly) es = mpol.appendLoopFromBoundary(p2Poly,true,fuzz);
else if (pCircle) es = mpol.appendLoopFromBoundary(pCircle,true,fuzz);
return (es != Acad::eOk);
}
inline Acad::ErrorStatus get_curve_selfcrossing(AcDbCurve *pCurv, double fuzz, AcGePoint2dArray &pts_int,
AcGeIntArray &sgs_int, AcGeIntArray &sge_int)
{
Acad::ErrorStatus es = Acad::eNotApplicable;
AcDbMPolygon mpol;
AcDbPolyline *pPoly = AcDbPolyline::cast(pCurv);
AcDb2dPolyline *p2Poly = AcDb2dPolyline::cast(pCurv);
AcDbCircle *pCircle = AcDbCircle::cast(pCurv);
if (pPoly) es = mpol.appendLoopFromBoundary(pPoly,false,fuzz);
else if (p2Poly) es = mpol.appendLoopFromBoundary(p2Poly,false,fuzz);
else if (pCircle) es = mpol.appendLoopFromBoundary(pCircle,false,fuzz);
else return es;
AcGePoint2dArray pts;
AcGeDoubleArray blgs;
es = mpol.getMPolygonLoopAt(0,pts,blgs);
if (es != Acad::eOk) return es;
bool is_crossing;
AcDbMPolygonCrossingArray crossArray;
mpol.removeMPolygonLoopAt(0);
es = mpol.loopCrossesItself(is_crossing,true,crossArray,pts,blgs,fuzz);
if (es != Acad::eOk) return es;
if (!is_crossing) return Acad::eOk;
pts_int.setLogicalLength(crossArray.mCrossingArray.length());
sgs_int.setLogicalLength(crossArray.mCrossingArray.length());
sge_int.setLogicalLength(crossArray.mCrossingArray.length());
sge_int.setAll(-1);
AcGeTol gtol; gtol.setEqualPoint(fuzz); gtol.setEqualVector(fuzz);
AcGeCircArc2d aSeg; AcGeLineSeg2d lSeg;
for (int i=0; i < crossArray.mCrossingArray.length(); i++) {
pts_int[ i ] = crossArray.mCrossingArray[ i ]->getCrossingPoint();
sgs_int[ i ] = crossArray.mCrossingArray[ i ]->getEdgeIndex();
double dst = 1e+100;
for (int j=0; j < pts.length(); j++) {
if (j == sgs_int[ i ]) continue;
if (fabs(blgs[ j ]) < 1e-6) {
lSeg.set(pts[ j ], pts[(j+1)%pts.length()]);
if (lSeg.isOn(pts_int[ i ],gtol)) {
sge_int[ i ] = j;
break;
} else {
double d = lSeg.distanceTo(pts_int[ i ],gtol);
if (d < dst) {
dst = d; sge_int[ i ] = j;
}
}
} else {
aSeg.set(pts[ j ], pts[(j+1)%pts.length()],blgs[ j ],true);
if (aSeg.isOn(pts_int[ i ],gtol)) {
sge_int[ i ] = j;
break;
} else {
double d = aSeg.distanceTo(pts_int[ i ],gtol);
if (d < dst) {
dst = d; sge_int[ i ] = j ;
}
}
}
}
}
return Acad::eOk;
}
[/code] |
|