import { CADFiler } from '../../src/DatabaseServices/CADFiler'; import { Polyline } from '../../src/DatabaseServices/Entity/Polyline'; import { GetPointAtCurveDir } from '../../src/Common/CurveUtils'; import { Vector3, Vector2 } from 'three'; import { Factory } from '../../src/DatabaseServices/CADFactory'; Factory(Polyline); test('2个大圆中间', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 3, [108.37693694676932, 28.257776463252547], 0.4472440944881872, [108.37693694676932, 17.68555707305448], 3.5940684866260213, [111.70676982557188, 14.089337563947739], 0.5086040192926764, false]; f.Read(); let pl = f.ReadObject() as Polyline; let isR = GetPointAtCurveDir(pl, new Vector3(110.19, 17.4)); expect(isR).toBe(-1); let p = new Vector3().fromArray([84.89024786541306, 11.031154321671167, 0]); isR = GetPointAtCurveDir(pl, p); expect(isR).toBe(1); }); test('点在端点且端点平行', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 43.1743189069092, -3.552713678800501e-15, 0, 1], 2, 3, [35.26780526232293, 5.878508963172803], -0.8898689681740283, [35.26780526232293, 13.326990467988661], 0, [35.26780526232293, 23.770222268555234], 0, false]; f.Read(); let pl = f.ReadObject() as Polyline; let p = new Vector3(81.8, 12.06); let isR = GetPointAtCurveDir(pl, p); expect(isR).toBeTruthy(); }); test('点在和端点平行', () => { let pl = new Polyline(); pl.AddVertexAt(0, new Vector2(0, 0)); pl.AddVertexAt(1, new Vector2(0, 5)); pl.AddVertexAt(2, new Vector2(0, 10)); let p = new Vector3(5, 5, 0); let isR = GetPointAtCurveDir(pl, p); expect(isR).toBeTruthy(); }); test('点在端点上且点在圆心上', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [17.513342658829444, 9.06588623278316], 0, [19.513342658829444, 9.06588623278316], 0.9999999999999999, [19.513342658829444, 7.06588623278316], -0.9999999999999999, [19.513342658829444, 5.06588623278316], 0, [17.513342658829444, 5.06588623278316], 0, true]; f.Read(); let pl = f.ReadObject() as Polyline; let p = new Vector3(19.48, 8.1097); let isR = GetPointAtCurveDir(pl, p); expect(isR).toBe(-1); }); test('存在精度误差,并且点在圆内', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [0, 0], 0, [2, 0], 1, [2, 2], -1, [2, 4], 0, [0, 4], 0, true]; f.Read(); let pl = f.ReadObject() as Polyline; let p = new Vector3().fromArray([2, 3.8, 0]); for (let i = 0; i < 5; i++) { p.x -= 0.01; let isR = GetPointAtCurveDir(pl, p); expect(isR).toBeTruthy(); } pl.Reverse(); for (let i = 0; i < 10; i++) { p.x += 0.01; let isR = GetPointAtCurveDir(pl, p); expect(isR).toBe(-1); } }); test('大于1凸度的圆', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [0, 0], 0, [1, 0], 3.7050811739160006, [1, 1.7149500468022372], 0, [0, 1.7149500468022374], 0, true]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([1.5998555184265881, 0.9127879590514852, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); }); test('盲区计算', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 3, [0, 0], 0, [1, 0], 0.6998085535161632, [1, -1], -1.9959956751332304, false]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([1.3789363811285338, -0.34949587695820905, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); pl.Reverse(); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); }); test('参数点在终点上', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 9, [26.388805509867886, 5.284389892538414], 0, [28.388805509867886, 5.284389892538414], 0.9999999999999999, [28.388805509867886, 7.284389892538414], -0.9999999999999999, [28.388805509867886, 9.284389892538414], 0, [24.129449189553043, 9.284389892538414], 0, [24.129449189553043, 13.772242014802323], 0, [33.10581078647962, 13.772242014802321], 0, [33.10581078647962, 0.368763303745288], 0, [27.762738407356657, 0.36876330374528865], 0, true]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([24.40481807693597, 4.679455426066854, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); pt = new Vector3().fromArray([30.314368267468268, 10.71117601112483, 0]); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); pl.Reverse(); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); pt = new Vector3().fromArray([24.40481807693597, 4.679455426066854, 0]); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); }); test('点在小角内', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -47.5997122622927, 10.897558314909338, 0, 1], 2, 4, [-0.906131771640112, 6.969061295372345], 3.7897716494829594, [4.660056657223795, 6.487252124645892], 0, [20.106696883852685, 18.393201133144473], 0, [9.169563739376775, 22.583048158640217], 0, false]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([-45.25245903106504, 20.057300217471017, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); pl.Reverse(); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); }); test('首尾点相等', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [0, 0], 0, [5, 0], 0.9999999999999999, [5, 5], -0.9999999999999999, [5, 10], 0, [0, 10], 0, [0, 0], 0, false]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([-0.4662687082606203, -0.5388413229688394, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); pl.Reverse(); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); }); test('点在圆弧的弦中心上', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [0, 0], 0, [5, 0], 0.9999999999999999, [5, 5], -0.9999999999999999, [5, 10], 0, [0, 10], 0, [0, 0], 0, false]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([4.999999999999999, 2.5, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); pt = new Vector3().fromArray([5, 9.5, 0]); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); pt = new Vector3().fromArray([5, 5.5, 0]); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); pt = new Vector3().fromArray([6, 10, 0]); isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeTruthy(); }); test('圆弧过大导致直线小角错误', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.028011204481791063, 0.028011204481792618, 0, 1], 2, 4, [-2241.358078364921, -214.80916327845875], -1.1401903887488165, [-2190.503423306555, -220.10318099746846], -1.1044015866963386, [-2231.667025600985, -212.01859443849355], 0, [-2241.358078364921, -214.80916327845875], 0, false]; f.Read(); let pl = f.ReadObject() as Polyline; let pt = new Vector3().fromArray([-2246.7733894227954, -220.1844621837422, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); pt = new Vector3().fromArray([-2184.668414731696, -221.35723534211996, 0]); //[1,["Circle",1,1,4,false,7,-1,[1,0,0,0,0,1,0,0,0,0,1,0,-2184,-221.357,0,1],1,1]] isR = GetPointAtCurveDir(pl, pt); expect(isR).toBe(-1); });