diff --git a/__test__/EdgeSealing/OneEdgeSealing.test.ts b/__test__/EdgeSealing/OneEdgeSealing.test.ts index 5d66eb057..602ca5b1b 100644 --- a/__test__/EdgeSealing/OneEdgeSealing.test.ts +++ b/__test__/EdgeSealing/OneEdgeSealing.test.ts @@ -33,3 +33,19 @@ test('只有一个封边,并且失败的案例(展示这个改进的缺陷的地 expect(con.Length).toMatchNumberSnapshot(); } }); + +test('偏移后曲线不闭合的问题', () => +{ + let d = + { "file": [1, "Board", 8, 2, 137, false, 1, 4, 0, [-1.8369701987210297e-16, -1, 0, 0, 0, 0, 1, 0, -1, 1.8369701987210297e-16, 0, 0, 1294.2320411714973, 300.3864645821159, -77.81148543980584, 1], 0, 0, true, [-1.8369701987210297e-16, -1, 0, 0, 1, -1.8369701987210297e-16, 0, 0, 0, 0, 1, 0, 1294.2320411714973, 300.3864645821159, -77.81148543980584, 1], 0, 3, 391.2271, 64.5794295120013, 18, false, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -15312.627584699, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -15312.627584699, 0, 0, 1], 0, 2, 20, [15368.177451746, 207.7892], -0.001715932, [15369.259901937, 258.6605], 0.014190138, [15374.529207322, 332.1809], 0.13371958, [15352.837584699, 390.6834], 0, [15352.837584699, 187.2], 0, [15334.817584699, 187.2], 0, [15334.817044013, 391.2271], 0.215796468, [15315.698324922, 309.4969], -0.01395558, [15320.518932854, 190.4847], -0.002175123, [15319.827584699, 79.2], -0.000333642, [15322.227584698, 49.2], 0.084045656, [15312.627584699, 9], 0, [15322.227584699, 9], 0, [15322.227584699, 0], 0, [15365.427584699, 0], 0, [15365.427584699, 9], 0, [15377.207014211, 9], 0.092440732, [15365.427584699, 55.2], -0.00015712, [15369.027584698, 78], -0.000156089, [15367.97674234, 104.4], -0.000039603, true, 0, 3, 0, 0, 0, 0, 0, 10, 2, "收口条", "", "_收口条", "", "", "", 0, 0, "不排", 2, 0, "1", "1", "1", "1", "", "", "", 20, "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0], "basePt": { "x": 1276.2320411714973, "y": 235.80703507011458, "z": -77.81148543980584 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + + let brs = LoadBoardsFromFileData(d); + + for (let br of brs) + { + let con = GetSealedBoardContour(br, false); + expect(con.IsClose).toBeTruthy(); + expect(con.Area2).toMatchNumberSnapshot(); + expect(con.Length).toMatchNumberSnapshot(); + } +}); diff --git a/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap b/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap index 188859cc0..481814c10 100644 --- a/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap +++ b/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`偏移后曲线不闭合的问题 1`] = `"14601.05213"`; + +exports[`偏移后曲线不闭合的问题 2`] = `"1271.45304"`; + exports[`只有一个封边,并且失败的案例 1`] = `"77140.00000"`; exports[`只有一个封边,并且失败的案例 2`] = `"2776.00000"`; diff --git a/src/GraphicsSystem/CalcEdgeSealing.ts b/src/GraphicsSystem/CalcEdgeSealing.ts index 1c3138094..998f09bb6 100644 --- a/src/GraphicsSystem/CalcEdgeSealing.ts +++ b/src/GraphicsSystem/CalcEdgeSealing.ts @@ -368,14 +368,14 @@ export function GetSealedBoardContour(br: Board, hasSealing: boolean): Polyline if (retPl && !retPl.IsClose) { //某些情况下,这里会出现非闭合轮廓 - retPl = CreateContour2([retPl]).Curve; + retPl = CreateContour2([retPl])?.Curve; } if (retPl && retPl.Area2 < 0) retPl.Reverse(); } - return retPl; + if (retPl) return retPl; } for (let i = 0; i < cus.length; i++) diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index 09ac4acf2..f7896595b 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -683,15 +683,17 @@ export class OffsetPolyline private RepairResultPolylineClosemark() { - if (this._RetCurves.length && this._Polyline.CloseMark) + if (!this._RetCurves.length) return; + + if (this._Polyline.CloseMark) { - if (!equalv2(this._Polyline.LineData[0].pt, arrayLast(this._Polyline.LineData).pt, 1e-3))//缺省一个点 + if (!equalv2(this._Polyline.LineData[0].pt, arrayLast(this._Polyline.LineData).pt, 8e-2))//缺省一个点 { for (let pl of this._RetCurves) { if (pl.IsClose && //封闭 equaln(arrayLast(pl.LineData).bul, 0, 1e-5) &&//是直线 - equalv2(pl.LineData[0].pt, arrayLast(pl.LineData).pt, 1e-3))//首尾重复(一般已经是了) + equalv2(pl.LineData[0].pt, arrayLast(pl.LineData).pt, 8e-2))//首尾重复(一般已经是了) { pl.LineData.pop();//移除最后一点 pl.CloseMark = true; @@ -707,6 +709,16 @@ export class OffsetPolyline } } } + else if (this._IsClose) + { + for (let pl of this._RetCurves) + { + let firstP = pl.LineData[0].pt; + let lastP = arrayLast(pl.LineData).pt; + if (equalv2(firstP, lastP, 8e-2)) + lastP.copy(firstP); + } + } } CheckPointDir(pt: Vector3): boolean