import * as THREE from 'three'; import { Vector3 } from 'three'; import { Arc } from '../../src/DatabaseServices/Arc'; import { Circle } from '../../src/DatabaseServices/Circle'; import { Curve } from '../../src/DatabaseServices/Curve'; import { Line } from '../../src/DatabaseServices/Line'; import { IntersectCircleAndCircle, IntersectLine3AndLine3, IntersectOption } from '../../src/GraphicsSystem/IntersectWith'; import { LoadCurvesFromFileData, LoadEntityFromFileData } from '../Utils/LoadEntity.util'; test('相交测试', () => { let p1 = new THREE.Vector3(0, 0, 0); let p2 = new THREE.Vector3(1, 0, 0); let p3 = new THREE.Vector3(0.5, 0.5, 0); let p4 = new THREE.Vector3(0.5, 1, 0); let p5 = new THREE.Vector3(3, 0, 0); let p6 = new THREE.Vector3(6, 0, 0); let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/ expect(res).toMatchSnapshot(); res = IntersectLine3AndLine3(p1, p2, p5, p6);/*?*/ expect(res).toMatchSnapshot(); let ins = IntersectLine3AndLine3( new THREE.Vector3(0, 5), new THREE.Vector3(5, 5), new THREE.Vector3(0.5, 1), new THREE.Vector3(0.5, 8)); expect(ins).toMatchSnapshot(); }) test('三维空间直线相交测试', () => { let p1 = new THREE.Vector3(); let p2 = new THREE.Vector3(10, 10, 10); let p3 = new THREE.Vector3(5, 5, 5); let p4 = new THREE.Vector3(5, 10, 5); let p5 = new THREE.Vector3(3, 3, 3); let p6 = new THREE.Vector3(6, 6, 6); let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/ expect(res).toMatchSnapshot(); res = IntersectLine3AndLine3(p1, p2, p5, p6);/*?*/ expect(res).toMatchSnapshot(); res = IntersectLine3AndLine3(p2, p6, p3, p4);/*?*/ expect(res).toMatchSnapshot(); res = IntersectLine3AndLine3( new Vector3(1, 1, 1), new Vector3(1, 1, 4), new Vector3(2, 2, 2), new Vector3(2, 2, 10) ) expect(res).toBeUndefined(); res = IntersectLine3AndLine3( new Vector3(1, 0, 1), new Vector3(1, 0, 4), new Vector3(0.5, 0, 3), new Vector3(0.5, 0, 10) ) expect(res).toBeUndefined(); }) test('三维空间圆圆相交测试', () => { let data = [2, "Circle", 1, 1, 0, false, 7, 0, [-0.1485675258840154, -0.98346692600856, 0.10353982663678746, 0, 0.8068528994682419, -0.18108783903750572, -0.5623127183093208, 0, 0.5717657639911589, 0, 0.8204169129946106, 0, 5.585923427922135, -0.5874251796993211, -0.834443475807827, 1], 1, 2.1223349919617873, "Circle", 1, 1, 0, false, 7, 0, [-0.1485675258840154, -0.98346692600856, 0.10353982663678746, 0, 0.8068528994682419, -0.18108783903750572, -0.5623127183093208, 0, 0.5717657639911589, 0, 0.8204169129946106, 0, 3.2540542870196947, -1.8996318241962369, 0.7906850652516981, 1], 1, 1.5840127550993974] testCirAndCirIntersect(data); data = [2, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 5, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2.5, 0, 0, 1], 1, 5] testCirAndCirIntersect(data); data = [2, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1], 1, 5, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 2.5, 0, 0, 1], 1, 5] testCirAndCirIntersect(data); data = [2, "Arc", 1, 1, 0, false, 7, 0, [0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, -7.223901135674274, -7.066640793063616, 1], 2, 4.787455889013074, 2.4468553886273967, 0.7203768859081977, true, "Arc", 1, 1, 0, false, 7, 0, [0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, -12.887397630639091, -5.59172322768673, 1], 2, 4.265691675276281, 3.020045238916937, 0.9631807673370143, true] testCirAndCirIntersect(data); data = [2, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2.5, 0, 0, 1], 1, 5, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 2.5, 0, 0, 1], 1, 5] testCirAndCirIntersect(data); }) test('三维空间直线和圆相交测试', () => { let data = [2, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 2.5, 0, 0, 1], 1, 5, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, [2.4219301113484804, 0, 6.278428496635537], [9.19486541121855, 0, -0.38347507700715716]] testLineAndCirIntersect(data); data = [2, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 5, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, [-3.6226270297054635, 5.273119429622456, 0], [-3.6226270297054652, -5.297100907223948, 0]] testLineAndCirIntersect(data); data = [2, "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 13.418897659897576, -9.71681408534522, 4.841809080303142, 1], 1, 5, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, [9.796270630192113, -4.443694655722764, 4.841809080303142], [9.796270630192112, -15.013914992569168, 4.841809080303142]] testLineAndCirIntersect(data); data = [2, "Circle", 1, 1, 0, false, 7, 0, [0.8517840265050032, 0, -0.5238930923298417, 0, 0, 1, 0, 0, 0.5238930923298417, 0, 0.8517840265050032, 0, 15.469956975945145, -9.71681408534522, 4.4481472148971575, 1], 1, 5, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, [12.384261138056765, -4.443694655722764, 6.346016491847221], [12.384261138056765, -15.013914992569168, 6.346016491847222]] testLineAndCirIntersect(data); }) test('补充相交测试', () => { let data = [2, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1.3934337707580937, 0.039495588796686576, 0, 1], 1, [12.270990240675426, 8.520323796959827, 0], [12.270990240675426, 4.4951100391838885, 0], "Arc", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 13.662687223232803, 4.584664645783669, 0, 1], 2, 0.003163048700428762, 6.156784789283385, 3.3367334474492862, true] let cus = LoadEntityFromFileData(data); let [cu1, cu2] = cus[0] instanceof Line ? cus : cus.reverse(); let pts = cu1.IntersectWith(cu2, 0); expect(pts.length).toBe(1); data = [2, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1.3934337707580937, 0.039495588796686576, 0, 1], 1, [12.270990240675426, 8.520323796959827, 0], [12.270990240675426, 4.4951100391838885, 0], "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 13.662687223232803, 4.584664645783669, 0, 1], 1, 0.0031630487004287015] cus = LoadEntityFromFileData(data); [cu1, cu2] = cus[0] instanceof Line ? cus : cus.reverse(); pts = cu1.IntersectWith(cu2, 0); expect(pts.length).toBe(2); }) function testCirAndCirIntersect(data) { let cus = LoadCurvesFromFileData(data) as Array; let pts = IntersectCircleAndCircle(cus[0], cus[1]); expect(pts).toMatchSnapshot(); } function testLineAndCirIntersect(data) { let cus = LoadCurvesFromFileData(data); let [cu1, cu2] = cus[0] instanceof Line ? cus : cus.reverse(); let pts = cu1.IntersectWith(cu2, IntersectOption.ExtendBoth); expect(pts).toMatchSnapshot(); } test('直线和圆 圆心和直线重合的时候', () => { let c = new Circle(new Vector3(0, 0, 0), 1); let l = new Line(new Vector3(), new Vector3()); let pts = c.IntersectWith(l, IntersectOption.ExtendBoth); expect(pts.length).toBe(0); }); test('直线和圆相切', () => { let data = [2, "Line", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0.33854166666666696, 0, 1], 1, [23700.893770110895, 6917.069643795053, 0], [34450.21257120082, 3606.4429407977773, 0], "Circle", 1, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 34567.94904695702, 3989.061644487676, 0, 1], 1, 400] let cus = LoadEntityFromFileData(data) as Array; let pts = cus[0].IntersectWith(cus[1], 0); expect(pts).toMatchSnapshot(); });