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/bool5.test.ts

101 lines
13 KiB

import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils";
import "../../__test__/Utils/jest.util";
import { LoadRegionsFromFileData } from "../Utils/LoadEntity.util";
test('差集共线(圆)', () =>
{
let d =
{ "file": [2, "Region", 7, 2, 103, false, 1, 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], 1, 1, 1, 1, "Polyline", 7, 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], 2, 6, [807.6555023923443, 146.3157894736844], 0, [1710.7559808612436, 146.3157894736844], 0, [1710.7559808612436, 706.1818181818184], 0, [1459.7725447442663, 706.1818181818184], -0.9999999999999999, [1058.6389385093214, 706.1818181818184], 0, [807.6555023923443, 706.1818181818184], 0, true, 0, "Region", 7, 2, 105, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1259.205741626794, 706.1818181818184, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1259.205741626794, 706.1818181818184, 0, 1], 1, 1, 1, 1, "Circle", 7, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1259.205741626794, 706.1818181818184, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 200.56680311747243, 0], "basePt": { "x": 807.6555023923443, "y": 146.3157894736844, "z": 0 } };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].Area).toMatchNumberSnapshot();
});
test('差集问题', () =>
{
let d = { "file": [2, "Region", 7, 2, 179, false, 1, 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], 1, 1, 1, 1, "Polyline", 7, 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], 2, 4, [0, 0], 0, [600, 0], 0, [600, 1200], 0, [0, 1200], 0, true, 2, "Polyline", 7, 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], 2, 4, [166.89661244019044, 262.16359808612503], 0, [361.0113684210519, 262.16359808612503], 0, [361.0113684210519, 475.46411483253655], 0, [166.89661244019044, 475.46411483253655], 0, true, "Polyline", 7, 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], 2, 4, [224.89278468899556, 700.9699521531093], 0, [516.496842105263, 700.9699521531093], 0, [516.496842105263, 756.458181818181], 0, [224.89278468899556, 756.458181818181], 0, true, "Region", 7, 2, 206, false, 1, 3, 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], 1, 1, 1, 1, "Polyline", 7, 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], 2, 4, [134.10526315789502, 423.99555980861203], 0, [419.38373205741664, 423.99555980861203], 0, [419.38373205741664, 903.3818181818185], 0, [134.10526315789502, 903.3818181818185], 0, true, 0], "basePt": { "x": 0, "y": 0, "z": 0 } };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].ShapeManager.ShapeList.length).toBe(1);
expect(regs[0].Explode().length).toBe(16);
expect(regs[0].Area).toMatchNumberSnapshot();
});
test("弧形板差集", () =>
{
let d = { "file": [2, "Region", 8, 2, 239, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -7164.031205116695, -312.3853909685172, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -7164.031205116695, -312.3853909685172, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -7164.031205116695, -312.3853909685172, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -7164.031205116695, -312.3853909685172, 0, 1], 0, 2, 4, [1488.2724956409866, -403.9906338621595], 0, [1556.769411177408, -276.18933276551024], 0.25108720252037403, [-1817.9873510282487, -276.1893327618018], 0, [-1749.4904354922473, -403.99063385883346], -0.25108720252039435, true, 0, "Region", 8, 2, 238, false, 1, 7, 0, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6729.018004950986, -356.8947148198645, 0, 1], 0, 0, true, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6729.018004950986, -356.8947148198645, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 4, 0, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6729.018004950986, -356.8947148198645, 0, 1], 0, 0, true, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6729.018004950986, -356.8947148198645, 0, 1], 0, 2, 4, [0, 0], 0, [145.0094999623654, 0], 0, [145.0094999623654, 18], 0, [0, 18], 0, true, 0], "basePt": { "x": -8982.018556144943, "y": -716.3760248306767, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].ShapeManager.ShapeList.length).toBe(2);
for (let s of regs[0].ShapeManager.ShapeList)
expect(s.Area).toMatchNumberSnapshot();
});
test("弧形板差集2", () =>
{
let d = { "file": [2, "Region", 8, 2, 237, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -6781.659977097809, -1502.9438267095907, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -6781.659977097809, -1502.9438267095907, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -6781.659977097809, -1502.9438267095907, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -6781.659977097809, -1502.9438267095907, 0, 1], 0, 2, 4, [1488.2724956409866, -403.9906338621595], 0, [1556.769411177408, -276.18933276551024], 0.25108720252037403, [-1817.9873510282487, -276.1893327618018], 0, [-1749.4904354922473, -403.99063385883346], -0.25108720252039435, true, 0, "Region", 8, 2, 236, false, 1, 7, 0, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6346.646776932101, -1547.453150560938, 0, 1], 0, 0, true, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6346.646776932101, -1547.453150560938, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 4, 0, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6346.646776932101, -1547.453150560938, 0, 1], 0, 0, true, [0.16234909674127015, 0.9867333838414984, 0, 0, -0.9867333838414984, 0.16234909674127015, 0, 0, 0, 0, 1, 0, -6346.646776932101, -1547.453150560938, 0, 1], 0, 2, 4, [0, 0], 0, [144.9994999623654, 0], 0, [144.9994999623654, 18], 0, [0, 18], 0, true, 0], "basePt": { "x": -8599.647328126059, "y": -1906.9344605717502, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].ShapeManager.ShapeList.length).toBe(2);
for (let s of regs[0].ShapeManager.ShapeList)
expect(s.Area).toMatchNumberSnapshot();
});
test("差集错误", () =>
{
let d = { "file": [2, "Region", 8, 2, 104, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 3556.345601907233, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 3556.345601907233, 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, 2485.841337666032, 3556.345601907233, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 1254.3456019072328, 0, 1], 0, 2, 6, [482, -2302], 0, [481.9999999999991, -1476], 0, [564, -1476.0000000000002], 0, [564, 0], 0, [0, 0], 0, [0, -2302], 0, true, 0, "Region", 8, 2, 105, false, 1, 7, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 0, true, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 3, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 0, true, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 2, 4, [0, 0], 0, [808, 0], 0, [808, 18], 0, [0, 18], 0, true, 0], "basePt": { "x": 2485.841337666032, "y": 1254.3456019072328, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].ShapeManager.ShapeList.length).toBe(1);
for (let s of regs[0].ShapeManager.ShapeList)
expect(s.Area).toMatchNumberSnapshot();
});
//由于切割的点在参数周围,导致分裂的时候,点出现了偏差(导致原先的算法 点在曲线内部了)
test("分裂的点在参数周围", () =>
{
let d = { "file": [2, "Region", 8, 2, 124, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2997.919883164752, -777.954629938351, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2997.919883164752, -777.954629938351, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2997.919883164752, -777.954629938351, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2997.919883164752, -777.954629938351, 0, 1], 0, 2, 4, [-965, -11], 0, [2603, -11], 0, [2603, 7], 0, [-965, 7], 0, true, 0, "Region", 8, 2, 125, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2994.919883164752, -770.954597934382, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2994.919883164752, -770.954597934382, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2994.919883164752, -770.954597934382, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2994.919883164752, -777.954629938351, 0, 1], 0, 2, 8, [829, -7.000032003968954], 0, [829, 2131], 0, [3, 2131], 0, [3, 2124.0000000000005], 0, [3, 2124.0000000000005], 0, [3, 0], 0, [3, 0], 0, [3, -7.000032003968954], 0, true, 0], "basePt": { "x": 2032.9198831647518, "y": -788.954629938351, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Intersection);
expect(regs[0].ShapeManager.ShapeList.length).toBe(1);
for (let s of regs[0].ShapeManager.ShapeList)
expect(s.Area).toMatchNumberSnapshot();
});
test('交点被优化成单个点,导致点在曲线外,导致求交错误', () =>
{
let d =
{ "file": [2, "Region", 8, 2, 6655, false, 1, 1, 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, 1, 1, 1, 1, "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, [0, 0], 0, [70, 0], 0, [70, 18], 0, [0, 18], 0, true, 0, "Region", 8, 2, 6656, false, 1, 2, 0, [0.7071067811865476, -0.7071067811865475, 0, 0, -0.7071067811865475, -0.7071067811865476, 0, 0, 0, 0, -1, 0, 183.22473504170694, 554.4594094334525, 0, 1], 0, 0, true, [0.7071067811865476, -0.7071067811865475, 0, 0, -0.7071067811865475, -0.7071067811865476, 0, 0, 0, 0, -1, 0, 183.22473504170694, 554.4594094334525, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [0.7071067811865476, -0.7071067811865475, 0, 0, -0.7071067811865475, -0.7071067811865476, 0, 0, 0, 0, -1, 0, 183.22473504170694, 554.4594094334525, 0, 1], 0, 0, true, [0.7071067811865476, -0.7071067811865475, 0, 0, -0.7071067811865475, -0.7071067811865476, 0, 0, 0, 0, -1, 0, 183.22473504170694, 554.4594094334525, 0, 1], 0, 2, 4, [0, 0], 0, [312, 0], 0, [312, 1313], 0, [0, 1313], 0, true, 0], "basePt": { "x": -745.2064686562298, "y": -594.5891099946873, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Intersection);
expect(regs[0].ShapeManager.ShapeList.length).toBe(1);
for (let s of regs[0].ShapeManager.ShapeList)
expect(s.Area).toMatchNumberSnapshot();
});
test('交点被优化成单个点,导致点在曲线内,导致求交错误', () =>
{
let d =
{ "file": [2, "Region", 8, 2, 102, false, 1, 1, 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, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -187, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -187, 0, 0, 1], 0, 2, 4, [314, 0], 0, [314, 536], 0, [187, 536], 0, [187, 0], 0, true, 0, "Region", 8, 2, 103, false, 1, 2, 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, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 535.9999999999998, 0, 1], 0, 0, true, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 535.9999999999998, 0, 1], 0, 2, 4, [0, 0], 0, [127.00000000000023, 0], 0, [127.00000000000023, 18], 0, [0, 18], 0, true, 0], "basePt": { "x": -18, "y": 0, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let regs = LoadRegionsFromFileData(d);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].ShapeManager.ShapeList.length).toBe(1);
for (let s of regs[0].ShapeManager.ShapeList)
expect(s.Area).toMatchNumberSnapshot();
});