import { Circle } from '../../src/DatabaseServices/Circle'; import { Vector3, Vector2 } from 'three'; import { app } from '../../src/ApplicationServices/Application'; import { Command } from '../../src/Editor/CommandMachine'; import { PromptStatus } from '../../src/Editor/PromptResult'; import { RenderType } from '../../src/GraphicsSystem/Enum'; import { equal, equaln } from '../../src/Geometry/GeUtils'; test('圆参数', () => { let circle = new Circle(new Vector3(5, 0, 0), 5); circle.GetParamAtPoint(new Vector3(0, 0, 0))/*?*/ expect(equaln(circle.GetParamAtPoint(new Vector3(0, 0, 0))/*?*/, 0.5)).toBeTruthy(); expect(equaln(circle.GetParamAtPoint(new Vector3(5, 5, 0)), 0.25)).toBeTruthy(); expect(equaln(circle.GetParamAtPoint(new Vector3(10, 0, 0)), 0)).toBeTruthy(); expect(circle.GetParamAtPoint(new Vector3(-5, -5, 0))).toBe(NaN); expect(circle.GetParamAtPoint(new Vector3(10, 0, 0))).toBe(0); }); test('半径为0的圆,参数', () => { let circle = new Circle(new Vector3(), 0); expect(circle.GetParamAtPoint(new Vector3(0, 0, 0))).toBe(0); }); test("圆的切割1", () => { let circle = new Circle(new Vector3(5, 0, 0), 5); let cs = circle.GetSplitCurves(0.5); expect(cs.length).toBe(0); }); test("圆的切割2", () => { let circle = new Circle(new Vector3(5, 0, 0), 5); let cs = circle.GetSplitCurves([0.5, 0.75, 0.25]); for (let c of cs) { expect(c.StartPoint).toMatchSnapshot() expect(c.EndPoint).toMatchSnapshot() } }); test("由距离得到圆参数", () => { let circle = new Circle(new Vector3(5, 0, 0), 5); expect(equaln(circle.GetParamAtDist(0.5 * Math.PI * 5), 0.25)).toBeTruthy(); } ); test("由距离得到对应点", () => { let circle = new Circle(new Vector3(5, 0, 0), 5); expect(equal(circle.GetPointAtDistance(0.5 * Math.PI * 5), new Vector3(5, 5, 0))).toBeTruthy(); } ); test("由参数得到距离", () => { let circle = new Circle(new Vector3(5, 0, 0), 5); expect(equaln(circle.GetDistAtParam(0.5), Math.PI * 5)).toBeTruthy(); } ); test("由点得到距离", () => { let circle = new Circle(new Vector3(5, 0, 0), 5); expect(equaln(circle.GetDistAtPoint(new Vector3(5, 5, 0)), 0.5 * Math.PI * 5)).toBeTruthy(); expect(circle.GetDistAtPoint(new Vector3(10, 0, 0))).toBe(0); } ); test('圆偏移', () => { let circle = new Circle(new Vector3(5, 0, 0), 5); let arcs3 = circle.GetOffsetCurves(10); let arcs = circle.GetOffsetCurves(-3); arcs3[0].StartPoint //? arcs3[0].EndPoint //? arcs[0].StartPoint //? arcs[0].EndPoint //? // expect(arcs.length).toBe(1); // expect(arcs.length).toBe(Math.PI * 2); let newArc = arcs[0]; expect(newArc.StartPoint).toMatchSnapshot(); expect(newArc.EndPoint).toMatchSnapshot(); let circle2 = new Circle(new Vector3(10, 0, 0), 10); let circles2 = circle2.GetOffsetCurves(-5)[0]; //? circles2.StartPoint //? circles2.EndPoint //? expect(circles2.StartPoint).toMatchSnapshot(); expect(circles2.EndPoint).toMatchSnapshot(); circles2 = circle2.GetOffsetCurves(10)[0]; //? circles2.StartPoint //? circles2.EndPoint //? expect(circles2.StartPoint).toMatchSnapshot(); expect(circles2.EndPoint).toMatchSnapshot(); expect(circles2.StartPoint).toMatchSnapshot(); expect(circles2.EndPoint).toMatchSnapshot(); circles2 = circle2.GetOffsetCurves(-5)[0]; //? circles2.StartPoint //? circles2.EndPoint //? expect(circles2.StartPoint).toMatchSnapshot(); expect(circles2.EndPoint).toMatchSnapshot(); }); test('最近点', () => { let circle = new Circle(new Vector3(5, 0, 0), 5); expect(circle.GetClosestPointTo(new Vector3(-5, 0, 0), true)/*?*/).toMatchSnapshot();//0,0,0. expect(circle.GetClosestPointTo(new Vector3(8, 0, 0), true)/*?*/).toMatchSnapshot();//10,0,0. }); test('最近点2', () => { let circle = new Circle(new Vector3(5, 0, 0), 5); let pt = circle.GetClosestPointTo(new Vector3(5), true); expect(pt).toMatchSnapshot(); });