You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/__test__/Interfere/intf.test.ts

37 lines
3.6 KiB

import { Contour } from "../../src/DatabaseServices/Contour";
import { Board } from "../../src/DatabaseServices/Entity/Board";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import "../Utils/jest.util";
import { LoadBoardsFromFileData, LoadEntityFromFileData } from "../Utils/LoadEntity.util";
test('求交集错误', () =>
{
let d =
[2, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [9.094947017729282e-12, -1411.0000000000002], 0, [9.094947017729282e-12, 2423], 0, [-17.999999999990905, 2423], 0, [-17.999999999990905, -1411.0000000000002], 0, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 2, 8, [540, 0], 0, [540, 102], 0, [552, 102], 0, [561, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [0, 0], 0, true];
let pls = LoadEntityFromFileData(d) as Polyline[];
let cons = pls.map(pl => Contour.CreateContour(pl));
let res = cons[0].GetIntersetAndUnionList(cons[1]);
expect(res.unionList.length).toMatchSnapshot();
expect(res.intersectionList.length).toMatchSnapshot();
for (let c of res.unionList)
expect(c.Length).toMatchNumberSnapshot();
for (let c of res.intersectionList)
expect(c.Length).toMatchNumberSnapshot();
});
test('obb 无法求交', () =>
{
let d =
{ "file": [2, "Board", 10, 2, 100, 0, 1, 2, 71, [0, -1.8369701987210297e-16, -1, 0, -1, 0, 0, 0, 0, 1, -1.8369701987210297e-16, 0, 2119.1214642262894, 559.840266222962, 462, 1], 0, 0, 1, [1, 0, 0, 0, 0, -1.8369701987210297e-16, -1, 0, 0, 1, -1.8369701987210297e-16, 0, 2119.1214642262894, 559.840266222962, 462, 1], 0, 0, 1, 3, 1892, 462, 18, true, "Polyline", 10, 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, 2, 4, [0, 0], 0, [462, 0], 0, [462, 1892], 0, [0, 1892], 0, true, 0, 3, 0, 0, 0, 0, 0, 11, 0, "层板", "2", "榻榻米", "18里精致灰生态板", "生态板", "精致灰", 0, 0, "xxx三", 2, 0, "1", "1", "1", "1", "", "", "", 4, "xxx三", "xxx三", "xxx三", "xxx三", false, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, null, "Board", 10, 2, 101, 0, 1, 2, 71, [0, 1, -2.828030789094926e-16, 0, 4.281864857152846e-9, 2.828030789094926e-16, 1, 0, 1, 0, 0, 0, 1164.1214642262896, -4.159733777038266, 60, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, -2.828030789094926e-16, 0, 4.281864857152846e-9, 2.828030789094926e-16, 1, 0, 1164.1214642262896, -4.159733777038266, 60, 1], 0, 0, 1, 3, 402, 582, 18, false, "Polyline", 10, 2, 0, 0, 0, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 352.00000000000017, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 6, [582, -352.00000000000017], 0, [582, 49.99999999999983], 0, [18, 49.99999999999983], 0, [18, 5.684341886080802e-14], 0, [0, 0], 0, [0, -352.00000000000017], 0, true, 0, 3, 0, 0, 0, 0, 0, 11, 1, "立板", "2", "榻榻米", "18里精致灰生态板", "生态板", "精致灰", 0, 0, "xxx三", 2, 6, 1, 1, 1, 1, 1, 1, "1", "1", "1", "1", "", "", "", 6, "xxx三", "xxx三", "xxx三", "xxx三", "xxx三", "xxx三", true, true, 0, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, null], "basePt": { "x": 227.1214642262894, "y": -4.159733777038266, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let brs = LoadBoardsFromFileData(d) as Board[];
expect(brs[0].OBB.intersectsOBB(brs[1].OBB)).toBeTruthy();
});