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

123 lines
2.6 KiB

import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { Vector2 } from "three";
//构造测试的多段线
function createTestPolyline(): Polyline
{
return new Polyline([
{
pt: new Vector2(0, 0),
bul: 0
},
{
pt: new Vector2(5, 0),
bul: 1
},
{
pt: new Vector2(5, 5),
bul: -1
},
{
pt: new Vector2(5, 10),
bul: 0
},
{
pt: new Vector2(0, 10),
bul: 0
},
{
pt: new Vector2(0, 0),
bul: 0
}
]);
}
//切割测试
{
let pl = createTestPolyline();
test('多切刀', () =>
{
//不闭合标志
pl.CloseMark = false;
//不包括0
let cus = pl.GetSplitCurves([1.5, 2.5, 2.8, 2.8, 1.2, 2, 1.8, 1, 2.2]);//
for (let cu of cus)
{
expect(cu.LineData).toMatchSnapshot();
}
//包括0
let cus2 = pl.GetSplitCurves([1.5, 2.5, 2.8, 2.8, 1.2, 2, 1.8, 1, 2.2, 0]);//
for (let cu of cus)
{
expect(cu.LineData).toMatchSnapshot();
}
});
test('多切刀闭合', () =>
{
//闭合标志
pl.CloseMark = true;
//不包括0
let cus = pl.GetSplitCurves([1.5, 2.5, 2.8, 2.8, 1.2, 2, 1.8, 1, 2.2]);//
for (let cu of cus)
{
expect(cu.LineData).toMatchSnapshot();
}
//包括0
let cus2 = pl.GetSplitCurves([1.5, 2.5, 2.8, 2.8, 1.2, 2, 1.8, 1, 2.2, 0]);//
for (let cu of cus)
{
expect(cu.LineData).toMatchSnapshot();
}
});
/*
test('单刀', () =>
{
for (let p of [0, 1.5, 2, 2.5, 3])
{
let cus = pl.GetSplitCurves(p);
for (let cu of cus)
{
//该测试用于数值精度的问题经常造成测试失败.请刷新测试.
expect(cu.LineData).toMatchSnapshot();
}
}
});
*/
test('单刀闭合', () =>
{
pl.CloseMark = true;
for (let p of [0, 1.5, 2, 2.5, 3])
{
let cus = pl.GetSplitCurves(p);
for (let cu of cus)
{
expect(cu.LineData).toMatchSnapshot();
}
}
});
}
test('切割点在尾部', () =>
{
let pl = new Polyline();
5 years ago
pl.Rectangle(100, 100);
let cus = pl.GetSplitCurves([1, 4]);
expect(cus.length).toBe(2);
cus = pl.GetSplitCurves([2, 3]);
expect(cus.length).toBe(2);
});