import { Vector3 } from 'three'; import { Line } from './../../src/DatabaseServices/Line'; import { RegionParse } from './../../src/Geometry/RegionParse'; function expectReg(alg: RegionParse) { let data1 = alg.m_RegionsInternal.map(o => { let res = []; o.forEach(r => { res.push(r.to.postion.toArray()) }) return res; }); let data2 = alg.m_RegionsOutline.map(o => { let res = []; o.forEach(r => { res.push(r.to.postion.toArray()) }) return res; }); expect(data1).toMatchSnapshot(); expect(data2).toMatchSnapshot(); } test('两个相连的区域', () => { let culist = []; let l1 = new Line(new Vector3(0, 0, 0), new Vector3(5, 5, 0)); let l2 = new Line(new Vector3(0, 0, 0), new Vector3(3, 2, 0)); let l3 = new Line(new Vector3(5, 5, 0), new Vector3(5, 25, 0)); let l4 = new Line(new Vector3(5, 25, 0), new Vector3(0, 0, 0)); let l5 = new Line(new Vector3(3, 2, 0), new Vector3(4, 3, 0)); let l6 = new Line(new Vector3(4, 3, 0), new Vector3(20, 5, 0)); let l7 = new Line(new Vector3(20, 5, 0), new Vector3(3, 2, 0)); culist.push(l1, l2, l3, l4, l5, l6, l7); let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(2); expect(g.m_RegionsInternal.length).toBe(0); expectReg(g); }); test('区域内有分割-三角形', () => { let culist = []; let l1 = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); let l2 = new Line(new Vector3(5, 0, 0), new Vector3(0, 5, 0)); let l3 = new Line(new Vector3(0, 5, 0), new Vector3(0, 0, 0)); let l4 = new Line(new Vector3(0, 0, 0), new Vector3(0, -5, 0)); let l5 = new Line(new Vector3(5, 0, 0), new Vector3(0, -5, 0)); culist.push(l1, l2, l3, l4, l5); let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(1); expect(g.m_RegionsInternal.length).toBe(2); expectReg(g); }); test('区域有延长线', () => { let culist = []; let l1 = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); let l2 = new Line(new Vector3(5, 0, 0), new Vector3(0, 5, 0)); let l3 = new Line(new Vector3(0, 5, 0), new Vector3(0, 0, 0)); let l4 = new Line(new Vector3(0, 0, 0), new Vector3(0, -5, 0)); let l5 = new Line(new Vector3(5, 0, 0), new Vector3(0, -5, 0)); let l6 = new Line(new Vector3(5, 0, 0), new Vector3(7, 0, 0)); culist.push(l1, l2, l3, l4, l5, l6); let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(1); expect(g.m_RegionsInternal.length).toBe(2); expectReg(g); }); test('区域内多条线', () => { let culist = []; let l1 = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); let l2 = new Line(new Vector3(5, 0, 0), new Vector3(0, 5, 0)); let l3 = new Line(new Vector3(0, 4, 0), new Vector3(0, 0, 0)); let l4 = new Line(new Vector3(0, 0, 0), new Vector3(0, -5, 0)); let l5 = new Line(new Vector3(5, 0, 0), new Vector3(0, -5, 0)); let l6 = new Line(new Vector3(0, 4, 0), new Vector3(5, 0, 0)); let l7 = new Line(new Vector3(0, 4, 0), new Vector3(0, 5, 0)); culist.push(l1, l2, l3, l4, l5, l6, l7); let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(1); expect(g.m_RegionsInternal.length).toBe(3); expectReg(g); }); test('包含区域', () => { let culist = []; let l1 = new Line(new Vector3(0, 0, 0), new Vector3(5, 0, 0)); let l2 = new Line(new Vector3(5, 0, 0), new Vector3(5, 5, 0)); let l3 = new Line(new Vector3(5, 5, 0), new Vector3(0, 5, 0)); let l4 = new Line(new Vector3(0, 5, 0), new Vector3(0, 0, 0)); let l5 = new Line(new Vector3(1, 1, 0), new Vector3(2, 1, 0)); let l6 = new Line(new Vector3(2, 1, 0), new Vector3(2, 2, 0)); let l7 = new Line(new Vector3(2, 2, 0), new Vector3(1, 2, 0)); let l8 = new Line(new Vector3(1, 2, 0), new Vector3(1, 1, 0)); culist.push(l1, l2, l3, l4, l5, l6, l7, l8); let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(2); expect(g.m_RegionsInternal.length).toBe(0); expectReg(g); }); test('测试复杂形状', () => { let culist = [ new Line(new Vector3().fromArray([3.9668615984405444, -1.042884990253411, 0]), new Vector3().fromArray([2.553606237816763, -2.3391812865497075, 0])), new Line(new Vector3().fromArray([2.553606237816763, -2.3391812865497075, 0]), new Vector3().fromArray([4.912280701754386, -2.7777777777777777, 0])), new Line(new Vector3().fromArray([4.912280701754386, -2.7777777777777777, 0]), new Vector3().fromArray([3.011695906432749, -3.469785575048733, 0])), new Line(new Vector3().fromArray([3.011695906432749, -3.469785575048733, 0]), new Vector3().fromArray([1.306042884990254, -0.30214424951267027, 0])), new Line(new Vector3().fromArray([2.348927875243664, -1.042884990253411, 0]), new Vector3().fromArray([2.553606237816763, -2.3391812865497075, 0])), new Line(new Vector3().fromArray([2.553606237816763, -2.3391812865497075, 0]), new Vector3().fromArray([3.011695906432749, -3.469785575048733, 0])), new Line(new Vector3().fromArray([3.011695906432749, -3.469785575048733, 0]), new Vector3().fromArray([4.844054580896684, -3.898635477582846, 0])), new Line(new Vector3().fromArray([4.844054580896684, -3.898635477582846, 0]), new Vector3().fromArray([4.912280701754386, -2.7777777777777777, 0])), new Line(new Vector3().fromArray([4.912280701754386, -2.7777777777777777, 0]), new Vector3().fromArray([3.9668615984405444, -1.042884990253411, 0])), new Line(new Vector3().fromArray([2.465886939571151, 1.939571150097466, 0]), new Vector3().fromArray([1.306042884990254, -0.30214424951267027, 0])), new Line(new Vector3().fromArray([1.306042884990254, -0.30214424951267027, 0]), new Vector3().fromArray([3.586744639376219, 0.253411306042885, 0])), new Line(new Vector3().fromArray([3.586744639376219, 0.253411306042885, 0]), new Vector3().fromArray([2.348927875243664, -1.042884990253411, 0])), new Line(new Vector3().fromArray([2.348927875243664, -1.042884990253411, 0]), new Vector3().fromArray([3.9668615984405444, -1.042884990253411, 0])), new Line(new Vector3().fromArray([1.306042884990254, -0.30214424951267027, 0]), new Vector3().fromArray([2.348927875243664, -1.042884990253411, 0])), new Line(new Vector3().fromArray([3.9668615984405444, -1.042884990253411, 0]), new Vector3().fromArray([3.586744639376219, 0.253411306042885, 0])), new Line(new Vector3().fromArray([3.586744639376219, 0.253411306042885, 0]), new Vector3().fromArray([2.465886939571151, 1.939571150097466, 0])), ] let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(1); expect(g.m_RegionsInternal.length).toBe(8); expectReg(g); }); test('矩形套矩形', () => { let culist = [ new Line(new Vector3().fromArray([12.781615108958839, -0.7407480871670697, 0]), new Vector3().fromArray([12.781615108958837, -5.947836900726392, 0])), new Line(new Vector3().fromArray([12.781615108958837, -5.947836900726392, 0]), new Vector3().fromArray([19.5123215496368, -5.947836900726394, 0])), new Line(new Vector3().fromArray([19.5123215496368, -5.947836900726394, 0]), new Vector3().fromArray([19.5123215496368, -0.7407480871670714, 0])), new Line(new Vector3().fromArray([19.5123215496368, -0.7407480871670714, 0]), new Vector3().fromArray([12.781615108958839, -0.7407480871670697, 0])), new Line(new Vector3().fromArray([12.781615108958839, -0.7407480871670697, 0]), new Vector3().fromArray([14.054086973365617, -2.0467060532687644, 0])), new Line(new Vector3().fromArray([14.054086973365617, -2.0467060532687644, 0]), new Vector3().fromArray([18.54122460048426, -2.0467060532687653, 0])), new Line(new Vector3().fromArray([18.54122460048426, -2.0467060532687653, 0]), new Vector3().fromArray([18.54122460048426, -5.026969104116222, 0])), new Line(new Vector3().fromArray([18.54122460048426, -5.026969104116222, 0]), new Vector3().fromArray([14.054086973365617, -5.026969104116221, 0])), new Line(new Vector3().fromArray([14.054086973365617, -5.026969104116221, 0]), new Vector3().fromArray([14.054086973365617, -2.0467060532687644, 0])), new Line(new Vector3().fromArray([18.54122460048426, -5.026969104116222, 0]), new Vector3().fromArray([19.5123215496368, -5.947836900726394, 0])), new Line(new Vector3().fromArray([14.054086973365617, -2.0467060532687644, 0]), new Vector3().fromArray([18.54122460048426, -5.026969104116222, 0])) ] let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(1); expect(g.m_RegionsInternal.length).toBe(4); expectReg(g); }); test('保护伞', () => { let culist = [ new Line(new Vector3().fromArray([-2.0843672456575684, 1.9106699751861045, 0]), new Vector3().fromArray([-4.01985111662531, -0.7196029776674939, 0])), new Line(new Vector3().fromArray([-4.01985111662531, -0.7196029776674939, 0]), new Vector3().fromArray([-1.4640198511166256, -0.7196029776674939, 0])), new Line(new Vector3().fromArray([-1.4640198511166256, -0.7196029776674939, 0]), new Vector3().fromArray([-2.0843672456575684, 1.9106699751861045, 0])), new Line(new Vector3().fromArray([-2.0843672456575684, 1.9106699751861045, 0]), new Vector3().fromArray([-4.156327543424318, 2.7171215880893302, 0])), new Line(new Vector3().fromArray([-4.156327543424318, 2.7171215880893302, 0]), new Vector3().fromArray([-1.7121588089330027, 4.094292803970223, 0])), new Line(new Vector3().fromArray([-1.7121588089330027, 4.094292803970223, 0]), new Vector3().fromArray([-2.0843672456575684, 1.9106699751861045, 0])), new Line(new Vector3().fromArray([-2.0843672456575684, 1.9106699751861045, 0]), new Vector3().fromArray([-0.33498759305210907, 2.7543424317617866, 0])), new Line(new Vector3().fromArray([-0.33498759305210907, 2.7543424317617866, 0]), new Vector3().fromArray([-0.33498759305210946, 0.5583126550868487, 0])), new Line(new Vector3().fromArray([-0.33498759305210946, 0.5583126550868487, 0]), new Vector3().fromArray([-2.0843672456575684, 1.9106699751861045, 0])), ] let g = new RegionParse(culist); g.m_RegionsOutline.length //? g.m_RegionsInternal.length //? expect(g.m_RegionsOutline.length).toBe(3); expect(g.m_RegionsInternal.length).toBe(0); expectReg(g); });