修复:在墙体分析时,删除同向线(只保留其一),保证了区域分析正确性

pull/1929/head
ChenX 2 years ago
parent 6a08ef9c39
commit a373749050

@ -230,3 +230,18 @@ test('分裂的曲线必须保持顺序', () =>
for (let c of walls[0].LeftCurves) for (let c of walls[0].LeftCurves)
expect(c.Length).toMatchNumberSnapshot(); 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<RoomWallBase>(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();
});

@ -166,6 +166,10 @@ exports[`分裂的曲线必须保持顺序 2`] = `"2229.24195"`;
exports[`分裂的曲线必须保持顺序 3`] = `"3933.92767"`; exports[`分裂的曲线必须保持顺序 3`] = `"3933.92767"`;
exports[`删除共面(同向)墙线 1`] = `"981.93479"`;
exports[`删除共面(同向)墙线 2`] = `"1364.37111"`;
exports[`双圆弧 1`] = ` exports[`双圆弧 1`] = `
Array [ Array [
-1868.5481692961328, -1868.5481692961328,
@ -1276,8 +1280,8 @@ Array [
exports[`测试重叠墙裁剪共面墙 27`] = ` exports[`测试重叠墙裁剪共面墙 27`] = `
Array [ Array [
-2511.8199855659095,
0, 0,
240,
0, 0,
] ]
`; `;
@ -1285,15 +1289,7 @@ Array [
exports[`测试重叠墙裁剪共面墙 28`] = ` exports[`测试重叠墙裁剪共面墙 28`] = `
Array [ Array [
0, 0,
360, -240,
0,
]
`;
exports[`测试重叠墙裁剪共面墙 29`] = `
Array [
0,
-360,
0, 0,
] ]
`; `;

@ -1234,7 +1234,7 @@ export class Polyline extends Curve
let d2 = this._LineData[FixIndex(i + 1, this._LineData)]; let d2 = this._LineData[FixIndex(i + 1, this._LineData)];
let curve: Curve; 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); curve = new Line(AsVector3(d1.pt), AsVector3(d2.pt)).ApplyMatrix(this.OCSNoClone);
else else
curve = new Arc().ParseFromBul(d1.pt, d2.pt, d1.bul).ApplyMatrix(this.OCSNoClone); curve = new Arc().ParseFromBul(d1.pt, d2.pt, d1.bul).ApplyMatrix(this.OCSNoClone);

@ -21,7 +21,7 @@ export class CurveTrim
this._Box = _curve.BoundingBox; this._Box = _curve.BoundingBox;
} }
TrimBy(contour: Contour, box: Box3) TrimBy(contour: Contour, box: Box3, saveSyntropy = false)
{ {
if (this._IsErase) return; if (this._IsErase) return;
@ -34,7 +34,7 @@ export class CurveTrim
if (iParams.length === 2)//[0,1]全包含 或者在外部 if (iParams.length === 2)//[0,1]全包含 或者在外部
{ {
let p = this._curve.GetPointAtParam(0.5); let p = this._curve.GetPointAtParam(0.5);
if (this.PointInContour(p, contour, box)) if (this.PointInContour(p, contour, box, saveSyntropy))
this._IsErase = true; this._IsErase = true;
return; return;
} }
@ -49,8 +49,8 @@ export class CurveTrim
continue; continue;
let midParam = (sparam + eparam) * 0.5; let midParam = (sparam + eparam) * 0.5;
let p = this._curve.GetPointAtParam(midParam);//这个性能不高 可以优化 let p = this.GetPointAtParam(midParam);
if (this.PointInContour(p, contour, box)) if (this.PointInContour(p, contour, box, saveSyntropy))
{ {
InsertRangeAndUnion(this._TrimParams, sparam, eparam, insertIndex); 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)); 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); 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; 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))//点在线上 if (cu.ParamOnCurve(d.param) && equalv3(d.closestPt, p, 1e-5))//点在线上
{ {
let derv = cu.GetFistDeriv(d.param).normalize(); let derv = cu.GetFistDeriv(d.param).normalize();
return equalv3(derv, this.derv); return equalv3(derv, this.derv) || (saveSyntropy && equalv3(derv.negate(), this.derv));//因为墙体为顺时针 轮廓为逆时针 所以这里相等=反向
} }
} }
else else
{ {
if (cu.PtOnCurve(p)) if (cu.PtOnCurve(p, 1e-5))
return equalv3(this.derv, cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize()); {
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); 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; if (!contourBox.containsPoint(p)) return false;
let pl = contour.Curve as Polyline; let pl = contour.Curve as Polyline;
let thisDerv = this._curve.GetFistDeriv(p).normalize(); let thisDerv = this._curve.GetFistDeriv(p).normalize();
if (this._IsLeft) thisDerv.negate();
for (let i = 0; i < pl.EndParam; i++) for (let i = 0; i < pl.EndParam; i++)
{ {
@ -183,19 +187,18 @@ export class CurveTrimArc extends CurveTrim
if (cu instanceof Line) if (cu instanceof Line)
{ {
let d = cu.GetClosestAtPoint(p, true); 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(); let derv = cu.GetFistDeriv(d.param).normalize();
return equalv3(derv, thisDerv); return equalv3(derv, thisDerv) || (saveSyntropy && equalv3(derv.negate(), thisDerv));//因为墙体为顺时针 轮廓为逆时针 所以这里相等=反向
} }
} }
else else
{ {
if (cu.PtOnCurve(p)) if (cu.PtOnCurve(p, 1e-5))
{ {
let derv = this._curve.GetFistDeriv(this._curve.GetParamAtPoint2(p)).normalize(); let cuDerv = cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize();
if (this._IsLeft) derv.negate(); return equalv3(thisDerv, cuDerv) || (saveSyntropy && equalv3(cuDerv.negate(), thisDerv));
return equalv3(derv, cu.GetFistDeriv(cu.GetParamAtPoint2(p)).normalize());
} }
} }
} }

@ -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 => 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) //裁剪的好处是有些细的盖子将会消失 // if (id !== index) //裁剪的好处是有些细的盖子将会消失
trim.TrimBy(trimContours[id], this.boxs[id]); trim.TrimBy(trimContours[id], this.boxs[id], index > id);
return false; return false;
})); }));

Loading…
Cancel
Save