From 20368903ac0ed1dd9ec09b8c02c1e20df7d91471 Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Mon, 16 Sep 2019 17:31:32 +0800 Subject: [PATCH] =?UTF-8?q?!500=20=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/offset.test.ts | 4 ++-- __test__/Polyline/offsetbug.test.ts | 27 +++++++++++++++++++++++++++ src/GraphicsSystem/OffsetPolyline.ts | 14 +++++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/__test__/Polyline/offset.test.ts b/__test__/Polyline/offset.test.ts index 9f6050931..3d6550cb1 100644 --- a/__test__/Polyline/offset.test.ts +++ b/__test__/Polyline/offset.test.ts @@ -494,7 +494,7 @@ describe("补圆弧测试", () => expect(cus[0].GetOffsetCurves(i).length).toBe(1); } }) - test("补圆弧测试3", () => + test("补圆弧测试4", () => { let data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 23, [-25.572010711696727, -62.383195892823124], 0, [-10.312959798454724, -40.55427583637971], 0, [0.28360333574111785, -55.81332674962171], 0, [9.820510156517361, -48.18380129300071], 0, [18.721623189241864, -65.13830230771404], 0, [29.530117586121616, -60.47581452866788], 0, [39.06702440689787, -79.97349069558823], 0, [51.78290016793288, -70.64851513749588], -0.6227891115113805, [70.85671380948538, -80.60928448363998], 0.3759603135798005, [86.75155851077912, -99.68309812519247], -1.1383492019405204, [81.45327694368122, -117.6972554533254], 0.6271394112393051, [57.2931129977147, -138.2545879336653], -1.2933960333754264, [21.68866086681669, -138.2545879336653], -0.8106183277649434, [-17.73055399239181, -132.9563063665674], 0, [-43.37423677714574, -105.82910474302606], 0, [-51.003762233766736, -83.5763221612148], 0, [-48.67251834424364, -64.07864599429448], 0, [-62.65998168138215, -50.09118265715597], 0, [-86.39628310198083, -65.35023357039795], 0, [-86.39628310198083, -33.13668164244262], 0, [-73.68040734094582, -13.639005475522275], 0, [-43.16230551446182, -13.639005475522275], 0, [-33.62539869368556, -11.307761585999202], 0, false] @@ -509,7 +509,7 @@ describe("补圆弧测试", () => //需要删除一个无效的线段 ref #IKO6L expect(cus[0].GetOffsetCurves(27.3).length).toBe(1); }) - test("补圆弧测试3", () => + test("补圆弧测试5", () => { let data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 10, [-5.637393767705383, -1.586402266288952], 0, [-0.84985835694051, 1.954674220963173], -0.5207626681247078, [1.728045325779038, 1.0906515580736542], -1.2136457904456304, [4.060938624362605, 1.3838754084985838], -1.0694858869096764, [6.891142200566573, -0.047681051558073895], -1.4716493502287318, [9.178341602266286, -2.976612659490083], -1.5003222663355726, [8.09233325325779, -7.040916632294616], -0.9628743606456998, [4.53257790368272, -7.478753541076488], -1.076087427994497, [2.3229461756373926, -7.478753541076488], 0, [-5.39660056657224, -7.478753541076487], 0, false] diff --git a/__test__/Polyline/offsetbug.test.ts b/__test__/Polyline/offsetbug.test.ts index 119b2e130..b98324dd7 100644 --- a/__test__/Polyline/offsetbug.test.ts +++ b/__test__/Polyline/offsetbug.test.ts @@ -73,3 +73,30 @@ test("偏移真交点判断错误", () => expect(cus.length).toBe(1); }) + +test("补圆弧错误01", () => +{ + let data = + [1, "Polyline", 5, 2, 102, false, 1, 7, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, -248.36561743341508, -235.59093395827813, 0, 1], 0, 0, 2, 4, [150, 74.99999999999999], -0.9999999999999997, [300, 74.99999999999903], 0.5398412275759912, [90.31248359508209, 212.61322750888567], 0, [137.41283997485402, 33.411090345222135], 0.14801304447405583, true] + + let pl = loadFile(data)[0]; + + let cus = pl.GetOffsetCurves(180); + expect(cus.length).toBe(1); + +}) +test("补圆弧错误02", () => +{ + let data = + [1, "Polyline", 5, 2, 101, false, 1, 7, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 222.42531269162828, 290.34989003720335, 0, 1], 0, 0, 2, 5, [30.164179214139466, -146.93577608035883], 0, [-2.966375216967549, -20.884369768256875], -0.3337793930899486, [-74.99999999999987, -74.99999999999926], -0.4142135623730949, [-149.99999999999986, 6.821210263296962e-13], 0.4142135623730963, [-2.842170943040401e-14, -149.99999999999986], 0.050662063831163964, true] + + let pl = loadFile(data)[0]; + + let cus = pl.GetOffsetCurves(120); + expect(cus.length).toBe(1); + + cus = pl.GetOffsetCurves(145); + expect(cus.length).toBe(1); + +}) + diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index c2a2e042f..2afed9da5 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -65,6 +65,7 @@ export class PolyOffsetUtil } //连接修剪并构建轮廓 this.TrimAndBuildContour(offres); + //裁剪并优化的曲线 let boxCurves = this.TrimByContours(); //优化删除无效和连接共线,必须执行上一步 @@ -464,13 +465,13 @@ export class PolyOffsetUtil if (index === endIndex) break; } - //找到和frontline存在离源线段距离大于偏移距离的交点的圆,跳过这个圆前面的圆计算 let iPts: Vector3[]; let index = 1; for (; index < cirs.length; index++) { - let pts = frontLine.IntersectWith(cirs[index], 0).filter(p => + //#I1264R + let pts = frontLine.IntersectWith(cirs[index], 1).filter(p => { let dist = p.distanceToSquared(this._Polyline.GetClosestPointTo(p, false)); return dist + 1e-3 > this._Dist2; @@ -518,9 +519,16 @@ export class PolyOffsetUtil let c2 = cirs[index + 1]; + let selectPts: Vector3[] = []; let iPts = c1.IntersectWith(c2, 0); - let iPt = PolyOffsetUtil.SelectFitInterPt(iPts, nextPt); + //#I1264R 第一条补圆弧并且frontline是直线,尽量让圆弧方向和直线一致 + if (index === 0 && frontLine instanceof Line) + { + let derv = frontLine.GetFistDeriv(1); + selectPts = iPts.filter(p => p.clone().sub(nextPt).angleTo(derv) < Math.PI / 2); + } + let iPt = PolyOffsetUtil.SelectFitInterPt(selectPts.length > 0 ? selectPts : iPts, nextPt); this.BuildArcJoinList(c1, nextPt, iPt, FixIndex(startIndex + 1, this._PtCount) === endIndex); } }