diff --git a/__test__/EdgeSealing/BoardHighHole.test.ts b/__test__/EdgeSealing/BoardHighHole.test.ts new file mode 100644 index 000000000..5b0cf1759 --- /dev/null +++ b/__test__/EdgeSealing/BoardHighHole.test.ts @@ -0,0 +1,28 @@ +import { InitRectBoardHoleOption, IRectHoleOption, SetRectHighHole } from "../../src/Add-on/DrawDrilling/HoleUtils"; +import "../Utils/jest.util"; +import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util"; + +test('分析上下左右排钻错误', () => +{ + let d = { "file": [1, "Board", 8, 2, 100, false, 1, 3, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, -663.6125654450263, 18, -228.07330801010744, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -663.6125654450263, 18, -228.07330801010744, 1], 0, 3, 1583.8020726116358, 409.9999999999068, 18, true, "Polyline", 8, 2, 0, false, 0, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2052, 2475.00000958101, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2052, 2475.00000958101, 0, 1], 0, 2, 4, [-1642.0000000000932, -2475.00000958101], 0, [-1642.0000000000932, -891.1979369693743], 0, [-2052, -891.1979369693743], 0, [-2052, -2475], 0, true, 0, 3, 0, 0, 0, 0, 0, 10, 2, "左开门板", "男孩房衣柜", "门板+见光板", "4*9尺华纶卡其L1075", "颗粒板", "华纶卡其L1075", 0, 0, "不排", 2, 0, "0.8", "0.8", "0.8", "0.8", "", "", "", 4, "不排", "不排", "不排", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0], "basePt": { "x": -663.6125654450263, "y": 0, "z": -228.07330801010744 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let brs = LoadBoardsFromFileData(d); + + let rectHoleOption: IRectHoleOption = { + up: "", + down: "", + left: "", + right: "" + }; + + InitRectBoardHoleOption(brs[0], rectHoleOption); + expect(rectHoleOption).toMatchSnapshot(); + + + SetRectHighHole(brs[0], { + up: "三合一", + down: "二合一", + left: "不排", + right: "不排" + }); + expect(brs[0].BoardProcessOption.highDrill).toMatchSnapshot(); +}); diff --git a/__test__/EdgeSealing/__snapshots__/BoardHighHole.test.ts.snap b/__test__/EdgeSealing/__snapshots__/BoardHighHole.test.ts.snap new file mode 100644 index 000000000..99a317f9b --- /dev/null +++ b/__test__/EdgeSealing/__snapshots__/BoardHighHole.test.ts.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`分析上下左右排钻错误 1`] = ` +Object { + "down": "不排", + "left": "不排", + "right": "不排", + "up": "不排", +} +`; + +exports[`分析上下左右排钻错误 2`] = ` +Array [ + "不排", + "三合一", + "不排", + "二合一", +] +`; diff --git a/src/Add-on/DrawDrilling/HoleUtils.ts b/src/Add-on/DrawDrilling/HoleUtils.ts index 2cae802cb..d30763743 100644 --- a/src/Add-on/DrawDrilling/HoleUtils.ts +++ b/src/Add-on/DrawDrilling/HoleUtils.ts @@ -9,7 +9,7 @@ import { Circle } from "../../DatabaseServices/Entity/Circle"; import { Curve } from "../../DatabaseServices/Entity/Curve"; import { Line } from "../../DatabaseServices/Entity/Line"; import { Polyline } from "../../DatabaseServices/Entity/Polyline"; -import { angle, equaln, isParallelTo, rotatePoint, ZAxis } from "../../Geometry/GeUtils"; +import { angle, clampRad, isParallelTo, rotatePoint, ZAxis } from "../../Geometry/GeUtils"; import { DrillType } from "../../UI/Store/BoardInterface"; export const SCALAR = 0.1; @@ -166,7 +166,9 @@ export function InitRectBoardHoleOption(br: Board, option: IRectHoleOption) let c = cus[i]; let derv = c.GetFistDeriv(0).multiplyScalar(dir); let an = angle(derv); - if (equaln(an, 0) || (an < Math.PI / 4 + 1e-8 && an > Math.PI * 7 / 4)) + an = clampRad(an); + + if (an < Math.PI / 4 + 1e-8 || an > Math.PI * 7 / 4) option.down = hightDrill[i]; else if (an > Math.PI / 4 && an < Math.PI * 3 / 4 + 1e-8) option.right = hightDrill[i]; @@ -207,7 +209,9 @@ export function SetRectHighHole(br: Board, option: IRectHoleOption) let c = cus[i]; let derv = c.GetFistDeriv(0).multiplyScalar(dir); let an = angle(derv); - if (equaln(an, 0) || (an < Math.PI / 4 + 1e-8 && an > Math.PI * 7 / 4)) + an = clampRad(an); + + if (an < Math.PI / 4 + 1e-8 || an > Math.PI * 7 / 4) highDrill.push(option.down); else if (an > Math.PI / 4 && an < Math.PI * 3 / 4 + 1e-8) highDrill.push(option.right); diff --git a/src/GraphicsSystem/CalcEdgeSealing.ts b/src/GraphicsSystem/CalcEdgeSealing.ts index db1ed0b80..ca014408e 100644 --- a/src/GraphicsSystem/CalcEdgeSealing.ts +++ b/src/GraphicsSystem/CalcEdgeSealing.ts @@ -10,7 +10,7 @@ import { ExtrudeContourCurve } 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 { angle, clampRad, equaln, equalv3, isParallelTo, SelectNearP, XAxis } from "../Geometry/GeUtils"; import { Production } from "../Production/Product"; import { IHighSealedItem, ISealingData } from "../UI/Store/BoardInterface"; import { IntersectOption } from "./IntersectWith"; @@ -270,7 +270,10 @@ export function GetBoardHighSeal(br: Board, sealcus: Curve[]): IHighSealedItem[] { let derv = c.GetFistDeriv(0).multiplyScalar(dir); let an = angle(derv); - if (equaln(an, 0) || (an < Math.PI / 4 + 1e-8 && an > Math.PI * 7 / 4)) + + an = clampRad(an); + + if ((an < Math.PI / 4 + 1e-8) || (an > Math.PI * 7 / 4)) highSeals.push({ size: sealDown }); else if (an > Math.PI / 4 && an < Math.PI * 3 / 4 + 1e-8) highSeals.push({ size: sealRight });