From 91201a5eec472ba196e0de01ac6a880422e6d8d7 Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 20 Dec 2023 17:23:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E5=B9=B6=E9=9B=86=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/bool6.test.ts.snap | 4 ++++ __test__/Booloperate/bool6.test.ts | 18 ++++++++++++++++++ src/DatabaseServices/Contour.ts | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/__test__/Booloperate/__snapshots__/bool6.test.ts.snap b/__test__/Booloperate/__snapshots__/bool6.test.ts.snap index 612bc61ff..9c98a27d2 100644 --- a/__test__/Booloperate/__snapshots__/bool6.test.ts.snap +++ b/__test__/Booloperate/__snapshots__/bool6.test.ts.snap @@ -1,5 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`并集错误 1`] = `"580529.02133"`; + +exports[`并集错误 2`] = `1`; + exports[`无法求到交集 1`] = `6966`; exports[`精度不一致导致的板件显示错误 1`] = `"84"`; diff --git a/__test__/Booloperate/bool6.test.ts b/__test__/Booloperate/bool6.test.ts index ef133c1de..ec86c2b83 100644 --- a/__test__/Booloperate/bool6.test.ts +++ b/__test__/Booloperate/bool6.test.ts @@ -1,4 +1,5 @@ import { Board } from "../../src/DatabaseServices/Entity/Board"; +import { Region } from "../../src/DatabaseServices/Entity/Region"; import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils"; import { LoadEntityFromFileData, LoadRegionsFromFileData } from "../Utils/LoadEntity.util"; import "../Utils/jest.util"; @@ -25,3 +26,20 @@ test('精度不一致导致的板件显示错误', () => expect(br.MeshGeometry.getAttribute("position").count).toMatchNumberSnapshot(0); }); + +test('并集错误', () => +{ + //原因: 两条线 已经相似(fastEqualCurve) 在判断方向相同时,因为精度问题,我们错误的认为它不同向,将判断同向的精度改成0.01后解决 + + let d = { "file": [2, "Region", 10, 2, 106, 0, 1, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, 1, 1, 1, 1, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, 2, 11, [487.3242, 322.0844], 0, [498.26980000000003, 538.7396], 0, [499.17220000000003, 755.6124], 0, [490.02970000000005, 972.3511000000001], 0, [455.53470000000004, 1303.1193], 0, [-2.5761000000000003, 1238.6734000000001], 0, [30.600900000000003, 881.4381000000001], 0, [36.0287, 647.2415000000001], 0, [28.446, 413.1016], 0, [-8.023100000000001, 56.1227], 0, [450.08520000000004, -8.3225], 0, true, 0, "Region", 10, 2, 107, 0, 1, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, 1, 1, 1, 1, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 863.9694986599663, 458.07124371859294, 0, 1], 0, 0, 1, 2, 14, [431.2735, 107.0175], 0, [452.0221, 322.5664], 0, [462.70520000000005, 538.8478], 0, [463.2995, 755.3922], 0, [453.80260000000004, 971.7552000000001], 0, [419.08840000000004, 1297.9876000000002], 0, [405.99760000000003, 1296.1904], 0, [439.3514, 970.7397000000001], 0, [448.81690000000003, 755.0946], 0, [448.2244, 539.224], 0, [437.57460000000003, 323.6175], 0, [416.8883, 108.7181], 0, [402.36, -1.6169], 0, [415.41150000000005, -3.4817], 0, true, 0], "basePt": { "x": 855.9463986599663, "y": 449.74874371859295, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + + let regs = LoadEntityFromFileData(d) as Region[]; + + let ok = regs[0].BooleanOper(regs[1], BoolOpeartionType.Union); + + expect(ok).toBeTruthy(); + + expect(regs[0].Area).toMatchNumberSnapshot(); + + expect(regs[0].ShapeManager.ShapeList.length).toMatchSnapshot(); +}); diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index b71d627ce..f32d4d3d4 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -283,7 +283,7 @@ export class Contour { //方向相同 if ( - equalv3(cu.GetFirstDeriv(cu.MidParam).normalize(), pl.GetFirstDeriv(pl.MidParam).normalize(), 1e-3) + equalv3(cu.GetFirstDeriv(cu.MidParam).normalize(), pl.GetFirstDeriv(pl.MidParam).normalize(), 1e-2) === isEqualNormal ) {