From c465af92d29f821a7100d07c988b78d4ad14d57b Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 29 Jun 2018 17:14:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20=20#IKIPE=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=81=8F=E7=A7=BB=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Polyline/Intersect.test.ts | 2 +- .../__snapshots__/offset.test.ts.snap | 4 ++ __test__/Polyline/offset.test.ts | 16 ++++++++ src/GraphicsSystem/OffsetPolyline.ts | 37 ++++++++++++------- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/__test__/Polyline/Intersect.test.ts b/__test__/Polyline/Intersect.test.ts index b3a1a9df7..7ccc0c2fa 100644 --- a/__test__/Polyline/Intersect.test.ts +++ b/__test__/Polyline/Intersect.test.ts @@ -105,7 +105,7 @@ describe("相交", () => let pts3 = pl.IntersectWith(p2, IntersectOption.ExtendArg); expect(pts3.length).toBe(1); let pts4 = pl.IntersectWith(p3, IntersectOption.OnBothOperands); - expect(pts4[0]).toEqual(new Vector3(2.5, 2.5, 0)) + expect(pts4[1]).toEqual(new Vector3(2.5, 2.5, 0)) expect(pts4.length).toBe(2); let pts5 = pl.IntersectWith(p4, IntersectOption.OnBothOperands); expect(pts5.length).toBe(1); diff --git a/__test__/Polyline/__snapshots__/offset.test.ts.snap b/__test__/Polyline/__snapshots__/offset.test.ts.snap index 3d4483410..03661d405 100644 --- a/__test__/Polyline/__snapshots__/offset.test.ts.snap +++ b/__test__/Polyline/__snapshots__/offset.test.ts.snap @@ -48,6 +48,10 @@ exports[`简单图形因为点在线内算法错误导致的丢失 3`] = `6.8025 exports[`简单图形因为点在线内算法错误导致的丢失 4`] = `6.045525633131274`; +exports[`补充bug测试 1`] = `7385.097729437721`; + +exports[`补充bug测试 2`] = `7455.833952762051`; + exports[`补圆弧测试 补圆弧测试1 1`] = `1`; exports[`补圆弧测试 补圆弧测试1 2`] = `202.39234999237357`; diff --git a/__test__/Polyline/offset.test.ts b/__test__/Polyline/offset.test.ts index 1b37e8f54..147d2b346 100644 --- a/__test__/Polyline/offset.test.ts +++ b/__test__/Polyline/offset.test.ts @@ -833,3 +833,19 @@ test('圆求交错误导致的线丢失', () => expect(cus[0].Length).toMatchSnapshot(); } }); + +test('补充bug测试', () => +{ + let data = + [1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3014.1813078325877, -118.48659432946494, 0, 1], 2, 25, [7212.90932057689, -239.9823077249786], -0.9999999999999921, [7212.9093205768895, 122.19897643916269], 0, [7779.276759343887, 122.19897643916269], 0, [7779.276759344071, 428.1814280252842], 0.1947099739542557, [7740.981455628771, 522.7925370761521], 0, [7304.310456694637, 522.7925370760897], 0, [7489.002384561892, 796.1365903196343], 0, [7742.516525859682, 796.1365903196343], 0, [7742.516525859682, 961.2048135488966], -1.3463056702167695, [8021.98728468389, 876.8699986200176], 0, [8021.987284683929, 789.3738464533299], -0.05161685745547489, [8028.1320183974, 790.0098847386233], 0, [8444.377142303902, 790.0098847389027], -1.1043175340350022, [8413.555740131487, 479.90559801040376], 0, [8049.204632346665, 479.9055980109795], 1.512505548953077, [8054.570478774117, 467.3001115689552], 0.06283615294599319, [8055.684165377956, 468.79464872233984], 0, [8055.684165377962, 182.7089738110588], -0.056342427094734256, [8062.381207162069, 183.46603224647305], 0, [8468.88396462686, 183.4660322464784], -0.20525770195463292, [8655.475816304977, 103.49809581299945], -0.8336853670274493, [8492.531297747215, -120.51154890075377], 0, [8104.435007347477, -120.51154890071338], -0.6646338605614993, [7740.532382653638, -239.9823077249987], 0, [7212.90932057689, -239.9823077249786], 0, false]]; + + let pl = loadFile(data)[0]; + + let cus = pl.GetOffsetCurves(10); + expect(cus.length).toBe(1); + expect(cus[0].Length).toMatchSnapshot(); + cus = pl.GetOffsetCurves(-10); + expect(cus.length).toBe(1); + expect(cus[0].Length).toMatchSnapshot(); + +}); diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index 2ecd4032d..f1f2372f0 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -70,7 +70,6 @@ export class PolyOffsetUtil this.m_RetCurves = this.optimizeCus(boxCurves, outputCus); - this.m_RetCurves = this.linkCurves(this.m_RetCurves); // 如果源线段闭合只保留闭合的部分 @@ -505,28 +504,38 @@ export class PolyOffsetUtil if (index === endIndex) break; } - //如果和第二个圆(消失圆弧终点构建圆)相交,则直接连接,否则从第一个圆开始,圆数量要大于1 - let iPts = cirs.length > 1 ? frontLine.IntersectWith(cirs[1], 0) : []; - if (iPts.length === 0) + + //找到和frontline存在离源线段距离大于偏移距离的交点的圆,跳过这个圆前面的圆计算 + let iPts: Vector3[]; + let index = 1; + for (; index < cirs.length; index++) + { + let pts = frontLine.IntersectWith(cirs[index], 0).filter(p => + { + let dist = p.distanceToSquared(this.m_Polyline.GetClosestPointTo(p, false)); + return dist + 1e-3 > this.m_dist2; + }); + if (pts.length === 0) + { + break; + } + else + { + iPts = pts; + } + } + if (!iPts) { - //第一个圆肯定和frontline相切,切点为frontline的终点 iPts = [frontLine.EndPoint]; } else { - cirs.shift(); + cirs.splice(0, index - 1); } - //#region 避免错误块 - //假设我们认为连接一定能成功,那么下面的if不是必要的 - // if (!iPts) - // { - // console.error("补圆失败,距离为", this.m_OffestDist); - // } - //#endregion - let iPt = this.selectFitInterPt(iPts, frontLine.EndPoint); + let iPt = this.selectFitInterPt(iPts, frontLine.EndPoint); this.appendNewCuAndContour(frontLine, nextPt, iPt, startIndex); //连接剩下的圆. From 56d52a797b51395f5a2f04d35ffb32b23e21627d Mon Sep 17 00:00:00 2001 From: ChenX Date: Fri, 29 Jun 2018 17:33:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GraphicsSystem/OffsetPolyline.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index f1f2372f0..7a3455531 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -507,8 +507,7 @@ export class PolyOffsetUtil //找到和frontline存在离源线段距离大于偏移距离的交点的圆,跳过这个圆前面的圆计算 let iPts: Vector3[]; - let index = 1; - for (; index < cirs.length; index++) + for (let index = 1; index < cirs.length; index++) { let pts = frontLine.IntersectWith(cirs[index], 0).filter(p => { @@ -517,23 +516,14 @@ export class PolyOffsetUtil }); if (pts.length === 0) { + cirs.splice(0, index - 1); break; } else - { iPts = pts; - } } if (!iPts) - { iPts = [frontLine.EndPoint]; - } - else - { - cirs.splice(0, index - 1); - } - - let iPt = this.selectFitInterPt(iPts, frontLine.EndPoint); this.appendNewCuAndContour(frontLine, nextPt, iPt, startIndex);