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__/Polyline/rectOffset.test.ts

106 lines
5.7 KiB

import { IsRect } from "../../src/Common/CurveUtils";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { RectOffset } from "../../src/GraphicsSystem/ToolPath/OptimizeToolPath";
import { LoadEntityFromFileData } from "../Utils/LoadEntity.util";
describe("矩形偏移", () =>
{
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, -1327.419794987397, 40.97675544794174, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1875.419794987397, -2248.0232597250492, 0, 1], 0, 2, 5, [0, 0], 0, [25, 0], 0, [25, 9.99998482700903], 0, [0, 9.99998482700903], 0, [0, 0], 0, false], "basePt": { "x": -1327.419794987397, "y": 40.97675544794174, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
let rectInfo = IsRect(pl);
let maxDist = Math.min(rectInfo.size.x, rectInfo.size.y) / 2;
for (let d of [maxDist / 2, -maxDist / 2, maxDist])
{
let l = RectOffset(pl, rectInfo, d);
if (l)
{
expect(l.Length).toMatchSnapshot();
expect(l.OCS.toArray()).toMatchSnapshot();
}
else
expect(l).toBeUndefined();
}
});
test("旋转矩形", () =>
{
let d = { "file": [1, "Polyline", 8, 2, 106, false, 1, 7, 0, [0.7789093282833541, 0.6271365547575537, 0, 0, -0.6271365547575537, 0.7789093282833541, 0, 0, 0, 0, 1, 0, -1281.8810060380358, 34.63108438909671, 0, 1], 0, 0, true, [0.7789093282833541, 0.6271365547575537, 0, 0, -0.6271365547575537, 0.7789093282833541, 0, 0, 0, 0, 1, 0, -273.2077345817363, -2091.963211877024, 0, 1], 0, 2, 5, [0, 0], 0, [25, 0], 0, [25, 9.99998482700903], 0, [0, 9.99998482700903], 0, [0, 0], 0, false], "basePt": { "x": -1288.152362070074, "y": 34.63108438909671, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
let rectInfo = IsRect(pl);
let maxDist = Math.min(rectInfo.size.x, rectInfo.size.y) / 2;
for (let d of [maxDist / 2, -maxDist / 2, maxDist])
{
let l = RectOffset(pl, rectInfo, d);
if (l)
{
expect(l.Length).toMatchSnapshot();
expect(l.OCS.toArray()).toMatchSnapshot();
}
else
expect(l).toBeUndefined();
}
});
test("其他视图旋转矩形", () =>
{
let d =
{ "file": [1, "Polyline", 8, 2, 113, false, 1, 7, 0, [0.7789093282833541, 0, 0.6271365547575537, 0, -0.6271365547575537, 0, 0.7789093282833541, 0, 0, -1, 0, 0, -1062.1715399995587, 0, 0.21291538503150775, 1], 0, 0, true, [0.7789093282833541, 0, 0.6271365547575537, 0, -0.6271365547575537, 0, 0.7789093282833541, 0, 0, -1, 0, 0, -53.4982685432592, 0, -2126.381380881089, 1], 0, 2, 5, [0, 0], 0, [25, 0], 0, [25, 9.99998482700903], 0, [0, 9.99998482700903], 0, [0, 0], 0, false], "basePt": { "x": -1068.442896031597, "y": 0, "z": 0.21291538503150775 }, "ucs": [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
let rectInfo = IsRect(pl);
let maxDist = Math.min(rectInfo.size.x, rectInfo.size.y) / 2;
for (let d of [maxDist / 2, -maxDist / 2, maxDist])
{
let l = RectOffset(pl, rectInfo, d);
if (l)
{
expect(l.Length).toMatchSnapshot();
expect(l.OCS.toArray()).toMatchSnapshot();
}
else
expect(l).toBeUndefined();
}
});
test('isrect', () =>
{
let d =
{ "file": [1, "Polyline", 10, 2, 114, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 667.9517737972537, 248.9700940733262, 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, 5, [0, 0], 0, [659.0489880991222, 659.0489880991224], 0, [430.39933916677364, 887.6986370314712], 0, [-228.64964893234873, 228.64964893234855], 0, [0, 0], 0, false], "basePt": { "x": 439.302124864905, "y": 248.9700940733262, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
let rectInfo = IsRect(pl);
expect(rectInfo).toMatchSnapshot();
expect(pl.LineData).toMatchSnapshot();
});
test('isrect_p0', () =>
{
let d =
{ "file": [1, "Polyline", 10, 2, 125, 0, 1, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 290.0558341667891, 565.5489034870092, 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, 7, [0, 0], 0, [92.43681019536899, 102.55762882989848], 0, [156.26222675883798, 173.37122968863787], 0, [48.82090131799208, 270.20979275045295], 0, [-217.48514710199936, -25.25385221187355], 0, [-110.04382166115346, -122.09241527368857], 0, [0, 0], 0, false], "basePt": { "x": 72.57068706478975, "y": 443.4564882133206, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
let rectInfo = IsRect(pl);
expect(rectInfo).toMatchSnapshot();
expect(pl.LineData).toMatchSnapshot();
});
test('不是矩形', () =>
{
let d =
[1, "Polyline", 10, 2, 0, 0, 0, 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, 4, [49.95586871614796, 0], 0, [49.96160816995791, 0], 0, [49.95586871614796, 2352.839413948619], 0, [49.95586871614796, 2352.0000499849994], 0, true];
let pl = LoadEntityFromFileData(d)[0] as Polyline;
let rectInfo = IsRect(pl);
expect(rectInfo).toBeUndefined();
});
});