!2972 优化:二维刀路半径动作功能

pull/2949/MERGE
黄诗津 1 month ago committed by ChenX
parent 4d407cc306
commit 11e1d3ca42

@ -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,
},
},
]
`;

@ -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();
});

@ -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;

Loading…
Cancel
Save