import { Vector3 } from "three"; import { RoomHolePolyline } from "../../src/DatabaseServices/Room/Entity/Wall/Hole/RoomHolePolyline"; import { RoomWallLine } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWallLine"; import { RoomIHoleParseAndModify, RoomLHoleParseAndModify } from "../../src/DatabaseServices/Room/ParseService/Hole/RoomIHoleParseAndModify"; import "../Utils/jest.util"; import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; LoadEntityFromFileData; //如果不延迟导入,则导致循环依赖错误 import { CADFiler } from "../../src/DatabaseServices/CADFiler"; import { Database } from "../../src/DatabaseServices/Database"; import { RoomWallArc } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWallArc"; import { RoomWallBase } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWallBase"; import { RoomWallParse } from "../../src/DatabaseServices/Room/ParseService/RoomWallParse"; import { UpdateRelevanceWallHole } from "../../src/Reactor/RoomHoleReactor"; test('墙洞1', () => { let db = new Database; let wall1 = new RoomWallLine(new Vector3(0, 0, 0), new Vector3(5000, 0, 0)); let wall2 = new RoomWallLine(new Vector3(0, 0, 0), new Vector3(0, 5000, 0)); db.ModelSpace.Append(wall1); db.ModelSpace.Append(wall2); let hole = new RoomHolePolyline(); hole.Points = [ new Vector3(100, 0, 0), new Vector3(1100, 0, 0), ]; hole.RelevancyWalls = [wall1.Id]; db.ModelSpace.Append(hole); wall1.RelevancyHoles.push(hole.Id); new RoomWallParse(true, db, true).Parse([wall1, wall2]); UpdateRelevanceWallHole([wall1, wall2]); let m = new RoomIHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.LeftDist = 300; UpdateRelevanceWallHole([wall1, wall2]); m = new RoomIHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.RightDist = 300; UpdateRelevanceWallHole([wall1, wall2]); m = new RoomIHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.LeftDist = 0; UpdateRelevanceWallHole([wall1, wall2]); m = new RoomIHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.RightDist = 0; UpdateRelevanceWallHole([wall1, wall2]); m = new RoomIHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); }); test('圆弧I洞', () => { let db = new Database; let wall = new RoomWallArc(new Vector3(0, 0, 0), 5000, 0, Math.PI); db.ModelSpace.Append(wall); new RoomWallParse(true, db, true).Parse([wall]); let hole = new RoomHolePolyline(); hole.Points = [ wall.GetPointAtDistance(100), wall.GetPointAtDistance(600), ]; hole.RelevancyWalls = [wall.Id]; db.ModelSpace.Append(hole); wall.RelevancyHoles.push(hole.Id); UpdateRelevanceWallHole([wall]); let m = new RoomIHoleParseAndModify(hole); expect(m.Length).toMatchNumberSnapshot(); m.LeftDist = 0; UpdateRelevanceWallHole([wall]); m = new RoomIHoleParseAndModify(hole); expect(m.Length).toMatchNumberSnapshot(); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); }); test('直线L洞', () => { let db = new Database(); let wall1 = new RoomWallLine(new Vector3(0, 0, 0), new Vector3(5000, 0, 0)); let wall2 = new RoomWallLine(new Vector3(0, 0, 0), new Vector3(0, 5000, 0)); db.ModelSpace.Append(wall1); db.ModelSpace.Append(wall2); let hole = new RoomHolePolyline(); hole.Points = [ new Vector3(1000, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 1000, 0), ]; hole.RelevancyWalls = [wall1.Id, wall2.Id]; db.ModelSpace.Append(hole); wall1.RelevancyHoles.push(hole.Id); wall2.RelevancyHoles.push(hole.Id); new RoomWallParse(true, db, true).Parse([wall1, wall2]); UpdateRelevanceWallHole([wall1, wall2]); let m = new RoomLHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.LeftDist = 0; m.RightDist = 5000; UpdateRelevanceWallHole([wall1, wall2]); m = new RoomLHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); }); test('直线U洞', () => { let db = new Database(); let wall1 = new RoomWallLine(new Vector3(0, 0, 0), new Vector3(5000, 0, 0)); let wall2 = new RoomWallLine(new Vector3(0, 0, 0), new Vector3(0, 5000, 0)); let wall3 = new RoomWallLine(new Vector3(5000, 0, 0), new Vector3(5000, 5000, 0)); db.ModelSpace.Append(wall1); db.ModelSpace.Append(wall2); db.ModelSpace.Append(wall3); let hole = new RoomHolePolyline(); hole.Points = [ new Vector3(0, 1000, 0), new Vector3(0, 0, 0), new Vector3(5000, 0, 0), new Vector3(5000, 1000, 0), ]; hole.RelevancyWalls = [wall2.Id, wall1.Id, wall3.Id]; db.ModelSpace.Append(hole); wall1.RelevancyHoles.push(hole.Id); wall2.RelevancyHoles.push(hole.Id); wall3.RelevancyHoles.push(hole.Id); new RoomWallParse(true, db, true).Parse([wall1, wall2, wall3]); UpdateRelevanceWallHole([wall1, wall2, wall3]); let m = new RoomLHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.LeftDist = 60; m.RightDist = 5000; UpdateRelevanceWallHole([wall1, wall2]); m = new RoomLHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); }); test('圆弧L洞', () => { let data = require("./roomLHole_test.json"); let file = new CADFiler(data); let db = new Database(); db.FileRead(file); let ents = db.ModelSpace.Entitys; let hole: RoomHolePolyline = new RoomHolePolyline(); for (let en of ents) { if (en instanceof RoomHolePolyline) hole = en; else if (en instanceof RoomWallBase) new RoomWallParse(true, db, true).Parse([en]); } UpdateRelevanceWallHole(hole.FakerWalls); let m = new RoomLHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); m.RightDist = 0; m.LeftDist = 0; UpdateRelevanceWallHole(hole.FakerWalls); m = new RoomLHoleParseAndModify(hole); expect(m.LeftDist).toMatchNumberSnapshot(); expect(m.RightDist).toMatchNumberSnapshot(); });