From 1c276043642cc966967e9d1a5abe40c75e9a6b1a Mon Sep 17 00:00:00 2001 From: Zoe Date: Tue, 19 Jun 2018 21:58:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=81=8F=E7=A7=BB=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Polyline/offset.test.ts | 9 +++++- src/Add-on/testEntity/TestCurve.ts | 21 ++++++++++---- src/GraphicsSystem/OffestPolyline.ts | 43 +++++++++++++++++----------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/__test__/Polyline/offset.test.ts b/__test__/Polyline/offset.test.ts index cf1046013..bcc774f0f 100644 --- a/__test__/Polyline/offset.test.ts +++ b/__test__/Polyline/offset.test.ts @@ -109,5 +109,12 @@ test('多段线偏移测试3', () => { expect(cus[0].GetOffsetCurves(i).length).toBe(1); } - + for (let i = 0; i <= 0.5; i += 0.01) + { + expect(cus[0].GetOffsetCurves(-i).length).toBe(1); + } + for (let i = 0.51; i <= 1; i += 0.1) + { + expect(cus[0].GetOffsetCurves(-i).length).toBe(0); + } }) diff --git a/src/Add-on/testEntity/TestCurve.ts b/src/Add-on/testEntity/TestCurve.ts index 798af7124..bea5d7acf 100644 --- a/src/Add-on/testEntity/TestCurve.ts +++ b/src/Add-on/testEntity/TestCurve.ts @@ -38,11 +38,12 @@ export class TestTargeOnCurve implements Command // testCurve(res.unionList, 1); // testCurve(res.intersectionList, 2); // testCurve(res.subtractList, 3); - this.testClip(source as Polyline, target).forEach((c, i) => - { - c.ColorIndex = i + 1; - app.m_Database.ModelSpace.Append(c); - }) + // this.testClip(source as Polyline, target).forEach((c, i) => + // { + // c.ColorIndex = i + 1; + // app.m_Database.ModelSpace.Append(c); + // }) + this.testPtIn(source as Polyline, target); // target.Erase(); // source.Erase(); @@ -89,6 +90,16 @@ export class TestTargeOnCurve implements Command } return tmpCus; } + testPtIn(outline: Polyline, l: Curve) + { + + if (outline.PtInCurve(l.StartPoint)) + { + l.ColorIndex = 3 + } else + l.ColorIndex = 1; + + } } export function testPts(pts: Vector3[], color = 2) diff --git a/src/GraphicsSystem/OffestPolyline.ts b/src/GraphicsSystem/OffestPolyline.ts index ca8740d92..4c13d3ed7 100644 --- a/src/GraphicsSystem/OffestPolyline.ts +++ b/src/GraphicsSystem/OffestPolyline.ts @@ -55,17 +55,17 @@ export class PolyOffestUtil // testContours(this.m_Contours); //裁剪 let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves); - // // 优化裁剪后的曲线 - // this.m_RetCurves = this.optimizeCus(boxCurves, outputCus); - // this.m_RetCurves.push(...this.unNeedCutCus); + // 优化裁剪后的曲线 + this.m_RetCurves = this.optimizeCus(boxCurves, outputCus); + this.m_RetCurves.push(...this.unNeedCutCus); - // this.m_RetCurves = this.linkCurves(this.m_RetCurves); - // // 如果源线段闭合只保留闭合的部分 - // if (this.m_Polyline.IsClose) - // return this.m_RetCurves.filter(c => c.IsClose); + this.m_RetCurves = this.linkCurves(this.m_RetCurves); + // 如果源线段闭合只保留闭合的部分 + if (this.m_Polyline.IsClose) + return this.m_RetCurves.filter(c => c.IsClose); - this.m_Contours.forEach(c => { c.Outline.ColorIndex = 2 }); - this.m_RetCurves.push(...this.m_Contours.map(c => c.Outline)) + // this.m_Contours.forEach(c => { c.Outline.ColorIndex = 2 }); + // this.m_RetCurves.push(...this.m_Contours.map(c => c.Outline)) return this.m_RetCurves; } @@ -192,6 +192,12 @@ export class PolyOffestUtil this.unNeedCutCus.push(splitCus[1]) } } + //防止轮廓自交 + if (l1.IntersectWith(l2, 0).length > 0) + { + l1 = new Line(cu1.StartPoint, cu2.EndPoint); + l2 = new Line(cu1.EndPoint, cu2.StartPoint); + } return Contour.CreateContour([ cu1.Clone() as Curve, cu2.Clone() as Curve, @@ -541,15 +547,20 @@ export class PolyOffestUtil //需要计算的点列表 let needCaclPts: Vector3[] = []; - for (let i = 0; i < iParams.length - 1; i++) + if (iParams.length === 0) + needCaclPts = [l.StartPoint] + else { - needCaclPts.push(l.GetPointAtParam((iParams[i] + iParams[i + 1]) / 2)); + for (let i = 0; i < iParams.length - 1; i++) + { + needCaclPts.push(l.GetPointAtParam((iParams[i] + iParams[i + 1]) / 2)); + } + //如果交点不是首尾点,就加入首尾点 + if (!equaln(iParams[0], 0, 1e-6)) + needCaclPts.unshift(l.StartPoint); + if (!equaln(arrayLast(iParams), 1, 1e-6)) + needCaclPts.push(l.EndPoint); } - //如果交点不是首尾点,就加入首尾点 - if (!equaln(iParams[0], 0, 1e-6)) - needCaclPts.unshift(l.StartPoint); - if (!equaln(arrayLast(iParams), 1, 1e-6)) - needCaclPts.push(l.EndPoint); //切割曲线,缓存切割后曲线包围盒 if (IsPtsAllOutOrOnReg(outline, needCaclPts))