From a661b57c2e47d4a7a7d6536c9a12c3f15c96972a Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Mon, 28 Sep 2020 11:02:37 +0800 Subject: [PATCH] =?UTF-8?q?!1234=20=E4=BF=AE=E5=A4=8D:=E5=88=87=E5=89=B2?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Booloperate/__snapshots__/bool5.test.ts.snap | 2 ++ .../Booloperate/__snapshots__/union.test.ts.snap | 2 +- __test__/Booloperate/bool5.test.ts | 13 +++++++++++++ src/DatabaseServices/Contour.ts | 10 ++++++---- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/__test__/Booloperate/__snapshots__/bool5.test.ts.snap b/__test__/Booloperate/__snapshots__/bool5.test.ts.snap index 54a14ceb7..a474aace4 100644 --- a/__test__/Booloperate/__snapshots__/bool5.test.ts.snap +++ b/__test__/Booloperate/__snapshots__/bool5.test.ts.snap @@ -2,6 +2,8 @@ exports[`差集共线(圆) 1`] = `442426.78778792813`; +exports[`差集错误 1`] = `1216051.1666666665`; + exports[`差集问题 1`] = `546438.8158863322`; exports[`弧形板差集 1`] = `165548.3611026407`; diff --git a/__test__/Booloperate/__snapshots__/union.test.ts.snap b/__test__/Booloperate/__snapshots__/union.test.ts.snap index 1b61a7246..8eae15731 100644 --- a/__test__/Booloperate/__snapshots__/union.test.ts.snap +++ b/__test__/Booloperate/__snapshots__/union.test.ts.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`并集错误,错误的曲线包含 1`] = `"20000.00000"`; +exports[`并集错误,错误的曲线包含 1`] = `"20000.00500"`; diff --git a/__test__/Booloperate/bool5.test.ts b/__test__/Booloperate/bool5.test.ts index 73d1e9aea..9788c59e0 100644 --- a/__test__/Booloperate/bool5.test.ts +++ b/__test__/Booloperate/bool5.test.ts @@ -44,3 +44,16 @@ test("弧形板差集2", () => for (let s of regs[0].ShapeManager.ShapeList) expect(s.Area).toMatchSnapshot(); }); + +test("差集错误", () => +{ + let d = { "file": [2, "Region", 8, 2, 104, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 3556.345601907233, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 3556.345601907233, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 3556.345601907233, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2485.841337666032, 1254.3456019072328, 0, 1], 0, 2, 6, [482, -2302], 0, [481.9999999999991, -1476], 0, [564, -1476.0000000000002], 0, [564, 0], 0, [0, 0], 0, [0, -2302], 0, true, 0, "Region", 8, 2, 105, false, 1, 7, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 0, true, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 1, 1, 1, 1, "Polyline", 8, 2, 0, false, 0, 3, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 0, true, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2967.841337666032, 1254.3489352405668, 0, 1], 0, 2, 4, [0, 0], 0, [808, 0], 0, [808, 18], 0, [0, 18], 0, true, 0], "basePt": { "x": 2485.841337666032, "y": 1254.3456019072328, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + + let regs = LoadRegionsFromFileData(d); + + regs[0].BooleanOper(regs[1], BoolOpeartionType.Subtract); + expect(regs[0].ShapeManager.ShapeList.length).toBe(1); + for (let s of regs[0].ShapeManager.ShapeList) + expect(s.Area).toMatchSnapshot(); + +}); diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index 11555a9c2..31edab5d3 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -16,6 +16,8 @@ import { IntersectBox2 } from "../Geometry/Box"; let cache = new WeakMap(); +const COMBINE_FUZZ = 1e-2; + export class Contour { private _Curve: Polyline | Circle; @@ -43,7 +45,7 @@ export class Contour return; } - let closeCurve = Contour.Combine(cus, needLink, 1e-2) as Polyline | Circle; + let closeCurve = Contour.Combine(cus, needLink, COMBINE_FUZZ) as Polyline | Circle; if (closeCurve && closeCurve.IsClose) { if (closeCurve instanceof Polyline && closeCurve.CloseMark === false) @@ -218,7 +220,7 @@ export class Contour let targetOutline = target.Curve; let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3); - let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands); + let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands, COMBINE_FUZZ); let sourceContainerTarget = this.CuInOutline(targetOutline); let targetContainerSource = target.CuInOutline(sourceOutline); @@ -301,7 +303,7 @@ export class Contour let isEqualNormal = equalv3(sourceOutline.Normal, targetOutline.Normal, 1e-3); - let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands, 1e-3); + let interPts = sourceOutline.IntersectWith2(targetOutline, IntersectOption.OnBothOperands, COMBINE_FUZZ); if (interPts.length <= 1) { @@ -409,7 +411,7 @@ export class Contour if (!IntersectBox2(outBox, targetOutline.BoundingBox)) continue; - let pts = sourceOutline.IntersectWith2(con.Curve, IntersectOption.OnBothOperands, 1e-3); + let pts = sourceOutline.IntersectWith2(con.Curve, IntersectOption.OnBothOperands, COMBINE_FUZZ); if (pts.length <= 1) { //反包含