From f1ef48dd8012f6a68f2c2392b825a8e7f6455c18 Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 24 Aug 2022 17:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=E5=9C=A8=E5=B8=83=E5=B0=94?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E7=BB=93=E6=9E=9C=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=9D=A2=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Booloperate/__snapshots__/union.test.ts.snap | 2 +- .../__snapshots__/FeedingToolPath.test.ts.snap | 2 +- __test__/Interfere/__snapshots__/intf.test.ts.snap | 4 +--- __test__/Interfere/intf.test.ts | 3 ++- __test__/Polyline/__snapshots__/offset.test.ts.snap | 2 +- src/Add-on/BoolOperation.ts | 4 ++++ src/DatabaseServices/Contour.ts | 5 +---- src/Geometry/GeUtils.ts | 5 +++-- src/GraphicsSystem/IntersectWith.ts | 7 ++++++- 9 files changed, 20 insertions(+), 14 deletions(-) diff --git a/__test__/Booloperate/__snapshots__/union.test.ts.snap b/__test__/Booloperate/__snapshots__/union.test.ts.snap index 8eae15731..a8f14af85 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.00500"`; +exports[`并集错误,错误的曲线包含 1`] = `"20000.01000"`; diff --git a/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap b/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap index b7a447b3b..c542ce8cf 100644 --- a/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap +++ b/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap @@ -182,7 +182,7 @@ exports[`精度不一致导致的错误: 走刀数量 1`] = `4`; exports[`超级复杂造型01 1`] = `"23338.03269"`; -exports[`超级复杂造型01 2`] = `"11855.39980"`; +exports[`超级复杂造型01 2`] = `"11855.39981"`; exports[`超级复杂造型01 3`] = `"9.89484"`; diff --git a/__test__/Interfere/__snapshots__/intf.test.ts.snap b/__test__/Interfere/__snapshots__/intf.test.ts.snap index 620dcdd20..62a93f78c 100644 --- a/__test__/Interfere/__snapshots__/intf.test.ts.snap +++ b/__test__/Interfere/__snapshots__/intf.test.ts.snap @@ -2,10 +2,8 @@ exports[`求交集错误 1`] = `2`; -exports[`求交集错误 2`] = `1`; +exports[`求交集错误 2`] = `0`; exports[`求交集错误 3`] = `"7704.00000"`; exports[`求交集错误 4`] = `"5771.53229"`; - -exports[`求交集错误 5`] = `"0.00000"`; diff --git a/__test__/Interfere/intf.test.ts b/__test__/Interfere/intf.test.ts index d3026bade..e42f9e9f0 100644 --- a/__test__/Interfere/intf.test.ts +++ b/__test__/Interfere/intf.test.ts @@ -5,7 +5,8 @@ import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; test('求交集错误', () => { - let d = [2, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [9.094947017729282e-12, -1411.0000000000002], 0, [9.094947017729282e-12, 2423], 0, [-17.999999999990905, 2423], 0, [-17.999999999990905, -1411.0000000000002], 0, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 2, 8, [540, 0], 0, [540, 102], 0, [552, 102], 0, [561, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [0, 0], 0, true]; + let d = + [2, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [9.094947017729282e-12, -1411.0000000000002], 0, [9.094947017729282e-12, 2423], 0, [-17.999999999990905, 2423], 0, [-17.999999999990905, -1411.0000000000002], 0, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.5140442132778844, 0, 0, 1], 0, 2, 8, [540, 0], 0, [540, 102], 0, [552, 102], 0, [561, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [-0.5140442132778844, 2329], 0, [0, 0], 0, true]; let pls = LoadEntityFromFileData(d) as Polyline[]; diff --git a/__test__/Polyline/__snapshots__/offset.test.ts.snap b/__test__/Polyline/__snapshots__/offset.test.ts.snap index 0cb1f1a45..fe16dcc6e 100644 --- a/__test__/Polyline/__snapshots__/offset.test.ts.snap +++ b/__test__/Polyline/__snapshots__/offset.test.ts.snap @@ -184,7 +184,7 @@ exports[`简单图形因为点在线内算法错误导致的丢失 3`] = `7.1494 exports[`简单图形因为点在线内算法错误导致的丢失 4`] = `6.693604273021893`; -exports[`精度过高导致无法连接 1`] = `"6723.54630"`; +exports[`精度过高导致无法连接 1`] = `"6723.54634"`; exports[`精度过高导致的曲线丢失 1`] = `1`; diff --git a/src/Add-on/BoolOperation.ts b/src/Add-on/BoolOperation.ts index 07a34d8f9..d5529aa36 100644 --- a/src/Add-on/BoolOperation.ts +++ b/src/Add-on/BoolOperation.ts @@ -13,6 +13,10 @@ function RegionsBoolOperate(regs: Region[], boolType: BoolOpeartionType): Region firstReg.BooleanOper(regs[i], boolType); regs[i].Erase(); } + + if (firstReg.ShapeManager.ShapeCount === 0) + firstReg.Erase(); + return firstReg; } diff --git a/src/DatabaseServices/Contour.ts b/src/DatabaseServices/Contour.ts index a4e0a8fd2..3369df863 100644 --- a/src/DatabaseServices/Contour.ts +++ b/src/DatabaseServices/Contour.ts @@ -6,7 +6,7 @@ import { FixIndex } from "../Common/Utils"; import { IntersectBox2 } from "../Geometry/Box"; import { CreateContour2 } from "../Geometry/CreateContour2"; import { Route } from "../Geometry/CurveMap"; -import { ComparePointFnGenerate, equaln, equalv2, equalv3 } from "../Geometry/GeUtils"; +import { equaln, equalv2, equalv3 } from "../Geometry/GeUtils"; import { RegionParse } from "../Geometry/RegionParse"; import { isTargetCurInOrOnSourceCur } from "../GraphicsSystem/BoolOperateUtils"; import { IntersectOption } from "../GraphicsSystem/IntersectWith"; @@ -451,9 +451,6 @@ export class Contour } else { - let fn = ComparePointFnGenerate("xyz", 1e-4); - pts.sort((p1, p2) => fn(p1.pt, p2.pt)); - arrayRemoveDuplicateBySort(pts, (p1, p2) => equalv2(p1.pt, p2.pt, 1e-4)); intPars.push(...pts.map(r => r.thisParam)); curveIntParamsMap.set(targetOutline, pts.map(r => r.argParam)); } diff --git a/src/Geometry/GeUtils.ts b/src/Geometry/GeUtils.ts index 473c80618..df3046321 100644 --- a/src/Geometry/GeUtils.ts +++ b/src/Geometry/GeUtils.ts @@ -337,8 +337,9 @@ const comparePointCache: Map = new Map(); */ export function ComparePointFnGenerate(sortKey: string, fuzz = 1e-8): compareVectorFn { - if (comparePointCache.has(sortKey)) - return comparePointCache.get(sortKey); + let cacheKey = `${sortKey}${fuzz}`; + if (comparePointCache.has(cacheKey)) + return comparePointCache.get(cacheKey); let sortIndex = []; diff --git a/src/GraphicsSystem/IntersectWith.ts b/src/GraphicsSystem/IntersectWith.ts index c6cd7a104..17294e99e 100644 --- a/src/GraphicsSystem/IntersectWith.ts +++ b/src/GraphicsSystem/IntersectWith.ts @@ -6,7 +6,7 @@ import { Curve } from '../DatabaseServices/Entity/Curve'; import { Ellipse } from '../DatabaseServices/Entity/Ellipse'; import { Line } from '../DatabaseServices/Entity/Line'; import { Polyline } from '../DatabaseServices/Entity/Polyline'; -import { ComparePointFnGenerate, equaln, equalv3 } from '../Geometry/GeUtils'; +import { ComparePointFnGenerate, equaln, equalv2, equalv3 } from '../Geometry/GeUtils'; /** * 相交延伸选项. @@ -456,6 +456,11 @@ export function IntersectPolylineAndCurve(pl: Polyline, cu: Curve, extType: Inte })); } } + + let fn = ComparePointFnGenerate("xyz", tolerance); + intRes.sort((p1, p2) => fn(p1.pt, p2.pt)); + arrayRemoveDuplicateBySort(intRes, (p1, p2) => equalv2(p1.pt, p2.pt, tolerance)); + return intRes; }