fix #IWQG7 修正面域合并问题,该问题导致了一个板件合并错误

pull/302/head
ChenX 5 years ago
parent 795360d446
commit f8bfe68927

@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`交点大于等于2_但是还是分离 1`] = `310430.5057844047`;
exports[`交点大于等于2_但是还是分离 2`] = `40090.549687200226`;

@ -0,0 +1,18 @@
import { LoadRegionsFromFileData } from "../Utils/LoadEntity.util";
import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils";
test('交点大于等于2_但是还是分离', () =>
{
let d = [2, "Region", 3, 2, 629, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 1, 1, 1, "Polyline", 3, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [5842.2632447015285, -382.81544021645357], 0, [6075.449244701528, -382.81544021645357], 0, [6075.449244701528, -210.8902402164536], 0, [5842.2632447015285, -210.8902402164536], 0, true, 0, "Region", 3, 2, 630, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 1, 1, 1, 1, "Polyline", 3, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 8, [5622.910304827508, -210.8902402164536], 0, [5842.2632447015285, -210.8902402164536], 0, [5842.2632447015285, -13.274942384012917], 0, [6075.449244701528, -13.274942384012888], 0, [6075.449244701528, -210.8902402164536], 0, [6253.303004827509, -210.8902402164536], 0, [6253.303004827509, 291.05255978354637], 0, [5622.910304827508, 291.05255978354637], 0, true, 0]
let [reg1, reg2] = LoadRegionsFromFileData(d);
let reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Union);
expect(reg.Area).toMatchSnapshot();
reg = reg1.Clone();
reg.BooleanOper(reg2.Clone(), BoolOpeartionType.Subtract);
expect(reg.Area).toMatchSnapshot();
});

@ -98,6 +98,11 @@ export class Contour
UnionBoolOperation(target: Contour): Contour[] UnionBoolOperation(target: Contour): Contour[]
{ {
let resultCus = this.GetIntersetAndUnionList(target); let resultCus = this.GetIntersetAndUnionList(target);
//快速
if (resultCus.unionList.every(c => c.IsClose))
return Contour.GetAllContour(resultCus.unionList);
//并集后的线段表如果有共线的直接合并起来 //并集后的线段表如果有共线的直接合并起来
let cus: Curve[] = []; let cus: Curve[] = [];
for (let pl of resultCus.unionList) for (let pl of resultCus.unionList)
@ -248,6 +253,12 @@ export class Contour
unionList.push(pl); unionList.push(pl);
} }
} }
//特殊的分离
if (intersectionList.length === 0 && unionList.length === (sourceCus.length + targetCus.length))
{
return { intersectionList, unionList: [sourceOutline, targetOutline] };
}
} }
return { intersectionList, unionList }; return { intersectionList, unionList };
} }
@ -295,11 +306,18 @@ export class Contour
subtractList.push(pl); subtractList.push(pl);
} }
//源对象没有被破坏
let sourceNotBreak = subtractList.length === sourceCus.length;
for (let pl of targetCus) for (let pl of targetCus)
{ {
if (this.CuInOutline(pl)) if (this.CuInOutline(pl))
subtractList.push(pl); subtractList.push(pl);
} }
if (sourceNotBreak && subtractList.length === sourceCus.length)
return [sourceOutline];
return subtractList; return subtractList;
} }
} }

Loading…
Cancel
Save