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__/Booloperate/bool4.test.ts

78 lines
8.7 KiB

import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils";
import { LoadRegionsFromFileData } from "../Utils/LoadEntity.util";
test('交点大于等于2_但是还是分离', () =>
{
let d = [2, "Region", 3, 2, 629, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 1, 1, 1, "Polyline", 3, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [5842.2632447015285, -382.81544021645357], 0, [6075.449244701528, -382.81544021645357], 0, [6075.449244701528, -210.8902402164536], 0, [5842.2632447015285, -210.8902402164536], 0, true, 0, "Region", 3, 2, 630, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 1, 1, 1, "Polyline", 3, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 8, [5622.910304827508, -210.8902402164536], 0, [5842.2632447015285, -210.8902402164536], 0, [5842.2632447015285, -13.274942384012917], 0, [6075.449244701528, -13.274942384012888], 0, [6075.449244701528, -210.8902402164536], 0, [6253.303004827509, -210.8902402164536], 0, [6253.303004827509, 291.05255978354637], 0, [5622.910304827508, 291.05255978354637], 0, true, 0];
let [reg1, reg2] = LoadRegionsFromFileData(d);
let reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Union);
expect(reg.Area).toMatchSnapshot();
reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Subtract);
expect(reg.Area).toMatchSnapshot();
});
test(`#I118PO`, () =>
{
let d =
[2, "Region", 5, 2, 109, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 1, 1, 1, "Polyline", 5, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 4, [0, 0], 0, [349.99999999999983, 0], 0, [349.99999999999983, 18], 0, [0, 18], 0, true, 0, "Region", 5, 2, 110, false, 1, 7, 0, [-0.6481962787933795, -0.7614732983883384, -3.969057490217688e-17, 0, 0.7614732983883384, -0.6481962787933795, 4.66267918753728e-17, 0, 6.123233995736766e-17, 0, -1, 0, -507.79108398045344, 1098.4374795109752, -4.082417520817821e-14, 1], 0, 0, 1, 1, 1, 1, "Polyline", 5, 2, 0, false, 0, 7, 0, [-0.6481962787933795, -0.7614732983883384, -3.969057490217688e-17, 0, -0.7614732983883384, 0.6481962787933795, -4.66267918753728e-17, 0, 6.123233995736766e-17, 0, -1, 0, -507.79108398045344, 1098.4374795109752, -4.082417520817821e-14, 1], 0, 0, 2, 4, [9.993381848422814, -884.0586414166524], 0.17863084838388266, [280.4138219783257, -1365.1880927528969], 0, [507.2825195560087, -1098.6724383169787], -0.09662306706998787, [400.5809327775901, -964.8005274526736], 0, true, 0];
let [reg1, reg2] = LoadRegionsFromFileData(d);
let reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Intersection);
expect(reg.ShapeManager.ShapeCount).toBe(1);
expect(reg.Area).toMatchSnapshot();
});
test(`#I16PA6`, () =>
{
let d =
[2, "Region", 6, 2, 102, false, 1, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, 1, 1, 1, 1, "Polyline", 6, 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, 2, 4, [0, 0], 0, [268, 0], 0, [268, 18], 0, [0, 18], 0, true, 0, "Region", 6, 2, 103, false, 1, 2, 0, [0, -1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 268.0018656456669, 309.4999930386355, 0, 1], 0, 0, true, 1, 1, 1, 1, "Polyline", 6, 2, 0, false, 0, 7, 0, [0, -1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 268.0018656456669, 309.4999930386355, 0, 1], 0, 0, true, 2, 5, [0, 0], 0, [582.9999860772712, 0.0037312913331012574], 0, [581.9999860772712, 268.0037312913331], 0, [199, 268], 0.4152503874339878, [0, 68], 0, true, 0];
let [reg1, reg2] = LoadRegionsFromFileData(d);
let reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Intersection);
expect(reg.ShapeManager.ShapeCount).toBe(1);
expect(reg.Area).toMatchSnapshot();
d = [2, "Region", 6, 2, 113, false, 1, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, 1, 1, 1, 1, "Polyline", 6, 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, 2, 4, [0, 0], 0, [268, 0], 0, [268, 18], 0, [0, 18], 0, true, 0, "Region", 6, 2, 114, false, 1, 2, 0, [0, -1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 268.0037312913331, 581.9999860772712, 0, 1], 0, 0, true, 1, 1, 1, 1, "Polyline", 6, 2, 0, false, 0, 7, 0, [0, -1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 268.0037312913331, 581.9999860772712, 0, 1], 0, 0, true, 2, 5, [0, 0], 0, [582.9999860772712, 0.0037312913331012574], 0, [581.9999860772712, 268.0037312913331], 0, [199, 268], 0.4152503874339878, [0, 68], 0, true, 0];
[reg1, reg2] = LoadRegionsFromFileData(d);
reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Intersection);
expect(reg.ShapeManager.ShapeCount).toBe(1);
expect(reg.Area).toMatchSnapshot();
});
test('共线多余点', () =>
{
let d =
{ "file": [2, "Region", 8, 2, 142, false, 1, 7, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 0, true, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 0, true, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 2, 4, [0, 0], 0, [304, 0], 0, [304, 2164], 0, [0, 2164], 0, true, 0, "Region", 8, 2, 143, false, 1, 7, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 0, true, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 1, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 0, true, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, -1187.6342759146728, 857.8612440191389, 1], 0, 2, 6, [285.9999999999998, 0], 0, [291.9999999999998, 0], 0, [303.9999999999998, 0], 0, [303.9999999999998, 2164], 0, [291.99999999999983, 2164], 0, [285.9999999999998, 2164.0000000000005], 0, true, 0], "basePt": { "x": 0, "y": -1187.6342759146728, "z": 857.8612440191389 } };
let [reg1, reg2] = LoadRegionsFromFileData(d);
reg1.BooleanOper(reg2.Clone(), BoolOpeartionType.Subtract);
expect(reg1.Area).toMatchSnapshot();
});
test('精度问题,导致的曲线合并失败,导致的无法重新生成轮廓', () =>
{
let d =
{ "file": [2, "Region", 10, 2, 110, 0, 1, 7, 71, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 863.9997678387444, -200, 0, 1], 0, 0, 1, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 863.9997678387444, -200, 0, 1], 0, 0, 1, 1, 1, 1, 1, "Polyline", 10, 2, 0, 0, 0, 1, 71, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 863.9997678387444, -200, 0, 1], 0, 0, 1, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 863.9997678387444, -200, 0, 1], 0, 0, 1, 2, 4, [100, 0], 0, [400, 0], 0, [400, 864], 0, [100, 864], 0, true, 0, "Region", 10, 2, 111, 0, 1, 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, 1, 1, 1, 1, "Polyline", 10, 2, 0, 0, 0, 2, 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, -614.9118387909318, -117.20906801007538, 0, 1], 0, 0, 1, 2, 4, [0, 0], 0, [1728.0001196034718, 0], 0, [1728.0001196034718, 9.5], 0, [0, 9.5], 0, true, 0], "basePt": { "x": -0.00023216125555336475, "y": -100, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let [reg1, reg2] = LoadRegionsFromFileData(d);
reg1.BooleanOper(reg2.Clone(), BoolOpeartionType.Intersection);
expect(reg1.Area).toMatchSnapshot();
});
test('精度问题,导致布尔错误', () =>
{
let d =
{ "file": [2, "Region", 10, 2, 167, 0, 1, 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, 1, 1, 1, 1, "Polyline", 10, 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, 2, 4, [0, 0], 0, [388, 0], 0, [388, 2376], 0, [0, 2376], 0, true, 0, "Region", 10, 2, 168, 0, 1, 7, 71, [0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 279.25, 2375.999670027406, 0, 1], 0, 0, 1, [0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 279.25, 2375.999670027406, 0, 1], 0, 0, 1, 1, 1, 1, 1, "Polyline", 10, 2, 0, 0, 0, 2, 71, [0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 279.25, 2375.999670027406, 0, 1], 0, 0, 1, [-1, 1.8369701987210297e-16, 0, 0, -1.8369701987210297e-16, -1, 0, 0, 0, 0, 1, 0, 124.27375296912115, 2791.4718058299673, 0, 1], 0, 0, 1, 2, 4, [0, 8.000000000000028], 0, [0, -1.9999999999999716], 0, [5, -1.9999999999999716], 0, [5, 8.000000000000028], 0, true, 0], "basePt": { "x": 0, "y": 0, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let [reg1, reg2] = LoadRegionsFromFileData(d);
reg1.BooleanOper(reg2, BoolOpeartionType.Subtract);
expect(reg1.Area).toMatchSnapshot();
});