diff --git a/__test__/Polyline/offset3.test.ts b/__test__/Polyline/offset3.test.ts index 464074c2c..1d908d886 100644 --- a/__test__/Polyline/offset3.test.ts +++ b/__test__/Polyline/offset3.test.ts @@ -65,3 +65,11 @@ test('产生小圆弧', () => expect(pls.EndParam).toMatchNumberSnapshot(0); expect(pls.Length).toMatchNumberSnapshot(5); }); + +test('尖角化文档', () => +{ + let d = + { "file": [22, "Arc", 10, 2, 100, 0, 1, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 612.3489562292762, 1276.4192942638308, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 612.3489562292762, 1276.4192942638308, 0, 1], 0, 0, 1, 2, 554.3740810429213, 4.803124089117446, 0.9420313933899384, 1, "Arc", 10, 2, 101, 0, 1, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1089.9106782723047, 1884.098195143212, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1089.9106782723047, 1884.098195143212, 0, 1], 0, 0, 1, 2, 219.86303368944365, 3.9521362227289285, 3.5399764901601127, 1, "Arc", 10, 2, 102, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 948.7575615797596, 1864.132465288415, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 948.7575615797596, 1864.132465288415, 0, 1], 0, 0, 1, 2, 89.71470329728743, 3.9572085555536427, 5.210501558572323, 0, "Arc", 10, 2, 103, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4438.41124666784, 906.6293114291364, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4438.41124666784, 906.6293114291364, 0, 1], 0, 0, 1, 2, 3557.030126597525, 2.891979491156536, 3.1180853302614966, 0, "Arc", 10, 2, 104, 0, 1, 8, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 612.3489562292762, 1276.4192942638308, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 612.3489562292762, 1276.4192942638308, 0, 1], 0, 0, 1, 2, 584.3740810429213, 4.803124089117446, 0.9420313933899384, 1, "Arc", 10, 2, 105, 0, 1, 8, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1089.9106782723047, 1884.098195143212, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1089.9106782723047, 1884.098195143212, 0, 1], 0, 0, 1, 2, 249.86303368944365, 3.9521362227289285, 3.5399764901601127, 1, "Circle", 10, 2, 106, 0, 1, 6, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 851.3916442434202, 1809.66563499364, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, 1, 11.332807117935072, "Text", 10, 2, 107, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 546.2194097508764, 1730.1757045499514, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 546.2194097508764, 1730.1757045499514, 0, 1], 0, 0, 1, 1, "尖角化:\n红色为原曲线,灰色为偏移后的曲线.\n粉色的交点因为上方的圆弧反向延长,所以被舍弃,\n如果我们往蓝色交点延伸,那么就会造成偏移错误.", 10, 0, "songti", 10, "Line", 10, 2, 108, 0, 1, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, 1, [13182.39247370293, 114.85071877224863, 0], [13239.706035081284, 209.983432896864, 0], "Line", 10, 2, 109, 0, 1, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, 1, [13239.706035081284, 209.983432896864, 0], [13263.87910178508, 103.93384993827638, 0], "Line", 10, 2, 110, 0, 1, 8, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 727.5405524322869, 1532.4081902035846, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, 1, [-25.69686830347858, 15.481310002505523, 0], [31.6166930748757, 110.6140241271209, 0], "Line", 10, 2, 111, 0, 1, 8, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 784.8541138106411, 1627.5409043282, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, 1, [29.249754388332345, 6.667223426752164, 0], [53.42282109212783, -99.38235953183546, 0], "Text", 10, 2, 112, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 680.3640835426195, 1463.3979836459741, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 680.3640835426195, 1463.3979836459741, 0, 1], 0, 0, 1, 1, "尖角化:仅在这种情况下允许连接\n因为圆的特性,所以这个是对的.", 10, 0, "songti", 10, "Line", 10, 2, 113, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 912.7952244357875, 452.0364529636016, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 912.7952244357875, 452.0364529636016, 0, 1], 0, 0, 1, 1, [-23.347824191196196, 0, 0], [152.56897186214883, 0, 0], "Arc", 10, 2, 114, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 954.9354755510558, 180.52673133225449, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 954.9354755510558, 180.52673133225449, 0, 1], 0, 0, 1, 2, 279.2959307753637, 3.795173024083316, 1.8074754005306746, 1, "Arc", 10, 2, 115, 0, 1, 8, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 954.9354755510558, 180.52673133225449, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 954.9354755510558, 180.52673133225449, 0, 1], 0, 0, 1, 2, 269.2959307753637, 3.795173024083316, 1.8074754005306746, 1, "Line", 10, 2, 116, 0, 1, 8, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 889.4474002445913, 452.0364529636016, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 912.7952244357875, 452.0364529636016, 0, 1], 0, 0, 1, 1, [0, -10, 0], [175.91679605334502, -10, 0], "Arc", 10, 2, 117, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, 260.0651615445943, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, 260.0651615445943, 0, 1], 0, 0, 1, 2, 279.2959307753637, 4.71238898038469, 0.7599528605119648, 1, "Line", 10, 2, 118, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, -19.230769230769283, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, -19.230769230769283, 0, 1], 0, 0, 1, 1, [202.4528183026996, 471.69934371019394, 0], [355.0217901648484, 471.69934371019383, 0], "Arc", 10, 2, 119, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, 260.0651615445943, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, 260.0651615445943, 0, 1], 0, 0, 1, 2, 249.29593077536367, 4.71238898038469, 0.7599528605119648, 1, "Line", 10, 2, 120, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 426.5648025897699, 452.46857447942455, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 224.1119842870703, -19.230769230769283, 0, 1], 0, 0, 1, 1, [-2.2354513437568925e-14, -30, 0], [152.5689718621488, -30.000000000000114, 0], "Circle", 10, 2, 121, 0, 1, 5, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1073.9726927662487, 1634.7439968178157, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -12454.851921270643, 1417.557471431336, 0, 1], 0, 0, 1, 1, 17.719640253387112], "basePt": { "x": -55.18394648829337, "y": -19.230769230769397, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + loadFile(d.file); + expect(true).toBeTruthy(); +}); diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index 2ce54b796..ee2e8a2e1 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -327,7 +327,7 @@ export class OffsetPolyline tp = SelectNearP(tPts, refP); else //补圆弧 或者尝试连接 { - if (iPts.length > 0 && !this._ToolPath && this.IsSharpCorner(curveResNow, curveResNext, refP))//非加工刀路 并且尖角化时 + if (iPts.length > 0 && !this._ToolPath && this.IsSharpCorner(curveResNow, curveResNext))//非加工刀路 并且尖角化(谷)时 { //设置新的连接点,并且备份旧点 let oldp: Vector3; @@ -428,7 +428,15 @@ export class OffsetPolyline } } - private IsSharpCorner(curveResNow: IOffsetResult, curveResNext: IOffsetResult, refP: Vector3): boolean + /** + * 判断两曲线是否尖角化 + * 在 + * 1.直线和圆弧,圆弧和圆弧 + * 2.有交点,无真交点时 + * 必须在正确的方向做出延伸动作,所以必须在尖角的情况下延伸,偏移的结果就像一个谷字去掉一个口的结果,上面的人就是偏移后的结果. + * 如果是谷,则允许连接 #I7WKKG + */ + private IsSharpCorner(curveResNow: IOffsetResult, curveResNext: IOffsetResult): boolean { let v1 = this._SubCurves[curveResNow.index].GetFistDeriv(1); let v2 = this._SubCurves[curveResNext.index].GetFistDeriv(0);