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

71 lines
6.0 KiB

import { curveLinkGroup } from "../../src/Common/CurveUtils";
import { Curve } from "../../src/DatabaseServices/Entity/Curve";
import { Line } from "../../src/DatabaseServices/Entity/Line";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { equaln } from "../../src/Geometry/GeUtils";
import "../Utils/jest.util";
import { LoadEntityFromFileData } from "../Utils/LoadEntity.util";
test('多段线与多段线Join', () =>
{
let data =
[2, "Polyline", 2, 1, 102, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 2, 4, [69.1964285714286, -106.02678571428574], 0, [-60.26785714285711, 58.03571428571427], 0.4847381535042383, [-241.07142857142856, 58.03571428571427], -1.124793513518748, [-340.9598214285714, 157.9241071428571], 0, false, "Polyline", 2, 1, 103, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 2, 4, [69.1964285714286, -106.02678571428574], 0, [181.36160714285717, 6.138392857142875], -0.7890083669838478, [389.50892857142867, -121.65178571428574], 1.286428411698261, [556.9196428571429, -132.81250000000003], 0, false];
let pls = LoadEntityFromFileData(data) as Polyline[];
let pl1 = pls[0].Clone();
let pl2 = pls[1].Clone();
let length = pl1.Length + pl2.Length;
//sp sp
expect(pl1.Join(pl2)).toBe(1);
expect(equaln(pl1.Length, length)).toBeTruthy();
pl1 = pls[0].Clone();
pl2 = pls[1].Clone();
pl2.Reverse();
//sp ep
expect(pl1.Join(pl2)).toBe(1);
expect(equaln(pl1.Length, length)).toBeTruthy();
pl1 = pls[0].Clone();
pl2 = pls[1].Clone();
pl1.Reverse();
//ep sp
expect(pl1.Join(pl2)).toBe(1);
expect(equaln(pl1.Length, length)).toBeTruthy();
pl1 = pls[0].Clone();
pl2 = pls[1].Clone();
pl1.Reverse();
pl2.Reverse();
//ep ep
expect(pl1.Join(pl2)).toBe(1);
expect(equaln(pl1.Length, length)).toBeTruthy();
});
test('一定精度容差内的直线Join', () =>
{
let data =
[2, "Line", 2, 1, 168, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -97.39422719143477, 40.30682517259278, 0, 1], 1, 1, [140.3943227792479, -100, 0], [314.3387826639938, -99.99999883531063, 0], "Line", 2, 1, 169, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -97.39422719143477, 40.30682517259278, 0, 1], 1, 1, [314.3387826639938, -99.99999883531063, 0], [318, -100, 0]];
let lines = LoadEntityFromFileData(data) as Line[];
expect(lines[0].Join(lines[1])).toBe(1);
});
test('镜像的圆弧join错误', () =>
{
let data =
{ "file": [5, "Arc", 10, 2, 381, 0, 1, 1, 0, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 31.950000002904744, 1814.9522549174983, -2.720676492299624e-13, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 31.950000002904744, 1814.9522549174983, -2.720676492299624e-13, 1], 0, 0, 1, 2, 3.0000000038214694, 1.570796326476423, 4.712388981340115, 1, "Line", 10, 2, 382, 0, 1, 1, 0, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, 1, [2737.030476529, -1484.0672999999997, 2.524354896707238e-29], [2724.9304765290003, -1484.0672999999997, 2.524354896707238e-29], "Arc", 10, 2, 383, 0, 1, 1, 0, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 44.04999999771144, 1814.9522549213198, -2.7206764923066435e-13, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 44.04999999771144, 1814.9522549213198, -2.7206764923066435e-13, 1], 0, 0, 1, 2, 3, 4.71238897974774, 1.5707963274318462, 1, "Line", 10, 2, 384, 0, 1, 1, 0, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, 1, [2724.9304765290003, -1478.0672999999997, 2.524354896707238e-29], [2737.0304765270894, -1478.0672999923568, 2.524354896707238e-29], "Line", 10, 2, 385, 0, 1, 1, 0, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, -1.2246467991052327e-16, -1, 1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, [-0.9999999999656061, 1.2246467991473532e-16, 0, 0, 1.2246467991052327e-16, 1, -1.836970198657849e-16, 0, -2.2496396739154126e-32, 0.000008293838842227955, -0.9999999999656061, 0, 2768.980476434901, 333.88495492131983, 0, 1], 0, 0, 1, 1, [2737.0304765270894, -1478.0672999923568, 2.524354896707238e-29], [2737.0304765270894, -1478.0672999923568, 2.524354896707238e-29]], "basePt": { "x": 28.94999999908327, "y": 1811.9522549136768, "z": -0.00002488151683044617 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let lines = LoadEntityFromFileData(data) as Curve[];
let groups = curveLinkGroup(lines);
for (let g of groups)
{
let pl = Polyline.Combine(g, 1e-3);
expect(pl.Area2).toMatchNumberSnapshot();
expect(pl.Length).toMatchNumberSnapshot();
}
});