diff --git a/__test__/Booloperate/__snapshots__/bool4.test.ts.snap b/__test__/Booloperate/__snapshots__/bool4.test.ts.snap new file mode 100644 index 000000000..733722f48 --- /dev/null +++ b/__test__/Booloperate/__snapshots__/bool4.test.ts.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`交点大于等于2_但是还是分离 1`] = `310430.5057844047`; + +exports[`交点大于等于2_但是还是分离 2`] = `40090.549687200226`; diff --git a/__test__/Booloperate/bool4.test.ts b/__test__/Booloperate/bool4.test.ts new file mode 100644 index 000000000..e67c54991 --- /dev/null +++ b/__test__/Booloperate/bool4.test.ts @@ -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(); +}); diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index 2b31b0fec..e0b1f7e4c 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -98,6 +98,11 @@ export class Contour UnionBoolOperation(target: Contour): Contour[] { let resultCus = this.GetIntersetAndUnionList(target); + + //快速 + if (resultCus.unionList.every(c => c.IsClose)) + return Contour.GetAllContour(resultCus.unionList); + //并集后的线段表如果有共线的直接合并起来 let cus: Curve[] = []; for (let pl of resultCus.unionList) @@ -248,6 +253,12 @@ export class Contour unionList.push(pl); } } + + //特殊的分离 + if (intersectionList.length === 0 && unionList.length === (sourceCus.length + targetCus.length)) + { + return { intersectionList, unionList: [sourceOutline, targetOutline] }; + } } return { intersectionList, unionList }; } @@ -295,11 +306,18 @@ export class Contour subtractList.push(pl); } + //源对象没有被破坏 + let sourceNotBreak = subtractList.length === sourceCus.length; + for (let pl of targetCus) { if (this.CuInOutline(pl)) subtractList.push(pl); } + + if (sourceNotBreak && subtractList.length === sourceCus.length) + return [sourceOutline]; + return subtractList; } }