From acff8be499c18836e1002eb691576924c5216453 Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 28 May 2018 17:03:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GraphicsSystem/OffestPolyline.ts | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/GraphicsSystem/OffestPolyline.ts b/src/GraphicsSystem/OffestPolyline.ts index 50bfbc95a..7529643fe 100644 --- a/src/GraphicsSystem/OffestPolyline.ts +++ b/src/GraphicsSystem/OffestPolyline.ts @@ -18,7 +18,7 @@ interface offestRes interface offestRes1 { index: number, - pl: Curve + curve: Curve } /** @@ -1065,13 +1065,14 @@ export class PolyOffestUtil3 //偏移 GetOffsetCurves(): Curve[] { - let plList1: offestRes1[] = this.offestCurve(this.m_Polyline.Explode()); - let plList2: offestRes1[] = this.offestCurve(this.m_Polyline.Explode(), true); + let expCus = this.m_Polyline.Explode(); + let plList1 = this.offestCurve(expCus, this.m_OffestDist); + let plList2 = this.offestCurve(expCus, -this.m_OffestDist); let contours: Contour[] = []; for (let i = 0; i < plList1.length; i++) { - let con = this.buildContourByTwoSideOfest(plList1[i].pl, plList2[i].pl); + let con = this.buildContourByTwoSideOfest(plList1[i].curve, plList2[i].curve); con && contours.push(con); } @@ -1126,17 +1127,15 @@ export class PolyOffestUtil3 } //偏移曲线 - private offestCurve(pls: Curve[], isContrary: boolean = false): offestRes1[] + private offestCurve(pls: Curve[], dis: number): offestRes1[] { - let plList: offestRes1[] = []; - pls.forEach((cu, index) => + return pls.map((cu, index) => { - let pl = cu.GetOffsetCurves(isContrary ? -this.m_OffestDist : this.m_OffestDist)[0]; - plList.push({ pl, index }); + let curve = cu.GetOffsetCurves(dis)[0]; + return { curve, index }; }); - return plList; } - //通过2侧偏移曲线构建封闭轮廓 + //通过2侧偏移曲线构建封闭轮廓,由于是双向偏移,所以不可能出现2个曲线都为空的情况 private buildContourByTwoSideOfest(pl1: Curve, pl2: Curve) { if (pl1 && pl2) @@ -1162,20 +1161,21 @@ export class PolyOffestUtil3 // 修剪连接相邻曲线 private trimAndJointOffestPolyline(offResList: offestRes1[], originLine: Polyline) { - offResList = offResList.filter(r => r.pl) - if (offResList.length === 0) return []; - if (offResList.length === 1) return [offResList[0].pl]; + offResList = offResList.filter(r => r.curve); + if (offResList.length <= 1) + return offResList.map(r => r.curve); + let newPlList: Array = []; - let nextPt: Vector3 = offResList[0].pl.StartPoint.clone(); + let nextPt: Vector3 = offResList[0].curve.StartPoint; for (let i = 0; i < offResList.length; i++) { //前面线 - let frontLine = offResList[i].pl; + let frontLine = offResList[i].curve; //后面线 - let laterLine = i === offResList.length - 1 ? undefined : offResList[i + 1].pl; + let laterLine = i === offResList.length - 1 ? undefined : offResList[i + 1].curve; //如果是闭合的,继续循环,否则直接添加到新数组列表 if (i === offResList.length - 1) { @@ -1183,7 +1183,6 @@ export class PolyOffestUtil3 laterLine = newPlList[0]; else { - let frontLine = offResList[offResList.length - 1].pl; this.appendNewPllist(frontLine, nextPt, frontLine.EndPoint, newPlList); break; }