From 91ab25be65c661baa9124d20146c696ab1e4acad Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Tue, 17 Mar 2020 16:17:28 +0800 Subject: [PATCH] =?UTF-8?q?!815=20=E4=BC=98=E5=8C=96:=E9=80=A0=E5=9E=8B?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E5=B0=8F=E4=BA=8E=E5=88=80=E5=8D=8A=E5=BE=84?= =?UTF-8?q?=E7=9A=84=E8=B5=B0=E5=88=80=E7=BB=93=E6=9E=9C=20fixes=20#I13LS1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FeedingToolPath/FeedingToolPath.test.ts | 2 +- .../FeedingToolPath.test.ts.snap | 46 +++++++++++-------- .../ToolPath/FeedingToolPath.ts | 11 +++-- .../ToolPath/OptimizeToolPath.ts | 20 ++++---- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/__test__/FeedingToolPath/FeedingToolPath.test.ts b/__test__/FeedingToolPath/FeedingToolPath.test.ts index 9515d8b52..55c3275e9 100644 --- a/__test__/FeedingToolPath/FeedingToolPath.test.ts +++ b/__test__/FeedingToolPath/FeedingToolPath.test.ts @@ -139,7 +139,7 @@ test("复杂造型01", () => let data = [1, "Board", 5, 2, 1702, false, 1, 2, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1335.7682619647353, 173.551637279597, 0, 1], 0, 0, 2, 1200, 600, 18, true, "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, [600, 0], 0, [600, 1200], 0, [0, 1200], 0, true, 1, 2, 1036.2015113350126, 440.4613267262604, 10, false, "Polyline", 5, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 361.54936893772503, 969.0075566750625, 0, 1], 0, 0, 2, 33, [0, 67.19395465995012], 0, [-310.0352644836272, 67.19395465995012], -0.5981144268442652, [-286.17264943072985, -164.2679339848869], 0.7207592200561973, [-277.08949795465924, -385.7570892090673], 0, [-237.96207621158624, -301.21391008564115], 0, [-211.41132574307244, -520.6069534307294], 0, [-274.2946821158684, -469.60156437279466], 0, [-351.85082164231676, -629.6047711435754], 0, [-232.3724445340044, -591.1760533602005], 0, [-183.46316735516308, -735.1090690579331], 0, [-155.51500896725372, -663.1425612090666], 0, [-171.58520004030163, -863.6705976423159], 0, [-257.52578708312274, -751.8779640906787], 0, [-257.52578708312274, -890.2213481108301], 0, [-310.0352644836272, -905.4214599899233], 0, [-310.0352644836272, -969.0075566750625], 0, [0, -969.0075566750625], 0, [0, -957.9240668043744], -0.9999999999999999, [0, -864.5645981830307], 0, [0, -843.3902891140606], -0.9999999999999999, [0, -700.891826754957], 0, [0, -684.906801007558], 0.9999999999999999, [0, -583.5264483627197], 0, [0, -579.9195144635983], 0.9999999999999999, [0, -422.09559888652757], 0, [0, -409.0723084849551], -0.9999999999999999, [0, -312.3785731271355], 0, [0, -301.4871765134408], 0.9999999999999999, [0, -243.13750862509778], 0, [0, -223.97984886649738], -1.2314232880459324, [0, -77.80352644836466], 0, [0, -58.23046517367129], 0.9999999999999999, [0, 58.230465173671746], 0, true, 5, 2, 20.05062061227784, 15.41391459568868, 10, false, "Polyline", 5, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 207.52578708312274, 919.0075566750625, 0, 1], 0, 0, 2, 3, [-207.52578708312274, -898.9569360627846], 0, [-207.52578708312274, -919.0075566750625], 0, [-192.11187248743406, -919.0075566750625], 0, true, 0, 3, 3, 0, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1203.380352644835, 439.26514490680165, 8, 1], 2, 114.03848323053074, 43.29850598181545, 10, false, "Polyline", 5, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 125.8595682183174, 146.86649874055365, 0, 1], 0, 0, 2, 4, [-125.85956821831739, -146.86649874055365], 0, [-96.36754317036441, -146.86649874055365], -0.15820638151829505, [-82.56106223650193, -88.79778749503191], -0.13776363653390294, [-116.72059569461629, -32.828015510022965], 0, true, 0, 3, 3, 0, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1203.380352644835, 520.931363771607, 8, 1], 2, 118.14017720514198, 67.669551962062, 10, false, "Polyline", 5, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 311.54936893772503, 313.09561944640836, 0, 1], 0, 0, 2, 3, [-264.0938145218924, -209.53632699236087], 0.5176782102931564, [-298.55626262432344, -313.0956194464084], 0, [-243.879816975663, -194.95544224126644], -0.03426656432289884, true, 0, 3, 3, 0, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 597.468415416181, 335.24156305219935, 8, 1], 2, 311.0762540509527, 138.91482988296556, 10, false, "Polyline", 5, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 110.00287209443024, 360.4181251057296, 0, 1], 0, 0, 2, 10, [-110.00287209443022, -360.4181251057296], -0.19710641679675492, [-42.513452087941566, -297.8639440751849], -0.25973952118910953, [-1.4337638048816683e-14, -274.1813602015127], 0.9999999999999999, [-2.0291827599733876e-14, -272.80100755667445], -0.41421356237309503, [-50.00000000000001, -222.80100755667445], 0, [-50.00000000000001, -219.19407365755296], -0.4142135623730949, [-2.6627322557224985e-14, -169.19407365755296], 0.9999999999999999, [-8.147194749383032e-15, -111.37015808048227], -0.25068130041493886, [-41.59378759840299, -89.11825410919994], -0.1533204796260371, [-85.07341619487701, -49.3418710547769], 0, true, 0, 3, 3, 0, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1005.5163618815475, 536.7880598954941, 8, 1], 2, 552.028541756849, 213.97641288072498, 10, false, "Polyline", 5, 2, 0, false, 0, 2, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 205.74594770705346, 534.8345870968991, 0, 1], 0, 0, 2, 9, [-28.565797815870887, 17.193954659949895], 0, [-193.0890787464058, 17.193954659949938], -0.24599915427853017, [-205.74594770705346, -151.24849135105575], 0, [-159.32470045118714, -534.8345870968991], 0, [-97.2910102382385, -375.09783479855645], -0.3264242677950859, [-43.25358703282456, -272.40084858481384], -0.805868213007247, [-40.3917540832408, -28.76003589144016], -0.23954788447860403, [-1.5119119245645884e-15, -8.230465173671519], 0.9999999999999999, [5.039706415215297e-16, 8.230465173671519], -0.15320924855818352, true, 0, 3, 3, 0, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 819.2073830666715, 441.0449842828709, 8, 1], 3, 0, 0, 0, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1253.380352644835, 285.24156305219935, 8, 1], 3, 3, 0, 0, 5, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1335.7682619647353, 173.551637279597, 0, 1], 0, "层板", "", "", "", "", "", 0, 0, "三合一", 2, 0, "1", "1", "1", "1", "", "", "", 4, "三合一", "三合一", "三合一", "三合一", true, true, 0, 0, 0, 0, 0]; let brs = LoadBoardsFromFileData(data); - testPathCount(brs[0], 19); + testPathCount(brs[0], 23); }); test("超级复杂造型01", () => diff --git a/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap b/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap index 12792be4b..5e2cfc181 100644 --- a/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap +++ b/__test__/FeedingToolPath/__snapshots__/FeedingToolPath.test.ts.snap @@ -64,43 +64,51 @@ exports[`复杂极限刀半径: 走刀数量 1`] = `5`; exports[`复杂造型01: 曲线长度 1`] = `3600`; -exports[`复杂造型01: 曲线长度 2`] = `59609.750635032455`; +exports[`复杂造型01: 曲线长度 2`] = `45851.27982948799`; -exports[`复杂造型01: 曲线长度 3`] = `1482.4552077856665`; +exports[`复杂造型01: 曲线长度 3`] = `9328.396540734857`; -exports[`复杂造型01: 曲线长度 4`] = `838.7907023816642`; +exports[`复杂造型01: 曲线长度 4`] = `4417.523956828297`; -exports[`复杂造型01: 曲线长度 5`] = `119.2450237058813`; +exports[`复杂造型01: 曲线长度 5`] = `1482.4552077856665`; -exports[`复杂造型01: 曲线长度 6`] = `920.6205527518313`; +exports[`复杂造型01: 曲线长度 6`] = `838.7907023816642`; -exports[`复杂造型01: 曲线长度 7`] = `136.38881122495832`; +exports[`复杂造型01: 曲线长度 7`] = `25.328937185896002`; -exports[`复杂造型01: 曲线长度 8`] = `40.76338989846492`; +exports[`复杂造型01: 曲线长度 8`] = `25.328939247232213`; -exports[`复杂造型01: 曲线长度 9`] = `3.2524680966497335`; +exports[`复杂造型01: 曲线长度 9`] = `676.6930479102875`; -exports[`复杂造型01: 曲线长度 10`] = `301.66992978702626`; +exports[`复杂造型01: 曲线长度 10`] = `227.6085817490802`; -exports[`复杂造型01: 曲线长度 11`] = `1749.8631881230117`; +exports[`复杂造型01: 曲线长度 11`] = `136.38881122495832`; -exports[`复杂造型01: 曲线长度 12`] = `7.8285491298056655`; +exports[`复杂造型01: 曲线长度 12`] = `40.76338989846492`; -exports[`复杂造型01: 曲线长度 13`] = `2.5692483033658107`; +exports[`复杂造型01: 曲线长度 13`] = `3.2524680966497335`; -exports[`复杂造型01: 曲线长度 14`] = `4316.136010511218`; +exports[`复杂造型01: 曲线长度 14`] = `301.66992978702626`; -exports[`复杂造型01: 曲线长度 15`] = `60.75516885168303`; +exports[`复杂造型01: 曲线长度 15`] = `1749.8631881230117`; -exports[`复杂造型01: 曲线长度 16`] = `270.97161059159566`; +exports[`复杂造型01: 曲线长度 16`] = `7.8285491298056655`; -exports[`复杂造型01: 曲线长度 17`] = `282.82481905047365`; +exports[`复杂造型01: 曲线长度 17`] = `2.5692483033658107`; -exports[`复杂造型01: 曲线长度 18`] = `819.9411466147131`; +exports[`复杂造型01: 曲线长度 18`] = `4316.136010511218`; -exports[`复杂造型01: 曲线长度 19`] = `1463.6056529693449`; +exports[`复杂造型01: 曲线长度 19`] = `60.75516885168303`; -exports[`复杂造型01: 走刀数量 1`] = `12`; +exports[`复杂造型01: 曲线长度 20`] = `270.97161059159566`; + +exports[`复杂造型01: 曲线长度 21`] = `282.82481905047365`; + +exports[`复杂造型01: 曲线长度 22`] = `819.9411466147131`; + +exports[`复杂造型01: 曲线长度 23`] = `1463.6056529693449`; + +exports[`复杂造型01: 走刀数量 1`] = `16`; exports[`复杂造型测试: 曲线长度 1`] = `2402.511185283596`; diff --git a/src/GraphicsSystem/ToolPath/FeedingToolPath.ts b/src/GraphicsSystem/ToolPath/FeedingToolPath.ts index 9bbb01e67..20600eba6 100644 --- a/src/GraphicsSystem/ToolPath/FeedingToolPath.ts +++ b/src/GraphicsSystem/ToolPath/FeedingToolPath.ts @@ -32,8 +32,9 @@ export class FeedingToolPath extends Singleton */ private HandleShape(shape: Shape, knifRadius: number, isOut = true): Curve[] { - let outline = shape.Outline.Curve.Clone(); - + let outline = shape.Outline.Curve; + if (isOut) + outline = outline.Clone(); let isBulge = (outline instanceof Polyline) && outline.IsBulge; let dir = GetCurveToInDir(outline); @@ -72,7 +73,9 @@ export class FeedingToolPath extends Singleton offsetDist += knifRadius; let retCus: Curve[] = []; - retCus.push(...GetOffsetCurves(outline, offsetDist * dir)); + + let tempOffsetCus = GetOffsetCurves(outline, offsetDist * dir); + retCus.push(...tempOffsetCus); //最后一次内偏移如果是凸多边形,需在偏移一个刀半径避免没切到中心 if (retCus.length === 0 && isBulge) @@ -110,6 +113,8 @@ export class FeedingToolPath extends Singleton shapeMg.BoolOper(holesMg, BoolOpeartionType.Subtract); for (let s of shapeMg.ShapeList) { + if (isOut && tempOffsetCus.length > 1) + s.Outline.Curve.TempData = { isOut: true }; s.Outline.Curve.ColorIndex = outline.ColorIndex; offsetCus.push(...this.HandleShape(s, knifRadius, false)); } diff --git a/src/GraphicsSystem/ToolPath/OptimizeToolPath.ts b/src/GraphicsSystem/ToolPath/OptimizeToolPath.ts index 0b4af2381..840075815 100644 --- a/src/GraphicsSystem/ToolPath/OptimizeToolPath.ts +++ b/src/GraphicsSystem/ToolPath/OptimizeToolPath.ts @@ -6,14 +6,14 @@ import { Curve } from "../../DatabaseServices/Entity/Curve"; import { Line } from "../../DatabaseServices/Entity/Line"; import { Polyline } from "../../DatabaseServices/Entity/Polyline"; import { Shape } from "../../DatabaseServices/Shape"; -import { AsVector2, AsVector3, comparePoint } from "../../Geometry/GeUtils"; +import { AsVector2, AsVector3, comparePoint, equalv3 } from "../../Geometry/GeUtils"; /** * 优化走刀路径,连接偏移后的曲线数组 - * @param offsetCus 偏移后的曲线组 + * @param offsetCus 偏移后的曲线组 * @param originShape 原始走刀形状 * @param rad 刀半径 - * @returns tool path + * @returns tool path */ export function OptimizeToolPath(offsetCus: Curve[], originShape: Shape, rad: number): Curve[] { @@ -93,10 +93,14 @@ export function OptimizeToolPath(offsetCus: Curve[], originShape: Shape, rad: nu for (let i = 1; i < plList.length; i++) { let ePt = firstPl.EndPoint; - - let refLine = new Line(ePt, plList[i].StartPoint); - - let isDisVail = cantIntCur.some(c => c.IntersectWith(refLine, 0).length > 1); + let isDisVail: boolean; + if (plList[i].TempData?.isOut && !equalv3(ePt, plList[i].StartPoint)) + isDisVail = true; + else + { + let refLine = new Line(ePt, plList[i].StartPoint); + isDisVail = cantIntCur.some(c => c.IntersectWith(refLine, 0).length > 1); + } if (isDisVail) { @@ -125,7 +129,7 @@ export function OptimizeToolPath(offsetCus: Curve[], originShape: Shape, rad: nu /** * 设定走刀路径起始点 * 为了统一刀路起点,最外轮廓左左点为起始点,其余轮廓以最接近最外轮廓起始点的点左起始点 -* @param plList +* @param plList */ function ChangePlListStartPt(plList: Polyline[]) {