import { Vector2, Vector3 } from 'three'; import { IsPointInPolyLine } from '../../src/DatabaseServices/PointInPolyline'; import { Polyline } from '../../src/DatabaseServices/Polyline'; import { CADFiler } from '../../src/DatabaseServices/CADFiler'; import { LoadCurvesFromFileData } from '../Utils/LoadEntity.util'; test('点在多段线内', () => { let pl = new Polyline([ { pt: new Vector2(0, 0), bul: 0 }, { pt: new Vector2(10, 0), bul: 0 }, { pt: new Vector2(10, 10), bul: 0 }, { pt: new Vector2(8, 10), bul: 0 }, { pt: new Vector2(8, 5), bul: 0 }, { pt: new Vector2(4, 5), bul: 0 }, { pt: new Vector2(4, 10), bul: 0 }, { pt: new Vector2(0, 10), bul: 0 }, ]); pl.CloseMark = true; let bIn = IsPointInPolyLine(pl, new Vector3(8, 3));//? expect(bIn).toBeTruthy(); }); describe("", () => { test('退化', () => { let pl = new Polyline( [ { pt: new Vector2(0, 0), bul: 0 }, { pt: new Vector2(10, 0), bul: 0 }, { pt: new Vector2(5, 5), bul: 0 }, ]) pl.CloseMark = true; expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy(); }); test('退化2', () => { //右边中间 < let pl = new Polyline( [ { pt: new Vector2(0, 0), bul: 0 }, { pt: new Vector2(10, 0), bul: 0 }, { pt: new Vector2(5, 5), bul: 0 }, { pt: new Vector2(10, 10), bul: 0 }, { pt: new Vector2(0, 10), bul: 0 }, ]) pl.CloseMark = true; expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy(); }); test('左边中间', () => { //左边中间 let pl = new Polyline([ { pt: new Vector2(0, 0), bul: 0 }, { pt: new Vector2(10, 0), bul: 0 }, { pt: new Vector2(10, 10), bul: 0 }, { pt: new Vector2(0, 10), bul: 0 }, { pt: new Vector2(0, 8), bul: 0 }, { pt: new Vector2(5, 5), bul: 0 }] ) pl.CloseMark = true; expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy(); }); test('点在曲线外精度问题', () => { let plData = [1, "Polyline", 1, 1, 0, false, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [-3, 3.6739403974420594e-16], 0.9999999999999999, [3, 3.6739403974420594e-16], 0, [3, 10], 0.9999999999999999, [-3, 10], 0, [-3, -3.6739403974420594e-16], 0, false] let pl = LoadCurvesFromFileData(plData)[0] as Polyline; let p = new Vector3(-3, -0.16000000000000014, 0); expect(pl.PtInCurve(p)).toBeFalsy(); }); test('精度过低导致的错误', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.7938671363300003, 0.39666461398798525, 0, 1], 2, 5, [12.414545456418505, 8.796498405316765], 0, [12.015990240675425, 8.743859037199755], 0, [12.23362472371057, 8.552710046188702], 0, [12.233990240675425, 8.552758322014249], 0, [12.414545456418505, 8.796498405316765], 0, false] let p = new Vector3().fromArray([13.027857377005425, 8.947146562082409, 0]); f.Read(); let pl = f.ReadObject() as Polyline; expect(pl.PtInCurve(p)).toBeFalsy(); }); test('圆弧起点切线与直线相切IKOTO', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2.1413261486708848, -0.2136470533821324, 0, 1], 2, 5, [376.7856405585377, -104.2720901386406], -0.9999999999999999, [378.6693614887703, -104.2720901386406], 0, [378.4693614887703, -104.2720901386406], 0.9999999999999999, [376.9856405585377, -104.2720901386406], 0, [376.7856405585377, -104.2720901386406], 0, false] let p = new Vector3().fromArray([380.6106876374412, -106.61364416876692, 0]); f.Read(); let pl = f.ReadObject() as Polyline; expect(pl.PtInCurve(p)).toBeFalsy(); }); test('直线和圆弧相切IKOTO', () => { let f = new CADFiler(); f.Data = [1, "Polyline", 1, 1, 0, false, 6, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [5135.438782795266, 1651.835443234731], -0.9999915853997117, [5470.58864251807, 1651.8382633987026], 0, [5370.588642280742, 1651.8413831024218], 0.9999560507337252, [5235.438782795266, 1651.835443234731], 0, [5135.438782795266, 1651.835443234731], 0, false] f.Read(); let pl = f.ReadObject() as Polyline; let p = new Vector3().fromArray([5370.588642541802, -904.7955785523422, 0]); expect(pl.PtInCurve(p)).toBeFalsy(); }); 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, [5.113122171945702, 3.235294117647059], 2.037852023242286, [6.69683257918552, 0.7918552036199095], 0, [5.113122171945702, 3.235294117647059], 0, false] let p = new Vector3().fromArray([5.113122171945701, 0.7239819004524888, 0]); f.Read(); let pl = f.ReadObject() as Polyline; expect(pl.PtInCurve(p)).toBeTruthy(); }); })