修正一个切割错误引发的布尔错误

pull/244/MERGE
ChenX 6 years ago
parent 7ed41f6536
commit 5f350e2459

@ -33,3 +33,15 @@ test('#IR8AN交集错误', () =>
reg.BooleanOper(regs[1], BoolOpeartionType.Intersection); reg.BooleanOper(regs[1], BoolOpeartionType.Intersection);
expect(reg.ShapeManager.ShapeList.length).toBe(1); expect(reg.ShapeManager.ShapeList.length).toBe(1);
}); });
test('布尔错误', () =>
{
let data =
[2, "Region", 2, 1, 117, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 1, 1, 1, 1, "Polyline", 2, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [-112.67605633802839, -202.8168633802817], 0, [357.7464436619716, -202.8168633802817], 0, [357.7464436619716, 173.23943661971833], 0, [-112.67605633802839, 173.23943661971833], 0, true, 0, "Region", 2, 1, 116, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 1, 1, 1, 1, "Polyline", 2, 1, 0, false, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [25.35211267605621, -202.81687464788737], 0, [225.3521126760562, -202.81687464788737], 0, [225.3521126760562, -49.295774647887384], 0, [25.35211267605621, -49.295774647887384], 0, true, 0]
let regs: Region[] = LoadRegionsFromFileData(data);
regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract);
expect(regs[0].ShapeManager.ShapeCount).toBe(1);
});

@ -1,5 +1,5 @@
import { Polyline } from "../../src/DatabaseServices/Polyline"; import { Polyline } from "../../src/DatabaseServices/Polyline";
import { Vector2 } from "three"; import { Vector2, Vector3 } from "three";
//构造测试的多段线 //构造测试的多段线
@ -109,3 +109,14 @@ function createTestPolyline(): Polyline
} }
}); });
} }
test('切割点在尾部', () =>
{
let pl = new Polyline();
pl.Create2Pt(new Vector3(), new Vector3(100, 100));
let cus = pl.GetSplitCurves([1, 4]);
expect(cus.length).toBe(2);
cus = pl.GetSplitCurves([2, 3]);
expect(cus.length).toBe(2);
});

@ -111,7 +111,7 @@ export abstract class Curve extends Entity
return []; return [];
param.push(0, this.EndParam); param.push(0, this.EndParam);
arraySortByNumber(param); arraySortByNumber(param);
arrayRemoveDuplicateBySort(param, (e1, e2) => equaln(e1, e2, 1e-6)); arrayRemoveDuplicateBySort(param, (e1, e2) => equaln(e1, e2, 1e-7));
return param; return param;
} }
else if (this.ParamOnCurve(param)) else if (this.ParamOnCurve(param))

@ -543,9 +543,11 @@ export class Polyline extends Curve
}); });
//排序 //排序
params.sort((a, b) => a - b); params.sort((a, b) => a - b);
let hasEndParam = arrayLast(params) === this.EndParam;
//必须加入最后一个参数,保证切割后的曲线完整 //必须加入最后一个参数,保证切割后的曲线完整
params.push(this.EndParam); if (!hasEndParam)
arrayRemoveDuplicateBySort(params, (e1, e2) => equaln(e1, e2, 1e-6)); params.push(this.EndParam);
arrayRemoveDuplicateBySort(params, (e1, e2) => equaln(e1, e2, 1e-8));
params = params.filter(p => this.ParamOnCurve(p)); params = params.filter(p => this.ParamOnCurve(p));
if (params.length === 0) if (params.length === 0)
return []; return [];
@ -577,7 +579,7 @@ export class Polyline extends Curve
//添加点 //添加点
for (let i = 0; i < pafloor; i++) for (let i = 0; i < pafloor; i++)
{ {
if (i == 0 && !equaln(buls[0], 0, 1e-6)) if (i == 0 && !equaln(buls[0], 0, 1e-8))
{ {
buls[0] = Math.tan((1 - prePa) * Math.atan(buls[0])); buls[0] = Math.tan((1 - prePa) * Math.atan(buls[0]));
} }
@ -611,7 +613,7 @@ export class Polyline extends Curve
} }
//当曲线为闭合曲线,并且不存在0切割参数时,首尾连接曲线 //当曲线为闭合曲线,并且不存在0切割参数时,首尾连接曲线
if (this.m_ClosedMark && !hasZeroParam) if (this.m_ClosedMark && !hasZeroParam && !hasEndParam)
{ {
let lastPl = pls[pls.length - 1]; let lastPl = pls[pls.length - 1];
if (equalv2(arrayLast(lastPl.m_LineData).pt, pls[0].m_LineData[0].pt)) if (equalv2(arrayLast(lastPl.m_LineData).pt, pls[0].m_LineData[0].pt))

Loading…
Cancel
Save