diff --git a/__test__/Polyline/__snapshots__/offset.test.ts.snap b/__test__/Polyline/__snapshots__/offset.test.ts.snap index 2de156250..9f6979c65 100644 --- a/__test__/Polyline/__snapshots__/offset.test.ts.snap +++ b/__test__/Polyline/__snapshots__/offset.test.ts.snap @@ -100,11 +100,11 @@ exports[`圆求交错误导致的线丢失 7`] = `3783.7486256305697`; exports[`圆求交错误导致的线丢失 8`] = `4972.0124797019525`; -exports[`圆求交错误导致的线丢失 9`] = `1148.6626298786346`; +exports[`圆求交错误导致的线丢失 9`] = `1148.6626297216462`; exports[`圆求交错误导致的线丢失 10`] = `5979.881805331884`; -exports[`圆求交错误导致的线丢失 11`] = `1049.9590630920934`; +exports[`圆求交错误导致的线丢失 11`] = `1049.9590628756293`; exports[`圆求交错误导致的线丢失 12`] = `6051.226636287796`; @@ -138,11 +138,11 @@ exports[`多段线因为合并问题造成的错误 2`] = `"2210.38330"`; exports[`多段线存在0长度线段导致偏移错误 1`] = `1`; -exports[`多段线存在0长度线段导致偏移错误 2`] = `"81933.70549"`; +exports[`多段线存在0长度线段导致偏移错误 2`] = `"81933.70529"`; exports[`多段线存在0长度线段导致偏移错误 3`] = `1`; -exports[`多段线存在0长度线段导致偏移错误 4`] = `"86144.16549"`; +exports[`多段线存在0长度线段导致偏移错误 4`] = `"86144.16525"`; exports[`拱门偏移 1`] = `1`; @@ -196,15 +196,15 @@ exports[`精度过高导致的曲线丢失 4`] = `"97661.61008"`; exports[`精度过高导致直连失败 1`] = `1`; -exports[`精度过高导致直连失败 2`] = `"32040.01360"`; +exports[`精度过高导致直连失败 2`] = `"32040.01359"`; exports[`精度过高导致直连失败 3`] = `1`; -exports[`精度过高导致直连失败 4`] = `"32045.24888"`; +exports[`精度过高导致直连失败 4`] = `"32045.24886"`; exports[`精度过高导致连接失败 1`] = `1`; -exports[`精度过高导致连接失败 2`] = `"75154.17849"`; +exports[`精度过高导致连接失败 2`] = `"75154.17758"`; exports[`精度过高导致连接失败 3`] = `1`; @@ -224,9 +224,9 @@ exports[`纯圆生成的多段线偏移 3`] = `1`; exports[`纯圆生成的多段线偏移 4`] = `"6328.57819"`; -exports[`补充bug测试 1`] = `7385.123391644352`; +exports[`补充bug测试 1`] = `7385.123350427525`; -exports[`补充bug测试 2`] = `7455.861403941375`; +exports[`补充bug测试 2`] = `7455.861373926681`; exports[`补圆弧测试 补圆弧测试1 1`] = `1`; @@ -340,12 +340,12 @@ exports[`连续丢圆弧后无法连接 9`] = `"574.66475"`; exports[`连续丢圆弧后无法连接 10`] = `"574.66475"`; -exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 1`] = `54789.24964851236`; +exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 1`] = `54789.24964823925`; -exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 2`] = `54907.28173780605`; +exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 2`] = `54907.28173753294`; -exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 3`] = `55497.50212266887`; +exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 3`] = `55497.50212239587`; -exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 4`] = `56678.241066044844`; +exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 4`] = `56678.240674867484`; -exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 5`] = `57859.37443960543`; +exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 5`] = `57859.37404922667`; diff --git a/__test__/Polyline/__snapshots__/offset3.test.ts.snap b/__test__/Polyline/__snapshots__/offset3.test.ts.snap index 05b5ac47e..5721f151f 100644 --- a/__test__/Polyline/__snapshots__/offset3.test.ts.snap +++ b/__test__/Polyline/__snapshots__/offset3.test.ts.snap @@ -2,4 +2,8 @@ exports[`圆弧被压扁时 1`] = `1`; -exports[`圆弧被压扁时 2`] = `"1260.08305"`; +exports[`圆弧被压扁时 2`] = `"1260.08301"`; + +exports[`圆弧被压扁时2 1`] = `1`; + +exports[`圆弧被压扁时2 2`] = `"2922.62557"`; diff --git a/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap b/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap index 5ad26c9a4..34b95a9c0 100644 --- a/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap +++ b/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap @@ -8,7 +8,7 @@ exports[`补充bug测试#IKWGF 3`] = `1.1376403544773557`; exports[`补充bug测试#IKWGF 4`] = `12.786911814880932`; -exports[`补充bug测试#IKWGF 5`] = `10.586573062117633`; +exports[`补充bug测试#IKWGF 5`] = `10.586692094955232`; exports[`补充bug测试#IKWGF 6`] = `0.624693344084014`; diff --git a/__test__/Polyline/offset3.test.ts b/__test__/Polyline/offset3.test.ts index 7d384d99e..7a8287493 100644 --- a/__test__/Polyline/offset3.test.ts +++ b/__test__/Polyline/offset3.test.ts @@ -34,3 +34,13 @@ test('圆弧被压扁时', () => testOffset(pl, -1); }); + +//会产生一个全圆,和上面的结果差不多 +test('圆弧被压扁时2', () => +{ + let pl = loadFile( + { "file": [1, "Polyline", 8, 2, 119, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1154.2238497367207, 104.14208322448218, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1154.2238497367207, 104.14208322448218, 0, 1], 0, 2, 60, [612.3014131291516, 516.3528702447977], 0.015806718902080345, [620.7943305625928, 607.0727250842237], 0.015085580217079377, [623.5388275982333, 693.9909315240145], 0.018559911555977058, [619.7184915236674, 800.899678859206], 0.014694123780868687, [611.0748359644397, 885.1634608721657], 0, [610.5937664221115, 885.5638696907919], 0.048351140222397095, [591.8736546167333, 974.856452029918], 0, [589.108411721164, 976.3352094794792], 0.12312867730767327, [549.49737942662, 1070.8379195719986], 0.17558566194791864, [493.1989814833556, 1105.1070499123898], 0, [493.1989814768517, 1106.8145087542505], 0.016687098951025527, [486.7752303851114, 1106.1799845700543], 0.016686934361763963, [480.3515429184599, 1106.814499939058], 0, [480.3515429184599, 1105.1070579994375], 0.1738513267498107, [424.462475564043, 1071.3443793295373], 0.14452030487651513, [385.51999664149616, 987.8692829759501], 0, [381.82742116645204, 985.894619916155], 0.05688790122446251, [362.1606942638914, 899.9341132066843], 0.06913430034215114, [358.36535846878064, 891.585241437522], 0.011951758276873363, [349.5455822495776, 813.8344631655293], 0.016079714858141424, [343.5599042095864, 708.741352103413], 0.012454880979067107, [343.57381445093506, 627.19890258108], 0.0353850507118894, [348.29886924626226, 547.5274109585339], 0, [347.91466794653746, 547.093379771549], 0.07426058357128477, [361.42189294407046, 461.28835523391433], 0, [360.0426715873188, 459.9156011573379], -0.06548790279458117, [360.2851152549719, 357.8786506661694], -0.04227753631212227, [346.33055464305374, 293.3324195844309], -0.056172333674162495, [311.43200724979914, 212.96070379493364], 0, [310.93871631800266, 212.88779827664194], -0.00793399669319285, [307.68508259066056, 206.58515476883855], -0.005919522217160536, [302.8230350758758, 198.70136235145944], 0, [303.28820964677647, 198.77011229634067], -0.07174730482095937, [263.3699447771607, 148.97924018587022], 0, [262.7596522831348, 149.10538038282925], -0.14255049355605404, [182.21024773410883, 113.61003285764781], -0.14077658798903714, [87.93677094888172, 136.03287484008467], 0, [88.19488827221956, 135.1956938030656], -0.04513801259751311, [45.780586931621485, 162.3898499135038], 0.39782128974410047, [-2.044548087593359, 147.4569370104155], 0, [-0.7859749528631816, 146.03276259253875], 0.2472291990501607, [-14.776371068260916, 124.25265858503285], 0.20695219839929455, [1.4915436378485722, 75.92120642684569], 0.013652847267144727, [12.194646194062642, 64.9005592146319], 0.11991101226154251, [126.7108106504181, -2.8175183289565666], 0.06970856590582382, [203.83456674596607, -14.959526923127044], 0.08482062762366688, [297.5168107124458, -0.5828301821931063], 0.08326244171921664, [379.7311114468818, 43.0216754773393], 0, [379.91321780220164, 40.48338437162393], 0.02592982720348706, [445.5507141763875, 108.87936972502882], 0, [445.5627415862375, 108.83630788084449], 0.0027506827909016085, [450.4676088733669, 114.61323114391712], 0.0021728799018758123, [455.5907752184968, 120.69112944801714], 0, [455.5706646369793, 120.76313155754232], 0.032323516875440585, [507.4200586291239, 193.05207203810642], 0.03636742975664602, [554.0598955470364, 281.58061383017815], 0.022695347458021323, [576.4724738949936, 339.9187895342726], 0, [577.3097360534697, 338.5946377731411], 0.02676041600254321, [600.1759496398608, 437.5240861303753], 0.01676422580319205, [614.3076343013773, 533.1181808392147], 0, false], "basePt": { "x": 1139.2238497367207, "y": 89.14208311646485, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] } + )[0] as Polyline; + + testOffset(pl, -15); +}); diff --git a/__test__/Sweep/__snapshots__/SweepSegs.test.ts.snap b/__test__/Sweep/__snapshots__/SweepSegs.test.ts.snap index de30a3245..c7541acaf 100644 --- a/__test__/Sweep/__snapshots__/SweepSegs.test.ts.snap +++ b/__test__/Sweep/__snapshots__/SweepSegs.test.ts.snap @@ -14,9 +14,9 @@ exports[`顶线分段测试 不闭合多补圆弧 6`] = `174.8880833875115`; exports[`顶线分段测试 不闭合多补圆弧 7`] = `9850.281806459632`; -exports[`顶线分段测试 不闭合多补圆弧 8`] = `167.51636096659317`; +exports[`顶线分段测试 不闭合多补圆弧 8`] = `167.51629993144502`; -exports[`顶线分段测试 不闭合多补圆弧 9`] = `9201.576517258296`; +exports[`顶线分段测试 不闭合多补圆弧 9`] = `9201.576579214025`; exports[`顶线分段测试 不闭合多补圆弧 10`] = `8466.391158009817`; @@ -62,7 +62,7 @@ exports[`顶线分段测试 不闭合直线圆弧2 5`] = `7158.345287787591`; exports[`顶线分段测试 不闭合直线圆弧2 6`] = `11250.987271676091`; -exports[`顶线分段测试 闭合圆弧 1`] = `183.06306067445354`; +exports[`顶线分段测试 闭合圆弧 1`] = `183.06301751608063`; exports[`顶线分段测试 闭合圆弧 2`] = `5822.513453880229`; @@ -70,15 +70,15 @@ exports[`顶线分段测试 闭合圆弧 3`] = `6427.17494400804`; exports[`顶线分段测试 闭合圆弧 4`] = `9954.439545178488`; -exports[`顶线分段测试 闭合圆弧 5`] = `5190.973862843558`; +exports[`顶线分段测试 闭合圆弧 5`] = `5190.973862843303`; -exports[`顶线分段测试 闭合圆弧 6`] = `7730.5776753028`; +exports[`顶线分段测试 闭合圆弧 6`] = `7730.577920416527`; exports[`顶线分段测试 闭合圆弧 7`] = `14243.520190228804`; -exports[`顶线分段测试 闭合圆弧 8`] = `11360.44019007804`; +exports[`顶线分段测试 闭合圆弧 8`] = `11360.440613921199`; -exports[`顶线分段测试 闭合圆弧 9`] = `4713.854133052737`; +exports[`顶线分段测试 闭合圆弧 9`] = `4713.8541762109`; exports[`顶线分段测试 闭合直线 1`] = `2152.655017660556`; diff --git a/src/DatabaseServices/Entity/Arc.ts b/src/DatabaseServices/Entity/Arc.ts index 304771f90..472f68e1f 100644 --- a/src/DatabaseServices/Entity/Arc.ts +++ b/src/DatabaseServices/Entity/Arc.ts @@ -355,6 +355,9 @@ export class Arc extends Curve { if (cu instanceof Arc) { + //非常小的圆弧直接结束 + if (cu.AllAngle < 5e-6) return Status.False; + if (equalv3(cu.Center, this.Center) && equaln(cu._Radius, this._Radius)) { this.WriteAllObjectRecord(); diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index 4a4987e8b..f787208d7 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -75,7 +75,7 @@ class CurveTreeNode for (let c of cus) { let p = c.GetPointAtParam(0.5); - if (c.Length > 1e-5 && (!contour.Curve.PtInCurve(p) || contour.Curve.PtOnCurve(p))) + if (CurveIsFine(c) && (!contour.Curve.PtInCurve(p) || contour.Curve.PtOnCurve(p))) this.children.push(new CurveTreeNode(c)); } if (this.children.length === cus.length) @@ -542,7 +542,7 @@ export class OffsetPolyline for (let d of this._SubOffsetedCurves) { let c = d.curve; - if (c.Length > 1e-5) + if (CurveIsFine(c)) this._CurveTreeNodes.push(new CurveTreeNode(c)); if (d.paddingCurve) this._CurveTreeNodes.push(...d.paddingCurve.map(c => new CurveTreeNode(c))); @@ -669,8 +669,11 @@ export class OffsetPolyline while (ss && !pl.IsClose) ss = searchNext(ss, pl); - if (pl.NumberOfVertices > 0) + if (pl.NumberOfVertices > 1) { + //避免0长度的线 + if (pl.NumberOfVertices === 2 && pl.Length < 1e-6) continue; + let d = pl.LineData; let ld = arrayLast(d); if (equalv2(d[0].pt, ld.pt, 1e-2)) @@ -793,3 +796,10 @@ function EntityEncode2(c1: Curve, c2: Curve) { return EntityEncode(c1) & EntityEncode(c2); } + +//表示这个是一个正常的曲线,不是0长度的线,也不是0长度的圆弧 +function CurveIsFine(curve: Curve) +{ + if (curve instanceof Arc && curve.AllAngle < 2e-6) return false; + return curve.Length > 5e-5; +}