修复:判断轮廓是否镜像的方法

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

@ -297,6 +297,18 @@ test('镜像判断不足导致点表凸度错误', () =>
} }
}); });
test('镜像判断不足导致点表凸度错误2', () =>
{
let d = { "file": [2, "Polyline", 10, 2, 334, 0, 1, 1, 71, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 14.099999999652617, 1801.9929776066522, 0, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 14.099999999652617, 1801.9929776066522, 0, 1], 0, 0, 1, 2, 7, [-5.900000002308138, -2.9999999999995453], 1.0000000002948952, [-5.900000001151641, 3.0000000000004547], 0, [-43.90000000030762, 3.0000000000004547], 0.9999999997563894, [-43.90000000230811, -2.9999999999995453], 0, [-5.900000002308138, -2.9999999999995453], 0, [-5.90000000230814, 9.048410439361683e-13], 0, [-43.9000000023081, 9.094947017729282e-13], 0, false, "Polyline", 10, 2, 335, 0, 1, 1, 71, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, 2, 7, [2737.030476527089, 1478.0672999923568], 0.9999999993630507, [2737.0304765289998, 1484.0672999999997], 0, [2724.930476529, 1484.0672999999997], 0.9999999993630501, [2724.930476529, 1478.0672999999997], 0, [2737.030476527089, 1478.0672999923568], 0, [2737.0304765289998, 1481.0672999999997], 0, [2724.930476529, 1481.0672999999997], 0, false], "basePt": { "x": 17.000000000294897, "y": 1798.9929776066524, "z": -0.00002488151683044617 }, "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();
}
});
//测试代码 //测试代码
/** /**

@ -249,3 +249,91 @@ Object {
], ],
} }
`; `;
exports[`镜像判断不足导致点表凸度错误2 1`] = `
Object {
"buls": Array [
-1.0000000002948952,
-0,
-0.9999999997563894,
-0,
-0,
-0,
-0,
],
"pts": Array [
Vector2 {
"x": 20.000000001757833,
"y": 1798.9929776066526,
},
Vector2 {
"x": 20.000000000601332,
"y": 1804.9929776066526,
},
Vector2 {
"x": 57.99999999845034,
"y": 1804.9929776066526,
},
Vector2 {
"x": 58.00000000045083,
"y": 1798.9929776066526,
},
Vector2 {
"x": 20.000000001757833,
"y": 1798.9929776066526,
},
Vector2 {
"x": 20.000000001757833,
"y": 1801.992977606653,
},
Vector2 {
"x": 58.00000000045082,
"y": 1801.992977606653,
},
],
}
`;
exports[`镜像判断不足导致点表凸度错误2 2`] = `
Object {
"buls": Array [
-0.9999999993630507,
-0,
-0.9999999993630501,
-0,
-0,
-0,
-0,
],
"pts": Array [
Vector2 {
"x": 31.95000000194932,
"y": 1811.9522549136768,
},
Vector2 {
"x": 31.95000000003847,
"y": 1817.9522549213198,
},
Vector2 {
"x": 44.04999999962229,
"y": 1817.9522549213198,
},
Vector2 {
"x": 44.04999999962229,
"y": 1811.9522549213198,
},
Vector2 {
"x": 31.95000000194932,
"y": 1811.9522549136768,
},
Vector2 {
"x": 31.95000000003847,
"y": 1814.9522549213198,
},
Vector2 {
"x": 44.04999999962229,
"y": 1814.9522549213198,
},
],
}
`;

@ -4,7 +4,7 @@ import { Vector2ApplyMatrix4 } from "../Common/Matrix4Utils";
import { Arc } from "../DatabaseServices/Entity/Arc"; import { Arc } from "../DatabaseServices/Entity/Arc";
import { Circle } from "../DatabaseServices/Entity/Circle"; import { Circle } from "../DatabaseServices/Entity/Circle";
import { Polyline } from "../DatabaseServices/Entity/Polyline"; import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { equaln, equalv3 } from "../Geometry/GeUtils"; import { equaln } from "../Geometry/GeUtils";
/**轮廓(多段线Pts Bul)数据 */ /**轮廓(多段线Pts Bul)数据 */
@ -16,7 +16,6 @@ export interface IContourData
const x = new Vector3; const x = new Vector3;
const y = new Vector3; const y = new Vector3;
const z = new Vector3;
let tempPolyline: Polyline; let tempPolyline: Polyline;
@ -42,19 +41,14 @@ export function ConverToPtsBul(cu: Polyline | Circle, isOutline = true): IContou
//判断是不是被镜像了 //判断是不是被镜像了
x.setFromMatrixColumn(ocs, 0); x.setFromMatrixColumn(ocs, 0);
y.setFromMatrixColumn(ocs, 1); y.setFromMatrixColumn(ocs, 1);
z.setFromMatrixColumn(ocs, 2);
let z1 = x.cross(y); let z1 = x.cross(y);
let isMirror = 0; let isMirror = !equaln(z1.z, 1, 1e-3);
if (equaln(ocs.elements[10], -1, 1e-4)) isMirror++;
if (!equalv3(z, z1)) isMirror++;
for (let i = 0; i < ptsBuls.pts.length; i++) for (let i = 0; i < ptsBuls.pts.length; i++)
{ {
Vector2ApplyMatrix4(ocs, ptsBuls.pts[i]); Vector2ApplyMatrix4(ocs, ptsBuls.pts[i]);
if (isMirror === 1) if (isMirror)
ptsBuls.buls[i] *= -1; ptsBuls.buls[i] *= -1;
// else if (isMirror === 0) { }//测试覆盖率
// else if (isMirror === 2) { }//测试覆盖率
} }
if (isOutline && cu.IsClose) if (isOutline && cu.IsClose)

Loading…
Cancel
Save