From 629c67448769c4ace69266f1b4987fea0db94c99 Mon Sep 17 00:00:00 2001 From: ChenX Date: Tue, 9 Jul 2019 11:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B9=B6=E9=9B=86=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Booloperate/__snapshots__/union.test.ts.snap | 3 +++ __test__/Booloperate/union.test.ts | 14 ++++++++++++++ src/GraphicsSystem/BoolOperateUtils.ts | 15 +++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 __test__/Booloperate/__snapshots__/union.test.ts.snap create mode 100644 __test__/Booloperate/union.test.ts diff --git a/__test__/Booloperate/__snapshots__/union.test.ts.snap b/__test__/Booloperate/__snapshots__/union.test.ts.snap new file mode 100644 index 000000000..1b61a7246 --- /dev/null +++ b/__test__/Booloperate/__snapshots__/union.test.ts.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`并集错误,错误的曲线包含 1`] = `"20000.00000"`; diff --git a/__test__/Booloperate/union.test.ts b/__test__/Booloperate/union.test.ts new file mode 100644 index 000000000..8c513aee7 --- /dev/null +++ b/__test__/Booloperate/union.test.ts @@ -0,0 +1,14 @@ +import { LoadRegionsFromFileData } from "../Utils/LoadEntity.util"; +import { BoolOpeartionType } from "../../src/GraphicsSystem/BoolOperateUtils"; +import "../Utils/jest.util"; + +test('并集错误,错误的曲线包含', () => +{ + let regsData = + [2, "Region", 5, 2, 103, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 1, 1, 1, "Polyline", 5, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 4, [0, 0], 0, [100, 0], 0, [100, 100], 0, [0, 100], 0, true, 0, "Region", 5, 2, 104, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 100.0001, 0, 1], 0, 0, 1, 1, 1, 1, "Polyline", 5, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 100.0001, 0, 1], 0, 0, 2, 4, [0, 0], 0, [100, 0], 0, [100, 100], 0, [0, 100], 0, true, 0] + + let regs = LoadRegionsFromFileData(regsData); + + regs[0].BooleanOper(regs[1], BoolOpeartionType.Union); + expect(regs[0].Area).toMatchNumberSnapshot(); +}); diff --git a/src/GraphicsSystem/BoolOperateUtils.ts b/src/GraphicsSystem/BoolOperateUtils.ts index 0fa034caf..e14b61e1f 100644 --- a/src/GraphicsSystem/BoolOperateUtils.ts +++ b/src/GraphicsSystem/BoolOperateUtils.ts @@ -12,21 +12,23 @@ export enum BoolOpeartionType Subtract = 2 } +const fuzz = 1e-3; +let fuzzV3 = new Vector3(fuzz, fuzz, fuzz); + //判断曲线是否在源封闭曲线内 export function isTargetCurInOrOnSourceCur(sourceCur: Polyline | Circle | Ellipse, targetCur: Curve) { - let pts = []; - getIntPtContextPts(sourceCur, targetCur, pts); + if (!sourceCur.BoundingBox.expandByVector(fuzzV3).containsBox(targetCur.BoundingBox)) + return false; + + let pts = getIntPtContextPts(sourceCur, targetCur); if (pts.length <= 1) - { pts.push(targetCur.StartPoint, targetCur.EndPoint); - } - return IsPtsAllInOrOnReg(sourceCur, pts); } //获取交点处上下距0.01par的点 -function getIntPtContextPts(sourceCur: Curve, cu: Curve, pts: Vector3[]) +function getIntPtContextPts(sourceCur: Curve, cu: Curve, pts: Vector3[] = []) { let interPts = cu.IntersectWith(sourceCur, IntersectOption.OnBothOperands); if (interPts.length > 0) @@ -41,6 +43,7 @@ function getIntPtContextPts(sourceCur: Curve, cu: Curve, pts: Vector3[]) pts.push(cu.GetPointAtParam(par + 0.01)); } } + return pts; } //判断点点是否全部都在封闭区域内或者在曲线上 function IsPtsAllInOrOnReg(sourceReg: Polyline | Circle | Ellipse, pts: Vector3[])