diff --git a/__test__/Room/RoomHoleUpdate.test.ts b/__test__/Room/RoomHoleUpdate.test.ts new file mode 100644 index 000000000..365b18caf --- /dev/null +++ b/__test__/Room/RoomHoleUpdate.test.ts @@ -0,0 +1,108 @@ +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 } from "../../src/DatabaseServices/Room/ParseService/Hole/RoomIHoleParseAndModify"; +import { RoomWallParse, UpdateRelevanceWallHole } from "../../src/ueapi"; +import "../Utils/jest.util"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; +LoadEntityFromFileData; +//如果不延迟导入,则导致循环依赖错误 +import { Database } from "../../src/DatabaseServices/Database"; +import { RoomWallArc } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWallArc"; + + +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(); +}); diff --git a/__test__/Room/__snapshots__/RoomHoleUpdate.test.ts.snap b/__test__/Room/__snapshots__/RoomHoleUpdate.test.ts.snap new file mode 100644 index 000000000..7d781c82d --- /dev/null +++ b/__test__/Room/__snapshots__/RoomHoleUpdate.test.ts.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`圆弧I洞 1`] = `"500.00000"`; + +exports[`圆弧I洞 2`] = `"500.00000"`; + +exports[`圆弧I洞 3`] = `"0.00000"`; + +exports[`圆弧I洞 4`] = `"15207.96327"`; + +exports[`墙洞1 1`] = `"40.00000"`; + +exports[`墙洞1 2`] = `"3900.00000"`; + +exports[`墙洞1 3`] = `"300.00000"`; + +exports[`墙洞1 4`] = `"3640.00000"`; + +exports[`墙洞1 5`] = `"3640.00000"`; + +exports[`墙洞1 6`] = `"300.00000"`; + +exports[`墙洞1 7`] = `"0.00000"`; + +exports[`墙洞1 8`] = `"3940.00000"`; + +exports[`墙洞1 9`] = `"3940.00000"`; + +exports[`墙洞1 10`] = `"0.00000"`; diff --git a/src/DatabaseServices/HistorycRecord.ts b/src/DatabaseServices/HistorycRecord.ts index 30cff0ce7..84d6223c3 100644 --- a/src/DatabaseServices/HistorycRecord.ts +++ b/src/DatabaseServices/HistorycRecord.ts @@ -1,13 +1,12 @@ import { Factory } from './CADFactory'; import { CADFiler } from './CADFiler'; -import { CADObject } from './CADObject'; import { ISerialize } from './ISerialize'; /** * 历史记录,用于撤销和重做的数据. */ @Factory -export class HistorycRecord extends CADObject +export class HistorycRecord { //指定撤销时所需要的数据 undoData: ISerialize;