From 8ff9d6b0e132f45ecb2d14e16f2c96948b4a7a4f Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 8 Jun 2022 17:13:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91:=E5=A2=9E=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Room/RoomRemoveDup.test.ts | 30 +++++++++++++++++++ .../__snapshots__/RoomRemoveDup.test.ts.snap | 21 +++++++++++++ src/Add-on/Room/DrawRectWall.ts | 4 +-- .../ParseService/RoomWallRemoveDuplicate.ts | 3 +- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 __test__/Room/RoomRemoveDup.test.ts create mode 100644 __test__/Room/__snapshots__/RoomRemoveDup.test.ts.snap diff --git a/__test__/Room/RoomRemoveDup.test.ts b/__test__/Room/RoomRemoveDup.test.ts new file mode 100644 index 000000000..9c1a89b96 --- /dev/null +++ b/__test__/Room/RoomRemoveDup.test.ts @@ -0,0 +1,30 @@ +import { RoomWallBase } from "../../src/DatabaseServices/Room/Entity/Wall/RoomWallBase"; +import { RoomWallRemoveDuplicate } from "../../src/DatabaseServices/Room/ParseService/RoomWallRemoveDuplicate"; +import "../Utils/jest.util"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; + + +test('简单的墙体删除重复', () => +{ + let d1 = + { "file": [4, "RoomWallLine", 1, 3, 8, 2, 116, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 0, 2000, 0, 0, 0, 0, "RoomWallLine", 1, 3, 8, 2, 117, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 0, 0, 0, 2000, 0, 0, "RoomWallLine", 1, 3, 8, 2, 118, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 2000, 0, 0, 2000, 2000, 0, "RoomWallLine", 1, 3, 8, 2, 119, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 2000, 2000, 0, 0, 2000, 0], "basePt": { "x": -60, "y": -60, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let d2 = + { "file": [4, "RoomWallLine", 1, 3, 8, 2, 126, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 1300, 0, 0, 1300, 1000, 0, "RoomWallLine", 1, 3, 8, 2, 127, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 1300, 1000, 0, 300, 1000, 0, "RoomWallLine", 1, 3, 8, 2, 124, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 300, 1000, 0, 300, 0, 0, "RoomWallLine", 1, 3, 8, 2, 125, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 120, 0, 2700, 300, 0, 0, 1300, 0, 0], "basePt": { "x": 240, "y": -60, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + + let walls1 = LoadEntityFromFileData(d1); + let walls2 = LoadEntityFromFileData(d2); + + let rrd = new RoomWallRemoveDuplicate(walls1, walls2); + expect(rrd.SplitWalls.length).toMatchSnapshot(); + for (let w of rrd.SplitWalls) + expect(w.Length).toMatchNumberSnapshot(); + + walls1 = LoadEntityFromFileData(d1); + walls2 = LoadEntityFromFileData(d2); + let rrd2 = new RoomWallRemoveDuplicate(walls2, walls1); + + expect(rrd2.SplitWalls.length).toMatchSnapshot(); + for (let w of rrd2.SplitWalls) + expect(w.Length).toMatchNumberSnapshot(); + +}); diff --git a/__test__/Room/__snapshots__/RoomRemoveDup.test.ts.snap b/__test__/Room/__snapshots__/RoomRemoveDup.test.ts.snap new file mode 100644 index 000000000..ba023f021 --- /dev/null +++ b/__test__/Room/__snapshots__/RoomRemoveDup.test.ts.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`简单的墙体删除重复 1`] = `5`; + +exports[`简单的墙体删除重复 2`] = `"300.00000"`; + +exports[`简单的墙体删除重复 3`] = `"700.00000"`; + +exports[`简单的墙体删除重复 4`] = `"2000.00000"`; + +exports[`简单的墙体删除重复 5`] = `"2000.00000"`; + +exports[`简单的墙体删除重复 6`] = `"2000.00000"`; + +exports[`简单的墙体删除重复 7`] = `3`; + +exports[`简单的墙体删除重复 8`] = `"1000.00000"`; + +exports[`简单的墙体删除重复 9`] = `"1000.00000"`; + +exports[`简单的墙体删除重复 10`] = `"1000.00000"`; diff --git a/src/Add-on/Room/DrawRectWall.ts b/src/Add-on/Room/DrawRectWall.ts index 69c2e1356..c5dfba63c 100644 --- a/src/Add-on/Room/DrawRectWall.ts +++ b/src/Add-on/Room/DrawRectWall.ts @@ -5,7 +5,7 @@ import { Log } from "../../Common/Log"; import { RoomWallBase } from "../../DatabaseServices/Room/Entity/Wall/RoomWallBase"; import { RoomWallLine } from "../../DatabaseServices/Room/Entity/Wall/RoomWallLine"; import { WallSnapMode } from "../../DatabaseServices/Room/Entity/Wall/WallSnapMode"; -import { RoomParse } from "../../DatabaseServices/Room/ParseService/RoomParseUtil"; +import { GetAllWalls, RoomParse } from "../../DatabaseServices/Room/ParseService/RoomParseUtil"; import { RoomWallParse } from "../../DatabaseServices/Room/ParseService/RoomWallParse"; import { RoomWallRemoveDuplicate } from "../../DatabaseServices/Room/ParseService/RoomWallRemoveDuplicate"; import { Command } from "../../Editor/CommandMachine"; @@ -107,7 +107,7 @@ export class Command_DrawRectWall implements Command { UpdateDraw(rectRes.Point1UCS, rectRes.Point2UCS, false); - let rrd = new RoomWallRemoveDuplicate(walls);//删除重复 + let rrd = new RoomWallRemoveDuplicate(walls, GetAllWalls());//删除重复 for (let wall of rrd.SplitWalls) { diff --git a/src/DatabaseServices/Room/ParseService/RoomWallRemoveDuplicate.ts b/src/DatabaseServices/Room/ParseService/RoomWallRemoveDuplicate.ts index 47901fda7..e8f0e2883 100644 --- a/src/DatabaseServices/Room/ParseService/RoomWallRemoveDuplicate.ts +++ b/src/DatabaseServices/Room/ParseService/RoomWallRemoveDuplicate.ts @@ -10,7 +10,6 @@ import { RoomWallLine } from "../Entity/Wall/RoomWallLine"; import { CreateCurveTrim, CurveTrim } from "./CurveTrim"; import { CreateGetCurveParam, GetCurveParam } from './GetCurveParam'; import { Intersection } from './RangeUtils'; -import { GetAllWalls } from "./RoomParseUtil"; /** @@ -24,7 +23,7 @@ export class RoomWallRemoveDuplicate * @param diffWalls 可能已经在图纸内部 也可能是新画的 * @param [walls=GetAllWalls()] 都在图纸内 */ - constructor(diffWalls: RoomWallBase[], walls: RoomWallBase[] = GetAllWalls()) + constructor(diffWalls: RoomWallBase[], walls: RoomWallBase[]) { let diffSet = new Set(diffWalls); walls = walls.filter(w => !diffSet.has(w));