//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : XSortedVertexList 类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: XSortedVertexList 类定义 // = Maintainers: // //-----------------------------------------------------------------------------+ #include "StdAfx.h" #include "XSortedVertexList.h" XSortedVertexList::XSortedVertexList(const XPoint & ptStart, const XPoint & ptEnd, ads_real dBulge) : PointList(ptStart, ptEnd, dBulge) { } XSortedVertexList::XSortedVertexList(const XCurveSegment &curve) : PointList(curve.GetStartPoint(), curve.GetEndPoint(), curve.GetBulge()) { } XSortedVertexList::~XSortedVertexList() { } void XSortedVertexList::InsertBeforeLast(const XPoint &ptSrc) { (*this)[Length() - 1]; XPointList::Insert(new XPoint(ptSrc)); } int XSortedVertexList::AsPoly2D(XPoly2D &poly) { PointList &pts = *this; if (!pts) { return RTERROR; } poly.Reset(); int nListLen = Length(); if (curveType == CURVE_CIRCLE) { if (nListLen <= 2) // 只处理园,不处理圆弧 { XPoint sPt = *pts[0]; XCurveSegment cv; cv = XCircle(center, ads_distance(center, sPt)); cv.AsPoly2D(poly); return RTNORM; } // pts[0]留作半径计算 for (int i = 1; i < nListLen; i++) { XPoint pt2; if (i == nListLen - 1) { pt2 = *pts[1]; } else { pt2 = *pts[i + 1]; } XArc arcSeg(center, ads_distance(center, *pts[i]), ads_angle(center, *pts[i]), ads_angle(center, pt2)); XCurveSegment cv; cv = arcSeg; poly.Append(new XPoint(cv.GetStartPoint())); poly.AppendBugle(cv.GetBulge()); if (i == nListLen - 1) { poly.Append(new XPoint(cv.GetEndPoint())); poly.AppendBugle(0.0); } } } else { // 弧或线 for (int j = 0; j < nListLen - 1; j++) { XPoint &pt1 = *pts[j]; XPoint &pt2 = *pts[j + 1]; XCurveSegment cv; if (curveType == CURVE_LINE) { XLine lineSeg(pt1, pt2); cv = lineSeg; } else { XArc arcSeg(center, ads_distance(center, pt1), ads_angle(center,pt1), ads_angle(center, pt2)); cv = arcSeg; } poly.Append(new XPoint(cv.GetStartPoint())); poly.AppendBugle(cv.GetBulge()); if (j == nListLen - 2) { poly.Append(new XPoint(cv.GetEndPoint())); poly.AppendBugle(0.0); } } } return RTNORM; }