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 }); }); test("由距离得到直线参数", () => { let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); expect(l.GetParamAtDist(10)).toBe(2); } ); test("由距离得到对应点", () => { let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); expect(l.GetPointAtDistance(-10)).toMatchObject({ "x": -10, 'y': 0, 'z': 0 }); } ); test("由参数得到距离", () => { let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); expect(l.GetDistAtParam(-2)).toBe(-10); } ); test("由点得到距离", () => { let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); expect(l.GetDistAtPoint(new Vector3(-10, 0, 0))).toBe(-10); expect(l.GetDistAtPoint(new Vector3(10, 0, 0))).toBe(10); } ); test('直线偏移', () => { let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); let lines = l.GetOffsetCurves(-10); expect(lines.length).toBe(1); let newLine = lines[0]; expect(newLine.StartPoint).toMatchSnapshot(); expect(newLine.EndPoint).toMatchSnapshot(); let l2 = new Line(new Vector3(0, 0, 0), new Vector3(5, 5, 0)); let lines2 = l2.GetOffsetCurves(-10)[0]; //? lines2.StartPoint //? lines2.EndPoint //? expect(lines2.StartPoint).toMatchSnapshot(); expect(lines2.EndPoint).toMatchSnapshot(); lines2 = l2.GetOffsetCurves(10)[0]; //? lines2.StartPoint //? lines2.EndPoint //? expect(lines2.StartPoint).toMatchSnapshot(); expect(lines2.EndPoint).toMatchSnapshot(); l2.EndPoint = l2.EndPoint.negate(); lines2 = l2.GetOffsetCurves(10)[0]; //? lines2.StartPoint //? lines2.EndPoint //? expect(lines2.StartPoint).toMatchSnapshot(); expect(lines2.EndPoint).toMatchSnapshot(); lines2 = l2.GetOffsetCurves(-10)[0]; //? lines2.StartPoint //? lines2.EndPoint //? expect(lines2.StartPoint).toMatchSnapshot(); expect(lines2.EndPoint).toMatchSnapshot(); }); test('最近点', () => { let l = new Line(new Vector3(0, 0, 0), new Vector3(5, 5, 0)); expect(l.GetClosestPointTo(new Vector3(-5, 0, 0), true)/*?*/).toMatchSnapshot();//-5,0,0. expect(l.GetClosestPointTo(new Vector3(-5, 0, 0), false)/*?*/).toMatchSnapshot();//0,0,0. }); test('拉伸直线的夹点', () => { let line = new Line(new Vector3(0, 0, 0), new Vector3(10, 0, 0)); //测试拉伸一个参数 line.MoveStretchPoints([0], new Vector3(0, 5, 0)); expect(line.StartPoint.toArray()).toMatchObject([0, 5, 0]); //测试同时拉伸2个点的情况下 line.MoveStretchPoints([0, 1], new Vector3(0, 5, 0)); expect(line.StartPoint /*?*/).toMatchSnapshot(); expect(line.EndPoint /*?*/).toMatchSnapshot(); line.MoveStretchPoints([1], new Vector3(5, 0, 0)); expect(line.StartPoint).toMatchSnapshot(); expect(line.EndPoint).toMatchSnapshot(); });