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__/CurveUtils/PolylineSpliteRect.test.ts

119 lines
7.9 KiB

import { PolylineSpliteRect } from "../../src/Common/CurveUtils";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { LoadCurvesFromFileData } from "../Utils/LoadEntity.util";
describe("封闭多段线分割矩形测试", () =>
{
test("轮廓1", () =>
{
let data =
{ "file": [1, "Polyline", 8, 2, 176, 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], 0, 2, 9, [8387.713348727397, 1084.5343505247351], 0, [7226.765061171589, 1084.5343505247351], 0, [7226.765061171589, 829.0146317325472], 0, [4632.684437781331, 829.0146317325472], 0, [4632.684437781331, 1078.9795740292527], 0, [5965.830796697095, 1078.9795740292527], 0, [5965.830796697095, 1301.1706338485465], 0, [8387.713348727397, 1301.1706338485465], 0, [8387.713348727397, 1084.5343505247351], 0, false], "basePt": { "x": 4632.684437781331, "y": 829.0146317325472, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(3);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test("轮廓2", () =>
{
let data =
{ "file": [1, "Polyline", 8, 2, 209, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5376.119285317616, -2438.550333164698, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 17, [0, 0], 0, [0, -2396.493624880947], 0, [774.4127870794337, -2396.493624880947], 0, [774.4127870794337, -805.8079000691391], 0, [1852.3116663926985, -805.8079000691391], 0, [1852.3116663926985, -1789.521440413283], 0, [2972.0706963589055, -1789.521440413283], 0, [2972.0706963589055, -1088.3639169765001], 0, [4029.0395003456997, -1088.3639169765001], 0, [4029.0395003456997, -2155.797758626529], 0, [4719.731986119246, -2155.797758626529], 0, [4719.731986119246, -1517.4304611691587], 0, [7095.295535673724, -1517.4304611691587], 0, [7095.295535673724, -690.6924857735476], 0, [4426.7109315486505, -690.6924857735476], 0, [4426.7109315486505, 0], 0, [0, 0], 0, false], "basePt": { "x": 5376.119285317616, "y": -4835.043958045645, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(7);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test("轮廓3", () =>
{
let data =
{ "file": [1, "Polyline", 8, 2, 204, 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], 0, 2, 13, [6757.27535177342, -889.6497705352106], 0, [8091.75010660756, -889.6497705352106], 0, [8091.75010660756, -490.4058330764652], 0, [6922.134064474898, -490.4058330764652], 0, [6922.134064474898, -259.85651707916213], 0, [5668.170711611516, -259.85651707916213], 0, [5668.170711611516, -479.1595249790362], 0, [4577.27882616086, -479.1595249790362], 0, [4577.27882616086, -889.6497705352106], 0, [5898.729096631669, -889.6497705352106], 0, [5898.729096631669, -658.1101316379868], 0, [6757.27535177342, -658.1101316379868], 0, [6757.27535177342, -889.6497705352106], 0, false], "basePt": { "x": 4577.27882616086, "y": -889.6497705352106, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(5);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test("轮廓4", () =>
{
let data = { "file": [1, "Polyline", 8, 2, 187, 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], 0, 2, 7, [-93.87293003759919, -1554.1191971829958], 0, [-93.87293003759919, -706.4182647686482], 0, [1667.016560471175, -706.4182647686482], 0, [1667.016560471175, -993.8361774756588], 0, [2743.9241827657966, -993.8361774756588], 0, [2743.9241827657966, -1554.1191971829958], 0, [-93.87293003759919, -1554.1191971829958], 0, false], "basePt": { "x": -93.87293003759919, "y": -1554.1191971829958, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(2);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test("轮廓5", () =>
{
let data = { "file": [1, "Polyline", 8, 2, 216, false, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2422.6764429900863, -452.7252899848789, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2422.6764429900863, -452.7252899848789, 0, 1], 0, 2, 6, [784.7209559691166, 681.8216720645796], 0, [193.7209559691164, 681.8216720645796], 0, [193.7209559691164, 663.8216720645796], 0, [1173, 663.8216720645796], 0, [1173, 672.8216720645801], 0, [784.7209559691164, 672.8216720645801], 0, true], "basePt": { "x": 2616.3973989592027, "y": 211.09638207970073, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(2);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test("轮廓6", () =>
{
let data = { "file": [1, "Polyline", 8, 2, 226, false, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1095.4517523011439, -5530.527123641856, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1095.4517523011439, -5530.527123641856, 0, 1], 0, 2, 8, [749.147341015374, 360.98889708156776], 0, [740.147341015374, 360.98889708156776], 0, [740.1473410153737, 582], 0, [731.147341015374, 582], 0, [731.1473410153742, 0], 0, [740.1473410153849, 0], 0, [740.1473410153849, 168.38705445030928], 0, [749.147341015374, 168.38705445030945], 0, true], "basePt": { "x": 1826.5990933165178, "y": -5530.527123641856, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(2);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test("轮廓7", () =>
{
let data = { "file": [1, "Polyline", 10, 2, 102, 0, 1, 7, 0, [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, 8, [163.99999999999997, 0], 0, [182, 0], 0, [181.99999999999997, 132], 0, [169.00000000000003, 132], 0, [169.00000000000003, 332], 0, [182, 332], 0, [182.00000000000009, 464], 0, [164, 464], 0, true], "basePt": { "x": 163.99999999999997, "y": 0, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[];
let cons = PolylineSpliteRect(pl[0]);
expect(cons.length).toBe(3);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
test('交点参数为负数?', () =>
{
let d =
{ "file": [1, "Polyline", 8, 2, 102, 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], 0, 2, 5, [753.4709588432369, 2025.012386886011], 0, [735.4710123919904, 2025.0123894054675], 0, [735.4710123919904, 863.0123868860028], 0, [753.4710123919904, 863.0123868860028], 0, [753.4710123919904, 863.0132159650564], 0, true], "basePt": { "x": 735.4710123919904, "y": 863.0123868860028, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(d)[0] as Polyline;
let cons = PolylineSpliteRect(pl);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
});