From 11e1d3ca42db71a08ecc6bda9d9452ac0ca5022a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=AF=97=E6=B4=A5?= <2723065175@qq.com> Date: Fri, 23 Aug 2024 07:33:36 +0000 Subject: [PATCH] =?UTF-8?q?!2972=20=E4=BC=98=E5=8C=96:=E4=BA=8C=E7=BB=B4?= =?UTF-8?q?=E5=88=80=E8=B7=AF=E5=8D=8A=E5=BE=84=E5=8A=A8=E4=BD=9C=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Fillet/__snapshots__/radius.test.ts.snap | 209 ++++++++++++++++++ __test__/Fillet/radius.test.ts | 50 +++++ .../Template/Action/TemplateaRadiusAction.ts | 13 +- 3 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 __test__/Fillet/__snapshots__/radius.test.ts.snap create mode 100644 __test__/Fillet/radius.test.ts diff --git a/__test__/Fillet/__snapshots__/radius.test.ts.snap b/__test__/Fillet/__snapshots__/radius.test.ts.snap new file mode 100644 index 000000000..946101114 --- /dev/null +++ b/__test__/Fillet/__snapshots__/radius.test.ts.snap @@ -0,0 +1,209 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`二维刀路半径动作 1`] = ` +Array [ + Object { + "dir": 0, + "items": Array [ + Object { + "depth": 15, + "depthExpr": "15", + "knife": Object { + "angle": 0, + "id": "4832", + "name": "222", + "radius": 10, + }, + "offset": 0, + }, + ], + "path": Polyline { + "AutoUpdate": true, + "HasBigHoleFaceRenderType": false, + "HasEdgeRenderType": false, + "HasPlaceFaceRenderType": false, + "IsEmbedEntity": false, + "NeedUpdateFlag": 0, + "OnlyRenderType": true, + "_CacheDrawObject": Map {}, + "_ClosedMark": false, + "_Color": 1, + "_CurRenderType": undefined, + "_Freeze": false, + "_Layer": undefined, + "_LineData": Array [ + Object { + "bul": -0.8491062833823316, + "pt": Vector2 { + "x": 95.91836734693862, + "y": 575.5102040816324, + }, + }, + Object { + "bul": 0, + "pt": Vector2 { + "x": 490.4761904761907, + "y": 564.6258503401358, + }, + }, + ], + "_LockMaterial": false, + "_MaterialId": undefined, + "_Matrix": Matrix4 { + "elements": Array [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + ], + }, + "_Owner": undefined, + "_SpaceOCS": Matrix4 { + "elements": Array [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + ], + }, + "_Visible": true, + "_VisibleInRender": true, + "__ProcessingGroupList": Array [], + "__ReadFileIng__": false, + "__UpdateVersion__": 1, + "_db": undefined, + "_drawObject": undefined, + "_isErase": false, + "objectId": undefined, + }, + }, +] +`; + +exports[`二维刀路半径高度动作 1`] = ` +Array [ + Object { + "dir": 0, + "items": Array [ + Object { + "depth": 15, + "depthExpr": "15", + "knife": Object { + "angle": 0, + "id": "4832", + "name": "222", + "radius": 10, + }, + "offset": 0, + }, + ], + "path": Polyline { + "AutoUpdate": true, + "HasBigHoleFaceRenderType": false, + "HasEdgeRenderType": false, + "HasPlaceFaceRenderType": false, + "IsEmbedEntity": false, + "NeedUpdateFlag": 0, + "OnlyRenderType": true, + "_CacheDrawObject": Map {}, + "_ClosedMark": false, + "_Color": 1, + "_CurRenderType": undefined, + "_Freeze": false, + "_Layer": undefined, + "_LineData": Array [ + Object { + "bul": -1.0134075758007557, + "pt": Vector2 { + "x": 95.91836734693862, + "y": 575.5102040816324, + }, + }, + Object { + "bul": 0, + "pt": Vector2 { + "x": 490.4761904761907, + "y": 564.6258503401358, + }, + }, + ], + "_LockMaterial": false, + "_MaterialId": undefined, + "_Matrix": Matrix4 { + "elements": Array [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + ], + }, + "_Owner": undefined, + "_SpaceOCS": Matrix4 { + "elements": Array [ + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + ], + }, + "_Visible": true, + "_VisibleInRender": true, + "__ProcessingGroupList": Array [], + "__ReadFileIng__": false, + "__UpdateVersion__": 1, + "_db": undefined, + "_drawObject": undefined, + "_isErase": false, + "objectId": undefined, + }, + }, +] +`; diff --git a/__test__/Fillet/radius.test.ts b/__test__/Fillet/radius.test.ts new file mode 100644 index 000000000..1a4a951a1 --- /dev/null +++ b/__test__/Fillet/radius.test.ts @@ -0,0 +1,50 @@ +import { Board } from "../../src/DatabaseServices/Entity/Board"; +import { TempalteActionRadiusType, TemplateaRadiusAction } from "../../src/DatabaseServices/Template/Action/TemplateaRadiusAction"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; +Board; +LoadEntityFromFileData; + +//如果不延迟导入,则导致循环依赖错误 +import { Database } from "../../src/DatabaseServices/Database"; + +test('二维刀路半径动作', () => +{ + let d = + { "file": [1, "Board", 11, 2, 100, 0, 1, 2, 71, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1564.6258503401364, 318.3673469387755, 0, 1], 244, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 364.62585034013637, 318.3673469387755, 0, 1], 0, 0, 1, 61, 3, 1200, 600, 18, true, "Polyline", 11, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 0, 2, 4, [0, 0], 0, [600, 0], 0, [600, 1200], 0, [0, 1200], 0, true, 0, 3, 0, 0, 0, 0, 0, 22, 0, "层板", "", "", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 4, "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 1, "Polyline", 11, 2, 0, 0, 0, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 0, 2, 2, [95.91836734693862, 575.5102040816324], -0.26386885101222296, [490.4761904761907, 564.6258503401358], 0, false, 0, 1, 15, 0, "4832", 10, 0, "222", "15", 0, null, 1, "4832", "Polyline", 11, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 25.399487084036537, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -3566.242006162735, -1297.3985627344691, 0, 1], 0, 0, 1, 0, 2, 5, [10, 2.2737367544323206e-13], 0, [0, 0], 0, [-10, 0], 0, [0, -25.399487084036537], 0, [10, 2.2737367544323206e-13], 0, false, 0, "", "", "", "", 0, false, 0, "", 0, 0], "basePt": { "x": 364.62585034013637, "y": 318.3673469387755, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let board = LoadEntityFromFileData(d)[0] as Board; + let db = new Database; + db.ModelSpace.Append(board); + + let action = new TemplateaRadiusAction(TempalteActionRadiusType.Radius); + action.FilletDatas.push({ + Entity: board.Id, + ArcParams: [], + Grooves: [], + Path2D: [{ Index: 0, ArcParams: [0.5] }], + ArcSweepPathParams: [] + }); + + action.Update(200, -200); + expect(board.Modeling2D).toMatchSnapshot(); +}); + +test('二维刀路半径高度动作', () => +{ + let d = + { "file": [1, "Board", 11, 2, 198, 0, 1, 2, 71, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1564.6258503401364, -1674.5369423494335, 36, 1], 199, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 364.62585034013637, -1674.5369423494335, 36, 1], 0, 0, 1, 61, 3, 1200, 600, 18, true, "Polyline", 11, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 0, 2, 4, [0, 0], 0, [600, 0], 0, [600, 1200], 0, [0, 1200], 0, true, 0, 3, 0, 0, 0, 0, 0, 22, 0, "层板", "", "", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 4, "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 1, "Polyline", 11, 2, 0, 0, 0, 1, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 0, 2, 2, [95.91836734693862, 575.5102040816324], -0.2533518939501889, [490.4761904761907, 564.6258503401358], 0, false, 0, 1, 15, 0, "4832", 10, 0, "222", "15", 0, null, 1, "4832", "Polyline", 11, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 25.399487084036537, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -3566.242006162735, -1297.3985627344691, 0, 1], 0, 0, 1, 0, 2, 5, [10, 2.2737367544323206e-13], 0, [0, 0], 0, [-10, 0], 0, [0, -25.399487084036537], 0, [10, 2.2737367544323206e-13], 0, false, 0, "", "", "", "", 0, false, 0, "", 0, 0], "basePt": { "x": 364.62585034013637, "y": -1674.5369423494335, "z": 36 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let board = LoadEntityFromFileData(d)[0] as Board; + let db = new Database(); + db.ModelSpace.Append(board); + + let action = new TemplateaRadiusAction(TempalteActionRadiusType.Height); + action.FilletDatas.push({ + Entity: board.Id, + ArcParams: [], + Grooves: [], + Path2D: [{ Index: 0, ArcParams: [0.5] }], + ArcSweepPathParams: [] + }); + + action.Update(-150, -200); + expect(board.Modeling2D).toMatchSnapshot(); +}); diff --git a/src/DatabaseServices/Template/Action/TemplateaRadiusAction.ts b/src/DatabaseServices/Template/Action/TemplateaRadiusAction.ts index 918109cf0..f03b228b6 100644 --- a/src/DatabaseServices/Template/Action/TemplateaRadiusAction.ts +++ b/src/DatabaseServices/Template/Action/TemplateaRadiusAction.ts @@ -1,4 +1,3 @@ -import { FixIndex } from "../../../Common/Utils"; import { AutoRecord } from "../../AutoRecord"; import { Factory } from "../../CADFactory"; import { CADFiler } from "../../CADFiler"; @@ -63,7 +62,17 @@ export class TemplateaRadiusAction extends TemplateFilletAction else { let p1 = cu.GetPointAtParam(Math.floor(arcParam)); - let p2 = cu.GetPointAtParam(FixIndex(Math.floor(arcParam) + 1, cu.EndParam)); + const FixIndex = (index: number, count: number, isClose = true) => + { + if (index < 0) + return count + index; + //没有闭合的曲线最后一个索引不变回原点 + else if (isClose && index >= count || !isClose && index > count) + return index - count; + else + return index; + }; + let p2 = cu.GetPointAtParam(FixIndex(Math.floor(arcParam) + 1, cu.EndParam, cu.IsClose)); let dist = p1.distanceTo(p2); let bul: number;