mirror of https://gitee.com/cf-fz/WebCAD.git
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.
112 lines
2.3 KiB
112 lines
2.3 KiB
7 years ago
|
import { Polyline } from "../../src/DatabaseServices/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();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|