修复:走刀路径错误的凸度翻转

pull/2241/MERGE
ChenX 1 year ago
parent 20164f4f61
commit 359582154f

@ -1,8 +1,6 @@
import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils";
import { LoadRegionsFromFileData } from "../Utils/LoadEntity.util";
// file.only
test('无法求到交集', () =>
{
let d = { "file": [2, "Region", 8, 2, 138, false, 1, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 402.7349980402736, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 402.7349980402736, 0, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 402.7349980402736, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 402.7349980402736, 0, 0, 1], 0, 2, 4, [0, 0], 0, [387, 0], 0, [387, 18], 0, [0, 18], 0, true, 0, "Region", 8, 2, 139, false, 1, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 377.7349980402736, -38.99960000002761, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 377.7349980402736, -38.99960000002761, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 377.7349980402736, -38.99960000002761, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 377.7349980402736, -764.0012000002525, 0, 1], 0, 2, 6, [412, 725.0016000002249], 0, [0, 725.0016000002249], 0, [0, 0], 0, [25, 0], 0, [25, -56.998399999775074], 0, [412, -56.998399999775074], 0, true, 0], "basePt": { "x": 377.7349980402736, "y": -764.0012000002525, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };

@ -4,7 +4,7 @@ import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { CalcEdgeSealing, GetBoardSealingData, GetSealedBoardContour, SubsectionCurvesOfHightSeal } from "../../src/GraphicsSystem/CalcEdgeSealing";
import { ConverToPtsBul } from "../../src/Production/Convert2PtsBul";
import "../Utils/jest.util";
import { LoadBoardsFromFileData } from "../Utils/LoadEntity.util";
import { LoadBoardsFromFileData, LoadEntityFromFileData } from "../Utils/LoadEntity.util";
function testBrSealing(br: Board, sealingSize: number[])
{
@ -283,3 +283,32 @@ test('封边编辑错误', () =>
expect(orgContour.Length).toMatchNumberSnapshot();
}
});
test('镜像判断不足导致点表凸度错误', () =>
{
let d = { "file": [4, "Polyline", 10, 2, 100, 0, 1, 7, 71, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, -0.000008293838842595351, 0.9999999999656061, 0, 200.34819277044215, 14.855421686746922, 0, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, -0.000008293838842595351, 0.9999999999656061, 0, 200.34819277044215, 14.855421686746922, 0, 1], 0, 0, 1, 2, 7, [-5.900000002308047, -3], 0, [-43.90000000230799, -3], -0.9999999997563863, [-43.90000000030756, 2.9999999999997726], 0, [-5.900000001151568, 3], -1.0000000002949003, [-5.900000002308047, -3], 0, [-5.900000002307912, -4.653657836759924e-15], 0, [-43.90000000230776, 0], 0, false, "Polyline", 10, 2, 101, 0, 1, 7, 71, [0.9999999999656061, 1.2246467991473532e-16, -1.2246467991052327e-16, 0, 1.2246467991052325e-16, -1, -1.8369701986578493e-16, 0, 1.224646799105233e-16, -0.000008293838842595351, 0.9999999999656061, 0, 322.34387027729207, 14.855421686746922, -7.43884581007662e-15, 1], 0, 0, 1, [0.9999999999656061, 1.2246467991473532e-16, -1.2246467991052327e-16, 0, 1.2246467991052325e-16, -1, -1.8369701986578493e-16, 0, 1.224646799105233e-16, -0.000008293838842595351, 0.9999999999656061, 0, 322.34387027729207, 14.855421686746922, -7.43884581007662e-15, 1], 0, 0, 1, 2, 7, [-43.90000000230782, -1.7763568394002505e-15], 0, [-5.900000002307991, 3.552713678800501e-15], 0, [-5.900000002308104, 2.9999999999999982], -1.0000000002949003, [-5.900000001151625, -3.0000000000000018], 0, [-43.900000000307614, -2.999999999999771], -0.9999999997563863, [-43.90000000230805, 2.9999999999999982], 0, [-5.900000002308104, 2.9999999999999982], 0, false, "Polyline", 10, 2, 102, 0, 1, 7, 71, [0.9999999999656061, 1.2246467991473532e-16, -1.2246467991052327e-16, 0, -1.224646799105233e-16, 1, -1.8369701986578488e-16, 0, -1.2246467991052325e-16, -0.000008293838842595351, -0.9999999999656061, 0, 487.598092036143, 14.855421686746922, -1.9424999332486008, 1], 0, 0, 1, [0.9999999999656061, 1.2246467991473532e-16, -1.2246467991052327e-16, 0, 1.224646799105233e-16, -1, 1.8369701986578488e-16, 0, -1.2246467991052325e-16, -0.000008293838842595351, -0.9999999999656061, 0, 487.598092036143, 14.855421686746922, -1.9424999332486008, 1], 0, 0, 1, 2, 7, [-5.900000002308047, -3], 0, [-43.90000000230799, -3], -0.9999999997563863, [-43.90000000030756, 2.9999999999997726], 0, [-5.900000001151568, 3], -1.0000000002949003, [-5.900000002308047, -3], 0, [-5.900000002307912, -4.653657836759924e-15], 0, [-43.90000000230776, 0], 0, false, "Polyline", 10, 2, 103, 0, 1, 7, 71, [-0.9999999999656061, 1.2246467991473532e-16, 2.4492935982104654e-16, 0, -1.2246467991052322e-16, -1, 1.8369701986578496e-16, 0, -2.4492935982104654e-16, -0.000008293838842595351, -0.9999999999656061, 0, 365.60241452929307, 14.855421686746922, -1.9424999332485784, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 2.4492935982104654e-16, 0, -1.2246467991052322e-16, -1, 1.8369701986578496e-16, 0, -2.4492935982104654e-16, -0.000008293838842595351, -0.9999999999656061, 0, 365.60241452929307, 14.855421686746922, -1.9424999332485784, 1], 0, 0, 1, 2, 7, [-43.90000000230782, -1.7763568394002505e-15], 0, [-5.900000002307991, 3.552713678800501e-15], 0, [-5.900000002308104, 2.9999999999999982], -1.0000000002949003, [-5.900000001151625, -3.0000000000000018], 0, [-43.900000000307614, -2.999999999999771], -0.9999999997563863, [-43.90000000230805, 2.9999999999999982], 0, [-5.900000002308104, 2.9999999999999982], 0, false], "basePt": { "x": 203.24819277108432, "y": 11.855421686746917, "z": -1.9425248147651277 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pls = LoadEntityFromFileData(d) as Polyline[];
for (let pl of pls)
{
let ptsbuls = ConverToPtsBul(pl, false);
expect(ptsbuls).toMatchSnapshot();
}
});
//测试代码
/**
let enRes = await app.Editor.GetEntity({ Filter: { filterTypes: [Polyline] } });
if (enRes.Status !== PromptStatus.OK) return;
let pl = enRes.Entity as Polyline;
let ptsbuls = ConverToPtsBul(pl, false);
let newpl = new Polyline(
ptsbuls.pts.map((p, i) =>
{
return { pt: p, bul: ptsbuls.buls[i] };
})
);
TestDraw(newpl, 1);
*/

@ -73,3 +73,179 @@ exports[`获取封边错误案例 4`] = `"1876.00000"`;
exports[`获取封边错误案例 5`] = `"165821.00000"`;
exports[`获取封边错误案例 6`] = `"1884.00000"`;
exports[`镜像判断不足导致点表凸度错误 1`] = `
Object {
"buls": Array [
-0,
0.9999999997563863,
-0,
1.0000000002949003,
-0,
-0,
-0,
],
"pts": Array [
Vector2 {
"x": 206.24819277254727,
"y": 11.855421686746922,
},
Vector2 {
"x": 244.24819277124024,
"y": 11.855421686746917,
},
Vector2 {
"x": 244.2481927692398,
"y": 17.855421686746688,
},
Vector2 {
"x": 206.2481927713908,
"y": 17.855421686746922,
},
Vector2 {
"x": 206.24819277254727,
"y": 11.855421686746922,
},
Vector2 {
"x": 206.24819277254716,
"y": 14.855421686746917,
},
Vector2 {
"x": 244.24819277124,
"y": 14.855421686746917,
},
],
}
`;
exports[`镜像判断不足导致点表凸度错误 2`] = `
Object {
"buls": Array [
-0,
-0,
1.0000000002949003,
-0,
0.9999999997563863,
-0,
-0,
],
"pts": Array [
Vector2 {
"x": 278.4438702764941,
"y": 14.855421686746919,
},
Vector2 {
"x": 316.443870275187,
"y": 14.855421686746919,
},
Vector2 {
"x": 316.4438702751869,
"y": 11.855421686746922,
},
Vector2 {
"x": 316.4438702763434,
"y": 17.855421686746922,
},
Vector2 {
"x": 278.44387027849433,
"y": 17.855421686746688,
},
Vector2 {
"x": 278.4438702764939,
"y": 11.855421686746919,
},
Vector2 {
"x": 316.4438702751869,
"y": 11.855421686746922,
},
],
}
`;
exports[`镜像判断不足导致点表凸度错误 3`] = `
Object {
"buls": Array [
0,
-0.9999999997563863,
0,
-1.0000000002949003,
0,
0,
0,
],
"pts": Array [
Vector2 {
"x": 481.69809203403787,
"y": 11.855421686746922,
},
Vector2 {
"x": 443.69809203534487,
"y": 11.855421686746917,
},
Vector2 {
"x": 443.6980920373453,
"y": 17.855421686746688,
},
Vector2 {
"x": 481.69809203519435,
"y": 17.855421686746922,
},
Vector2 {
"x": 481.69809203403787,
"y": 11.855421686746922,
},
Vector2 {
"x": 481.698092034038,
"y": 14.855421686746917,
},
Vector2 {
"x": 443.6980920353451,
"y": 14.855421686746917,
},
],
}
`;
exports[`镜像判断不足导致点表凸度错误 4`] = `
Object {
"buls": Array [
0,
0,
-1.0000000002949003,
0,
-0.9999999997563863,
0,
0,
],
"pts": Array [
Vector2 {
"x": 409.502414530091,
"y": 14.855421686746919,
},
Vector2 {
"x": 371.50241453139813,
"y": 14.855421686746919,
},
Vector2 {
"x": 371.50241453139824,
"y": 11.855421686746922,
},
Vector2 {
"x": 371.50241453024177,
"y": 17.855421686746922,
},
Vector2 {
"x": 409.5024145280908,
"y": 17.855421686746688,
},
Vector2 {
"x": 409.50241453009124,
"y": 11.855421686746919,
},
Vector2 {
"x": 371.50241453139824,
"y": 11.855421686746922,
},
],
}
`;

@ -1,9 +1,6 @@
import { Euler, Matrix4, Vector3 } from "three";
import { equaln } from "../../src/Geometry/GeUtils";
// file.only
//证明 EU和旋转矩阵复合的转换
test('Euler', () =>
{

@ -52,5 +52,3 @@ test('range2', () =>
expect(SubtractRange(0.1, 0.8, 0.3, 0.6, 1)).toMatchSnapshot();
expect(SubtractRange(0.1, 0.8, 0.3, 0.9, 1)).toMatchSnapshot();
});
// file.only

@ -8,8 +8,6 @@ import { RoomWallLine } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWa
import { WallCurveDirType } from "../../src/DatabaseServices/Room/ParseService/RoomRegionParse";
import { RoomWallParse } from "../../src/DatabaseServices/Room/ParseService/RoomWallParse";
// file.only
test('分析房间和墙的关系', () =>
{
let d =

@ -76,9 +76,9 @@ export class FeedingCommand implements Command
let sealingContour = Production.Data2Polyline(info.outline);
originContour.ApplyMatrix(tMtx);
originContour.ApplyMatrix(tMtx);//原始轮廓 绿色
originContour.ColorIndex = 3;
sealingContour.ApplyMatrix(tMtx);
sealingContour.ApplyMatrix(tMtx);//扣除封边的轮廓 灰色
sealingContour.ColorIndex = 9;
app.Database.ModelSpace.Append(originContour);
app.Database.ModelSpace.Append(sealingContour);

@ -224,7 +224,7 @@ export class FeedingToolPath extends Singleton
GetModelFeedPath(br: { Thickness: number, ContourCurve: ExtrudeContourCurve; }, modeling: IModeling): Curve[]
{
const brThickness = br.Thickness;
let cus: Curve[] = [];
let cus: Curve[] = [];//返回走刀路径
let { shape, thickness, knifeRadius, addLen, addWidth, addDepth } = modeling;
if (!knifeRadius) knifeRadius = 3;
if (addDepth)
@ -240,9 +240,8 @@ export class FeedingToolPath extends Singleton
if (outline instanceof Circle && equaln(outline.Radius, modeling.knifeRadius))
return [new Polyline([{ pt: AsVector2(outline.Center), bul: 0 }, { pt: AsVector2(outline.Center), bul: 0 }])];
if (thickness >= brThickness)
if (thickness >= brThickness) //通孔只切一刀
{
//通孔只切一刀
let dir = GetCurveToInDir(outline);
let paths: Curve[];
if (outline instanceof Circle)
@ -378,6 +377,7 @@ export class FeedingToolPath extends Singleton
return errHoles;
}
HandleThoughGroove(brCon: ExtrudeContourCurve, shape: Shape, knifeRadius: number)
{
let outline = shape.Outline.Curve;
@ -487,6 +487,7 @@ export class FeedingToolPath extends Singleton
}
}
}
if (hasChange)
{
let con = Contour.CreateContour(Polyline.Combine(cus));
@ -497,6 +498,7 @@ export class FeedingToolPath extends Singleton
}
}
}
export function GetModelingFromCustomDrill(br: Board)
{
let normal = br.Normal;

@ -76,15 +76,14 @@ export function OptimizeToolPath(offsetCus: Curve[], originShape: Shape, rad: nu
let dir = GetCurveToInDir(outline);
let cantIntCur: Curve[] = [outline];
cantIntCur.push(...GetOffsetCurves(outline, rad * dir));
if (originShape.Holes.length > 0)
//洞的外圈走一刀
for (let h of originShape.Holes)
{
for (let h of originShape.Holes)
{
let dir = Math.sign(h.Curve.Area2);
if (h.Curve instanceof Circle)
dir = 1;
cantIntCur.push(h.Curve, ...GetOffsetCurves(h.Curve, rad * dir));
}
let dir = Math.sign(h.Curve.Area2);
if (h.Curve instanceof Circle)
dir = 1;
cantIntCur.push(h.Curve, ...GetOffsetCurves(h.Curve, rad * dir));
}
//曲线统一起点

@ -4,7 +4,7 @@ import { Vector2ApplyMatrix4 } from "../Common/Matrix4Utils";
import { Arc } from "../DatabaseServices/Entity/Arc";
import { Circle } from "../DatabaseServices/Entity/Circle";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { equaln } from "../Geometry/GeUtils";
import { equaln, equalv3 } from "../Geometry/GeUtils";
/**轮廓(多段线Pts Bul)数据 */
@ -14,8 +14,19 @@ export interface IContourData
buls: number[];
}
const x = new Vector3;
const y = new Vector3;
const z = new Vector3;
//转换成多段线点表(pts bul)
let tempPolyline: Polyline;
/**
* 线(pts bul)
* @param cu
* @param [isOutline=true] ,
* @returns pts buls
*/
export function ConverToPtsBul(cu: Polyline | Circle, isOutline = true): IContourData
{
let ptsBuls: IContourData;
@ -25,23 +36,42 @@ export function ConverToPtsBul(cu: Polyline | Circle, isOutline = true): IContou
ptsBuls = pl.PtsBuls;
}
else
{
if (isOutline && cu.IsClose && cu.Normal.z * cu.Area2 < 0)
cu.Reverse();
ptsBuls = cu.PtsBuls;
}
let ocs = cu.OCSNoClone;
if (!equaln(ocs.elements[0], 1)
|| !equaln(ocs.elements[9], 0)
|| !equaln(ocs.elements[10], 0)
)
//判断是不是被镜像了
x.setFromMatrixColumn(ocs, 0);
y.setFromMatrixColumn(ocs, 1);
z.setFromMatrixColumn(ocs, 2);
let z1 = x.cross(y);
let isMirror = 0;
if (equaln(ocs.elements[10], -1, 1e-4)) isMirror++;
if (!equalv3(z, z1)) isMirror++;
for (let i = 0; i < ptsBuls.pts.length; i++)
{
Vector2ApplyMatrix4(ocs, ptsBuls.pts[i]);
if (isMirror === 1)
ptsBuls.buls[i] *= -1;
// else if (isMirror === 0) { }//测试覆盖率
// else if (isMirror === 2) { }//测试覆盖率
}
if (isOutline && cu.IsClose)
{
tempPolyline = tempPolyline || new Polyline;
tempPolyline.LineData.length = 0;
for (let i = 0; i < ptsBuls.pts.length; i++)
tempPolyline.LineData.push({ pt: ptsBuls.pts[i], bul: ptsBuls.buls[i] });
if (cu.Area2 < 0)
{
Vector2ApplyMatrix4(ocs, ptsBuls.pts[i]);
ptsBuls.buls[i] *= cu.Normal.z;
tempPolyline.Reverse();
ptsBuls = tempPolyline.PtsBuls;
}
tempPolyline.LineData.length = 0;
}
return ptsBuls;
}

@ -282,8 +282,8 @@ export namespace Production
m.knifeRadius = HostApplicationServices.chaidanOption.radius;
data.push({
outline: ConverToPtsBul(cu.Clone(), false),
holes: m.shape.Holes.map(h => ConverToPtsBul(h.Curve.Clone(), false)),
outline: ConverToPtsBul(cu, false),
holes: m.shape.Holes.map(h => ConverToPtsBul(h.Curve, false)),
thickness: m.thickness + (m.addDepth ?? 0),
dir: m.dir,
knifeRadius: m.knifeRadius,
@ -301,6 +301,12 @@ export namespace Production
return { modeling, sideModeling };
}
/**
* ( )
* @param br
* @param offsetTanslation
*/
export function GetBoardModelingData(br: Board, offsetTanslation: Vector3)
{
const tool = FeedingToolPath.GetInstance();
@ -316,10 +322,11 @@ export namespace Production
continue;
if (HostApplicationServices.chaidanOption.useDefaultRad)
m.knifeRadius = HostApplicationServices.chaidanOption.radius;
let paths = tool.GetModelFeedPath(br, m);
let paths = tool.GetModelFeedPath(br, m);//走刀路径
if (!isSide)
paths.forEach(path => path.ApplyMatrix(tMtx));
//走刀的ptsbuls
let feeding = paths.map((c: ExtrudeContourCurve) => ConverToPtsBul(c, false));
if (feeding.length > 0)
data.push({
@ -328,8 +335,8 @@ export namespace Production
dir: m.dir,
knifeRadius: m.knifeRadius,
origin: {
outline: ConverToPtsBul(cu.Clone(), false),
holes: m.shape.Holes.map(h => ConverToPtsBul(h.Curve.Clone(), false)),
outline: ConverToPtsBul(cu, false),
holes: m.shape.Holes.map(h => ConverToPtsBul(h.Curve, false)),
addLen: m.addLen,
addWidth: m.addWidth,
addDepth: m.addDepth,

Loading…
Cancel
Save