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.
60 lines
1.7 KiB
60 lines
1.7 KiB
7 years ago
|
import { Line } from "../../src/DatabaseServices/Line";
|
||
|
import { Vector3 } from "three";
|
||
|
|
||
|
|
||
|
test('直线参数', () =>
|
||
|
{
|
||
|
|
||
|
let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 5, 0));
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(0, 0, 0))).toBe(0);
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(5, 5, 0))).toBe(1);
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(-5, -5, 0))).toBe(-1);
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(10, 10, 0))).toBe(2);
|
||
|
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(11, 10, 0))).toBe(NaN);
|
||
|
});
|
||
|
|
||
|
|
||
|
test('0长度直线,参数', () =>
|
||
|
{
|
||
|
|
||
|
let l = new Line(new Vector3(), new Vector3());
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(0, 0, 0))).toBe(0);
|
||
|
|
||
|
expect(l.GetParamAtPoint(new Vector3(1, 0, 0))).toBe(NaN);
|
||
|
});
|
||
|
|
||
|
test("直线的切割1", () =>
|
||
|
{
|
||
|
let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0));
|
||
|
expect(l.GetSplitCurves(0.5)[0].EndPoint).toMatchObject({ 'x': 2.5, 'y': 0, 'z': 0 });
|
||
|
expect(l.GetSplitCurves(0.5)[1].EndPoint).toMatchObject({ 'x': 5, 'y': 0, 'z': 0 });
|
||
|
|
||
|
});
|
||
|
test("直线的切割2", () =>
|
||
|
{
|
||
|
let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0));
|
||
|
expect(l.GetSplitCurves([0.5, 0.2, 0.8])[0].EndPoint).toMatchObject({ 'x': 1, 'y': 0, 'z': 0 });
|
||
|
expect(l.GetSplitCurves([0.2, 0.5, 0.8])[1].StartPoint).toMatchObject({ 'x': 1, 'y': 0, 'z': 0 });
|
||
|
expect(l.GetSplitCurves([0.2, 0.5, 0.8]).length).toBe(4);
|
||
|
});
|
||
|
test("直线延伸-反向", () =>
|
||
|
{
|
||
|
let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0));
|
||
|
l.Extend(-1);
|
||
|
expect(l.StartPoint).toMatchObject({ 'x': -5, 'y': 0, 'z': 0 });
|
||
|
|
||
|
});
|
||
|
test("直线延伸-正向", () =>
|
||
|
{
|
||
|
let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0));
|
||
|
l.Extend(2);
|
||
|
expect(l.EndPoint).toMatchObject({ 'x': 10, 'y': 0, 'z': 0 });
|
||
|
});
|