From bc5faff5b42f33b3b1c181ced3750111c26073d9 Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 16 Jun 2021 17:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=E5=AF=B9=E5=B0=81=E8=BE=B9?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E7=9A=84=E6=9D=BF=E8=BF=9B=E8=A1=8C=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E5=81=8F=E7=A7=BB,=E8=80=8C=E9=9D=9E=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=81=8F=E7=A7=BB=20fix=20#I39T1I?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/EdgeSealing/EdgeSealing.test.ts | 33 ++++++++------- __test__/EdgeSealing/OneEdgeSealing.test.ts | 19 +++++++++ .../__snapshots__/EdgeSealing.test.ts.snap | 42 +++++++++---------- .../__snapshots__/OneEdgeSealing.test.ts.snap | 17 ++++++++ src/GraphicsSystem/CalcEdgeSealing.ts | 36 +++++++++++++++- 5 files changed, 108 insertions(+), 39 deletions(-) create mode 100644 __test__/EdgeSealing/OneEdgeSealing.test.ts create mode 100644 __test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap diff --git a/__test__/EdgeSealing/EdgeSealing.test.ts b/__test__/EdgeSealing/EdgeSealing.test.ts index 68754c069..d05bf9cd8 100644 --- a/__test__/EdgeSealing/EdgeSealing.test.ts +++ b/__test__/EdgeSealing/EdgeSealing.test.ts @@ -1,7 +1,8 @@ import { Board } from "../../src/DatabaseServices/Entity/Board"; import { Curve } from "../../src/DatabaseServices/Entity/Curve"; import { Polyline } from "../../src/DatabaseServices/Entity/Polyline"; -import { CalcEdgeSealing, ParagraphCulist, GetSealedBoardContour } from "../../src/GraphicsSystem/CalcEdgeSealing"; +import { CalcEdgeSealing, GetSealedBoardContour, ParagraphCulist } from "../../src/GraphicsSystem/CalcEdgeSealing"; +import "../Utils/jest.util"; import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util"; function testBrSealing(br: Board, sealingSize: number[]) @@ -123,7 +124,7 @@ test("椭圆弧封边", () => let con = GetSealedBoardContour(br, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); }); test("封边错误板件", () => { @@ -133,7 +134,7 @@ test("封边错误板件", () => let con = GetSealedBoardContour(br, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); }); test("封边错误板件2", () => { @@ -143,7 +144,7 @@ test("封边错误板件2", () => let con = GetSealedBoardContour(br, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); }); test("封边错误板件3", () => { @@ -153,7 +154,7 @@ test("封边错误板件3", () => let con = GetSealedBoardContour(br, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); }); test("封边错误板件4", () => { @@ -163,7 +164,7 @@ test("封边错误板件4", () => let con = GetSealedBoardContour(br, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); }); test("切割残留一个封边厚度的凸角的板件封边", () => @@ -173,13 +174,13 @@ test("切割残留一个封边厚度的凸角的板件封边", () => let con = GetSealedBoardContour(brs[0], false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); - expect(con.Length).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); + expect(con.Length).toMatchNumberSnapshot(); con = GetSealedBoardContour(brs[1], false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); - expect(con.Length).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); + expect(con.Length).toMatchNumberSnapshot(); }); test("切割残留2个封边厚度的凸角的板件封边", () => @@ -191,8 +192,8 @@ test("切割残留2个封边厚度的凸角的板件封边", () => { let con = GetSealedBoardContour(b, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); - expect(con.Length).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); + expect(con.Length).toMatchNumberSnapshot(); } }); test("切割残留一个小于封边厚度的凸角的板件封边", () => @@ -204,8 +205,8 @@ test("切割残留一个小于封边厚度的凸角的板件封边", () => { let con = GetSealedBoardContour(b, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); - expect(con.Length).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); + expect(con.Length).toMatchNumberSnapshot(); } }); test("获取封边错误案例", () => @@ -217,7 +218,7 @@ test("获取封边错误案例", () => { let con = GetSealedBoardContour(b, false); expect(con.IsClose).toBeTruthy(); - expect(con.Area).toMatchSnapshot(); - expect(con.Length).toMatchSnapshot(); + expect(con.Area2).toMatchNumberSnapshot(); + expect(con.Length).toMatchNumberSnapshot(); } }); diff --git a/__test__/EdgeSealing/OneEdgeSealing.test.ts b/__test__/EdgeSealing/OneEdgeSealing.test.ts new file mode 100644 index 000000000..f47805bdb --- /dev/null +++ b/__test__/EdgeSealing/OneEdgeSealing.test.ts @@ -0,0 +1,19 @@ +import { GetSealedBoardContour } from "../../src/GraphicsSystem/CalcEdgeSealing"; +import "../Utils/jest.util"; +import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util"; + +test('只有一个封边,并且失败的案例', () => +{ + let d = + { "file": [4, "Board", 8, 2, 121, false, 1, 1, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 5156.78604262264, 155.71155098138843, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5156.78604262264, 155.71155098138843, -517.2053991103303, 1], 0, 3, 1332.7946008896697, 60, 18, false, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1332.7946008896697, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 6, [0.9999999999995453, -1332.7946008896697], 0, [0.9999999999995453, -1332], 0, [60, -1332], 0, [60, 0], 0, [0, 0], 0, [0, -1332.7946008896697], 0, true, 0, 3, 0, 0, 0, 0, 0, 10, 1, "右收口条", "榻米衣柜及书桌", "柜体4右收口", "固峰希腊白", "多层板", "希腊白", 0, 0, "不排", 2, 0, "1", "1", "1", "1", "", "", "", 6, "不排", "不排", "不排", "不排", "不排", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 8, 2, 125, false, 1, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5019.321452985634, 377.9382754993276, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 4283.636154264983, 377.9382754993276, 0, 1], 0, 3, 116.0936470770996, 492.7358454018065, 18, false, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -410.58187625625226, -2.2737367544323206e-13, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -410.58187625625226, -2.2737367544323206e-13, 0, 1], 0, 2, 8, [903.0128456459614, 0.042011759224124035], 0.00006257940248264371, [903.3177216580588, 0.044582197205727425], 0, [903.1637146020545, 18.0439233470006], -0.00006250723639880799, [902.8636905320473, 18.041393772886522], -0.002076508735090201, [892.896577535593, 17.999999999999773], -0.10213911426261756, [417.70988855098807, 116.09364707709983], 0, [410.5818762562526, 99.56514318901282], 0.10213916213559157, [892.8965775355929, 4.547473508864641e-13], 0.0020764365686957082, true, 0, 3, 0, 0, 0, 0, 0, 10, 2, "背板", "", "", "", "", "", 1, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 8, "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 8, 2, 126, false, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4947.116633075755, 488.82041104941163, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 4211.431334355104, 488.82041104941163, 0, 1], 0, 3, 116.09364707712712, 492.73584540181275, 18, false, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4.547473508864641e-13, 99.56514318901509, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -69.12869845001791, -1926.3342224071403, 0, 1], 0, 2, 6, [492.73584540181236, -99.52056099181004], 0, [492.5818383458083, -81.52121984201517], -0.00006250723639903003, [492.2818142757997, -81.52374941612948], -0.10423773106609027, [7.128012294613768, 16.528503888112027], 0, [0, 0], 0.10423770600938752, [492.4309693897147, -99.52313142979142], 0.00006257940248264371, true, 0, 3, 0, 0, 0, 0, 0, 10, 2, "背板", "", "", "", "", "", 1, 0, "三合一", 2, 4, 1, 1, 1, 1, "1", "1", "1", "1", "", "", "", 6, "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, "Board", 8, 2, 127, false, 1, 4, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 5078.087564233807, 657.0134638837771, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5078.087564233807, 657.0134638837771, 0, 1], 0, 3, 2111.999999999998, 350, 18, false, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 2031, 0, 1], 0, 0, true, [0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, -1207.750629722921, -11265.46679826914, 0, 1], 0, 2, 8, [350, -2031], 0, [350, 80.99999999999818], 0, [147, 80.99999999999818], 0, [147, 80], -0.41421356237309503, [107, 40], 0, [40, 40], 0.41421356237309503, [0, 0], 0, [0, -2031], 0, true, 0, 3, 0, 0, 0, 0, 0, 10, 1, "右侧板", "大厅", "鞋柜", "格绿", "生态板", "和风细雨", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 8, "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0], "basePt": { "x": 4947.116633075755, "y": 155.71155098138843, "z": 0 }, "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__/EdgeSealing.test.ts.snap b/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap index 07cd41ab7..62ddc8b1f 100644 --- a/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap +++ b/__test__/EdgeSealing/__snapshots__/EdgeSealing.test.ts.snap @@ -4,33 +4,33 @@ exports[`丢失线段板件 1`] = `554052.5007766777`; exports[`丢失线段板件 2`] = `398758.8789695821`; -exports[`切割残留2个封边厚度的凸角的板件封边 1`] = `30420`; +exports[`切割残留2个封边厚度的凸角的板件封边 1`] = `"30127.50000"`; -exports[`切割残留2个封边厚度的凸角的板件封边 2`] = `1274`; +exports[`切割残留2个封边厚度的凸角的板件封边 2`] = `"1273.00000"`; -exports[`切割残留一个封边厚度的凸角的板件封边 1`] = `30420`; +exports[`切割残留一个封边厚度的凸角的板件封边 1`] = `"30420.00000"`; -exports[`切割残留一个封边厚度的凸角的板件封边 2`] = `1274`; +exports[`切割残留一个封边厚度的凸角的板件封边 2`] = `"1274.00000"`; -exports[`切割残留一个封边厚度的凸角的板件封边 3`] = `30420`; +exports[`切割残留一个封边厚度的凸角的板件封边 3`] = `"30420.00000"`; -exports[`切割残留一个封边厚度的凸角的板件封边 4`] = `1274`; +exports[`切割残留一个封边厚度的凸角的板件封边 4`] = `"1274.00000"`; -exports[`切割残留一个小于封边厚度的凸角的板件封边 1`] = `30127.5`; +exports[`切割残留一个小于封边厚度的凸角的板件封边 1`] = `"30127.50000"`; -exports[`切割残留一个小于封边厚度的凸角的板件封边 2`] = `1273`; +exports[`切割残留一个小于封边厚度的凸角的板件封边 2`] = `"1273.00000"`; -exports[`切割残留一个小于封边厚度的凸角的板件封边 3`] = `30127.5`; +exports[`切割残留一个小于封边厚度的凸角的板件封边 3`] = `"30127.50000"`; -exports[`切割残留一个小于封边厚度的凸角的板件封边 4`] = `1273`; +exports[`切割残留一个小于封边厚度的凸角的板件封边 4`] = `"1273.00000"`; -exports[`封边错误板件 1`] = `130118.40946854133`; +exports[`封边错误板件 1`] = `"130118.40950"`; -exports[`封边错误板件2 1`] = `779770.9650700318`; +exports[`封边错误板件2 1`] = `"779770.96110"`; -exports[`封边错误板件3 1`] = `359947.9362569036`; +exports[`封边错误板件3 1`] = `"359947.95128"`; -exports[`封边错误板件4 1`] = `30748.998495139338`; +exports[`封边错误板件4 1`] = `"30748.99860"`; exports[`常规板件,常规坐标系 1`] = `716404`; @@ -58,16 +58,16 @@ exports[`异型板件,非相切圆弧 1`] = `635612.2751433642`; exports[`异型板件,非相切圆弧 2`] = `626242.2196800549`; -exports[`椭圆弧封边 1`] = `23816.280001593965`; +exports[`椭圆弧封边 1`] = `"23816.28000"`; -exports[`获取封边错误案例 1`] = `153800.9412630349`; +exports[`获取封边错误案例 1`] = `"153800.94126"`; -exports[`获取封边错误案例 2`] = `1812.3606355214206`; +exports[`获取封边错误案例 2`] = `"1812.36064"`; -exports[`获取封边错误案例 3`] = `163941`; +exports[`获取封边错误案例 3`] = `"163941.00000"`; -exports[`获取封边错误案例 4`] = `1876`; +exports[`获取封边错误案例 4`] = `"1876.00000"`; -exports[`获取封边错误案例 5`] = `165821`; +exports[`获取封边错误案例 5`] = `"165821.00000"`; -exports[`获取封边错误案例 6`] = `1884`; +exports[`获取封边错误案例 6`] = `"1884.00000"`; diff --git a/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap b/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap new file mode 100644 index 000000000..3e5a06beb --- /dev/null +++ b/__test__/EdgeSealing/__snapshots__/OneEdgeSealing.test.ts.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`只有一个封边,并且失败的案例 1`] = `"77140.00000"`; + +exports[`只有一个封边,并且失败的案例 2`] = `"2776.00000"`; + +exports[`只有一个封边,并且失败的案例 3`] = `"8009.31415"`; + +exports[`只有一个封边,并且失败的案例 4`] = `"1033.16428"`; + +exports[`只有一个封边,并且失败的案例 5`] = `"8009.31415"`; + +exports[`只有一个封边,并且失败的案例 6`] = `"1033.16428"`; + +exports[`只有一个封边,并且失败的案例 7`] = `"728287.33629"`; + +exports[`只有一个封边,并且失败的案例 8`] = `"4881.66371"`; diff --git a/src/GraphicsSystem/CalcEdgeSealing.ts b/src/GraphicsSystem/CalcEdgeSealing.ts index a3a589aab..1c3138094 100644 --- a/src/GraphicsSystem/CalcEdgeSealing.ts +++ b/src/GraphicsSystem/CalcEdgeSealing.ts @@ -8,6 +8,7 @@ import { Curve } from "../DatabaseServices/Entity/Curve"; import { ExtureContourCurve } from "../DatabaseServices/Entity/Extrude"; import { Line } from "../DatabaseServices/Entity/Line"; import { Polyline } from "../DatabaseServices/Entity/Polyline"; +import { CreateContour2 } from "../Geometry/CreateContour2"; import { angle, equaln, equalv3, isParallelTo, SelectNearP, XAxis } from "../Geometry/GeUtils"; import { Production } from "../Production/Product"; import { IHighSealedItem } from "../UI/Store/BoardInterface"; @@ -323,13 +324,14 @@ export function GetBoardSealingCurves(br: Board, isOffset = false): Curve[] */ export function GetSealedBoardContour(br: Board, hasSealing: boolean): Polyline | Circle | undefined { - if (equaln(br.ContourCurve.Area, 0)) + let area2 = br.ContourCurve.Area2; + if (Math.abs(area2) < 10) return; let offsetCus: Curve[] = []; let cus = GetBoardSealingCurves(br); let highSeals = GetBoardHighSeal(br, cus); - let dir = Math.sign(br.ContourCurve.Area2); + let dir = Math.sign(area2); if (hasSealing) { @@ -346,6 +348,36 @@ export function GetSealedBoardContour(br: Board, hasSealing: boolean): Polyline if (cus[0] instanceof Circle) dir = 1; + //所有的封边都一样时 + if (highSeals.every(s => equaln(s.size, highSeals[0].size), 1e-3)) + { + let brContour = br.ContourCurve; + + let retPl: ExtureContourCurve; + + if (!highSeals[0].size || equaln(highSeals[0].size, 0, 1e-3)) + { + retPl = brContour.Clone(); + if (dir < 0) + retPl.Reverse(); + } + else + { + retPl = brContour.GetOffsetCurves(-highSeals[0].size * dir)[0] as ExtureContourCurve; + + if (retPl && !retPl.IsClose) + { + //某些情况下,这里会出现非闭合轮廓 + retPl = CreateContour2([retPl]).Curve; + } + + if (retPl && retPl.Area2 < 0) + retPl.Reverse(); + } + + return retPl; + } + for (let i = 0; i < cus.length; i++) { let cs: Curve[];