From a3737490501bc25eb4979014fbe2009596e452dd Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 1 Jun 2022 11:28:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E5=9C=A8=E5=A2=99=E4=BD=93?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=97=B6,=E5=88=A0=E9=99=A4=E5=90=8C?= =?UTF-8?q?=E5=90=91=E7=BA=BF(=E5=8F=AA=E4=BF=9D=E7=95=99=E5=85=B6?= =?UTF-8?q?=E4=B8=80),=E4=BF=9D=E8=AF=81=E4=BA=86=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=AD=A3=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Room/RoomParse.test.ts | 15 ++++++++ .../Room/__snapshots__/RoomParse.test.ts.snap | 16 ++++----- src/DatabaseServices/Entity/Polyline.ts | 2 +- .../Room/ParseService/CurveTrim.ts | 35 ++++++++++--------- .../Room/ParseService/RoomWallParse.ts | 2 +- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/__test__/Room/RoomParse.test.ts b/__test__/Room/RoomParse.test.ts index 1283aed80..7f14f11ec 100644 --- a/__test__/Room/RoomParse.test.ts +++ b/__test__/Room/RoomParse.test.ts @@ -230,3 +230,18 @@ test('分裂的曲线必须保持顺序', () => for (let c of walls[0].LeftCurves) expect(c.Length).toMatchNumberSnapshot(); }); + +test('删除共面(同向)墙线', () => +{ + let d = + { "file": [3, "RoomWallLine", 1, 3, 8, 2, 107, 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, 5651.575210577166, 5517.021087841073, 0, 4448.422258703592, 5517.021087841073, 0, "RoomWallLine", 1, 3, 8, 2, 108, 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, 4448.422258703592, 4477.491540022665, 0, 5651.575210577166, 5517.021087841073, 0, "RoomWallLine", 1, 3, 8, 2, 102, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -3964.6797074899305, 60, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -3964.6797074899305, 60, 0, 1], 0, 120, 0, 2700, 8413.101966193522, 4417.491540022665, 0, 8413.101966193522, 5517.021087841073, 0], "basePt": { "x": 4388.422258703592, "y": 4432.090428143906, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let walls = LoadEntityFromFileData(d); + new RoomWallParse(true, undefined, false).Parse(walls); + + for (let c of walls[0].LeftCurves) + expect(c.Length).toMatchNumberSnapshot(); + for (let c of walls[0].RightCurves) + expect(c.Length).toMatchNumberSnapshot(); + for (let c of walls[0].LidCurves) + expect(c.Length).toMatchNumberSnapshot(); +}); diff --git a/__test__/Room/__snapshots__/RoomParse.test.ts.snap b/__test__/Room/__snapshots__/RoomParse.test.ts.snap index 06fdc6b0f..3e1acfeac 100644 --- a/__test__/Room/__snapshots__/RoomParse.test.ts.snap +++ b/__test__/Room/__snapshots__/RoomParse.test.ts.snap @@ -166,6 +166,10 @@ exports[`分裂的曲线必须保持顺序 2`] = `"2229.24195"`; exports[`分裂的曲线必须保持顺序 3`] = `"3933.92767"`; +exports[`删除共面(同向)墙线 1`] = `"981.93479"`; + +exports[`删除共面(同向)墙线 2`] = `"1364.37111"`; + exports[`双圆弧 1`] = ` Array [ -1868.5481692961328, @@ -1276,8 +1280,8 @@ Array [ exports[`测试重叠墙裁剪共面墙 27`] = ` Array [ - -2511.8199855659095, 0, + 240, 0, ] `; @@ -1285,15 +1289,7 @@ Array [ exports[`测试重叠墙裁剪共面墙 28`] = ` Array [ 0, - 360, - 0, -] -`; - -exports[`测试重叠墙裁剪共面墙 29`] = ` -Array [ - 0, - -360, + -240, 0, ] `; diff --git a/src/DatabaseServices/Entity/Polyline.ts b/src/DatabaseServices/Entity/Polyline.ts index 6db6a5048..d0de43b0c 100644 --- a/src/DatabaseServices/Entity/Polyline.ts +++ b/src/DatabaseServices/Entity/Polyline.ts @@ -1234,7 +1234,7 @@ export class Polyline extends Curve let d2 = this._LineData[FixIndex(i + 1, this._LineData)]; let curve: Curve; - if (equaln(d1.bul, 0, 1e-8)) + if (equaln(d1.bul, 0, 1e-5)) curve = new Line(AsVector3(d1.pt), AsVector3(d2.pt)).ApplyMatrix(this.OCSNoClone); else curve = new Arc().ParseFromBul(d1.pt, d2.pt, d1.bul).ApplyMatrix(this.OCSNoClone); diff --git a/src/DatabaseServices/Room/ParseService/CurveTrim.ts b/src/DatabaseServices/Room/ParseService/CurveTrim.ts index e741bce35..9c8f141af 100644 --- a/src/DatabaseServices/Room/ParseService/CurveTrim.ts +++ b/src/DatabaseServices/Room/ParseService/CurveTrim.ts @@ -21,7 +21,7 @@ export class CurveTrim this._Box = _curve.BoundingBox; } - TrimBy(contour: Contour, box: Box3) + TrimBy(contour: Contour, box: Box3, saveSyntropy = false) { if (this._IsErase) return; @@ -34,7 +34,7 @@ export class CurveTrim if (iParams.length === 2)//[0,1]全包含 或者在外部 { let p = this._curve.GetPointAtParam(0.5); - if (this.PointInContour(p, contour, box)) + if (this.PointInContour(p, contour, box, saveSyntropy)) this._IsErase = true; return; } @@ -49,8 +49,8 @@ export class CurveTrim continue; let midParam = (sparam + eparam) * 0.5; - let p = this._curve.GetPointAtParam(midParam);//这个性能不高 可以优化 - if (this.PointInContour(p, contour, box)) + let p = this.GetPointAtParam(midParam); + if (this.PointInContour(p, contour, box, saveSyntropy)) { InsertRangeAndUnion(this._TrimParams, sparam, eparam, insertIndex); @@ -64,7 +64,7 @@ export class CurveTrim } - PointInContour(p: Vector3, contour: Contour, contourBox: Box3) + PointInContour(p: Vector3, contour: Contour, contourBox: Box3, saveSyntropy = false) { return contourBox.containsPoint(p) && (contour.Curve.PtInCurve(p) && !contour.Curve.PtOnCurve(p)); } @@ -109,7 +109,7 @@ export class CurveTrimLine extends CurveTrim return this._Fd.clone().multiplyScalar(param).add(this._Sp); } - override PointInContour(p: Vector3, contour: Contour, contourBox: Box3) + override PointInContour(p: Vector3, contour: Contour, contourBox: Box3, saveSyntropy = false) { if (!contourBox.containsPoint(p)) return false; @@ -123,13 +123,16 @@ export class CurveTrimLine extends CurveTrim if (cu.ParamOnCurve(d.param) && equalv3(d.closestPt, p, 1e-5))//点在线上 { let derv = cu.GetFistDeriv(d.param).normalize(); - return equalv3(derv, this.derv); + return equalv3(derv, this.derv) || (saveSyntropy && equalv3(derv.negate(), this.derv));//因为墙体为顺时针 轮廓为逆时针 所以这里相等=反向 } } else { - if (cu.PtOnCurve(p)) - return equalv3(this.derv, cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize()); + if (cu.PtOnCurve(p, 1e-5)) + { + let derv = cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize(); + return equalv3(this.derv, derv) || (saveSyntropy && equalv3(derv.negate(), this.derv)); + } } } @@ -170,12 +173,13 @@ export class CurveTrimArc extends CurveTrim { super(_curve); } - override PointInContour(p: Vector3, contour: Contour, contourBox: Box3) + override PointInContour(p: Vector3, contour: Contour, contourBox: Box3, saveSyntropy = false) { if (!contourBox.containsPoint(p)) return false; let pl = contour.Curve as Polyline; let thisDerv = this._curve.GetFistDeriv(p).normalize(); + if (this._IsLeft) thisDerv.negate(); for (let i = 0; i < pl.EndParam; i++) { @@ -183,19 +187,18 @@ export class CurveTrimArc extends CurveTrim if (cu instanceof Line) { let d = cu.GetClosestAtPoint(p, true); - if (cu.ParamOnCurve(d.param) && equalv3(d.closestPt, p, 1e-5))//点在线上 + if (cu.ParamOnCurve(d.param) && equalv3(d.closestPt, p, 1e-5))//点在线上 //这个代码似乎是错误的,因为直线和圆弧不可能重合 { let derv = cu.GetFistDeriv(d.param).normalize(); - return equalv3(derv, thisDerv); + return equalv3(derv, thisDerv) || (saveSyntropy && equalv3(derv.negate(), thisDerv));//因为墙体为顺时针 轮廓为逆时针 所以这里相等=反向 } } else { - if (cu.PtOnCurve(p)) + if (cu.PtOnCurve(p, 1e-5)) { - let derv = this._curve.GetFistDeriv(this._curve.GetParamAtPoint2(p)).normalize(); - if (this._IsLeft) derv.negate(); - return equalv3(derv, cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize()); + let cuDerv = cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize(); + return equalv3(thisDerv, cuDerv) || (saveSyntropy && equalv3(cuDerv.negate(), thisDerv)); } } } diff --git a/src/DatabaseServices/Room/ParseService/RoomWallParse.ts b/src/DatabaseServices/Room/ParseService/RoomWallParse.ts index ba7c628f6..e242c3d4a 100644 --- a/src/DatabaseServices/Room/ParseService/RoomWallParse.ts +++ b/src/DatabaseServices/Room/ParseService/RoomWallParse.ts @@ -692,7 +692,7 @@ export class RoomWallParse this.fb.search(trim._Box.min.x - 1e-2, trim._Box.min.y - 1e-2, trim._Box.max.x + 1e-2, trim._Box.max.y + 1e-2, (id => { // if (id !== index) //裁剪的好处是有些细的盖子将会消失 - trim.TrimBy(trimContours[id], this.boxs[id]); + trim.TrimBy(trimContours[id], this.boxs[id], index > id); return false; }));