diff --git a/__test__/Polyline/PtInPolylineDir.test.ts b/__test__/Polyline/PtInPolylineDir.test.ts index 92652a256..d89ac619d 100644 --- a/__test__/Polyline/PtInPolylineDir.test.ts +++ b/__test__/Polyline/PtInPolylineDir.test.ts @@ -194,4 +194,11 @@ test('点在圆弧的弦中心上', () => let pt = new Vector3().fromArray([4.999999999999999, 2.5, 0]); let isR = GetPointAtCurveDir(pl, pt); expect(isR).toBeFalsy(); + + pt = new Vector3().fromArray([5, 9.5, 0]); + isR = GetPointAtCurveDir(pl, pt); + expect(isR).toBeTruthy(); + pt = new Vector3().fromArray([5, 5.5, 0]); + isR = GetPointAtCurveDir(pl, pt); + expect(isR).toBeTruthy(); }); diff --git a/__test__/Polyline/offset.test.ts b/__test__/Polyline/offset.test.ts index e4c8e4fc0..c31e81eac 100644 --- a/__test__/Polyline/offset.test.ts +++ b/__test__/Polyline/offset.test.ts @@ -32,6 +32,7 @@ test('IKKGK圆与直线补圆弧', () => expect(f.Data).toMatchSnapshot(); + //圆丢失的问题 cus = pl.GetOffsetCurves(-1.926388985025112); expect(cus.length).toBe(2); diff --git a/src/Add-on/test.ts b/src/Add-on/test.ts index a94b5d252..17604e6b6 100644 --- a/src/Add-on/test.ts +++ b/src/Add-on/test.ts @@ -37,7 +37,7 @@ export class Test implements Command } //将多段线转换为cad图形 - async exec() + async exec4() { // let d = [["Polyline", 1, 1, 12839, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 24, [256.5228611988947, -38.705370748164505], 0, [372.1955588024039, 31.844231195771492], 0, [372.1955588024039, -31.54297461172431], 0, [450.9819163032461, 37.57414810492366], 0, [423.0485713711294, -54.10452244151095], 0, [589.216161736542, 52.97329979827009], 0, [611.0614699526845, -2.177150452319474], 0, [672.6580767260702, 61.21005535517633], 0, [678.0298738284004, 13.938240854670997], 0, [735.329042919922, 21.100636991111184], 0, [684.1179105443746, -21.515620020708024], 0, [730.6734854312358, -32.61733403219032], 0, [815.1897598412304, 38.29038771856768], 0, [835.6025888300849, -8.981426781937659], 0, [862.1034545349137, 74.4604882075907], 0, [943.4539498526012, 74.46048820759069], 0, [986.972668777612, -29.064785548515978], 0, [924.5022496755805, -66.26627108118637], 0, [1001.0109652050348, -106.27541589934134], 0, [965.9152241364777, -128.73669018321777], 0, [1006.6262837760039, -176.46689803645526], 0, [904.1467198558175, -189.8032796425069], 0, [981.3573502066429, -242.44689124534239], 0, [1004.5205393118904, -256.48518767276516], 0, false]] @@ -127,7 +127,7 @@ export class Test implements Command r2.ShapeManager.ShapeList.forEach(s => s.Explode().forEach(c => app.m_Database.ModelSpace.Append(c))); } - async exec4() + async exec() { let e = await app.m_Editor.GetEntity(); if (e.Status === PromptStatus.OK) @@ -136,10 +136,7 @@ export class Test implements Command if (e.Entity instanceof Polyline) { - console.log(GetPointAtCurveDir(e.Entity, new Vector3(2.5, 3.1699))); - console.log(GetPointAtCurveDir(e.Entity, new Vector3(5, 2.5))); - console.log(GetPointAtCurveDir(e.Entity, new Vector3(4.99999999999, 2.5))); - console.log(GetPointAtCurveDir(e.Entity, new Vector3(2.5, 2.5))); + console.log(GetPointAtCurveDir(e.Entity, new Vector3(5, 5.5))); this.drawPtDirTestCir(e.Entity); } return; @@ -161,7 +158,7 @@ export class Test implements Command { p.y += size.y; let c = new Circle(p, 0.1); - c.ColorIndex = GetPointAtCurveDir(pl, p) ? 1 : 2; + c.ColorIndex = GetPointAtCurveDir(pl, p) ? 3 : 1; app.m_Database.ModelSpace.Append(c); } } diff --git a/src/GraphicsSystem/OffestPolyline.ts b/src/GraphicsSystem/OffestPolyline.ts index c18f22d9a..740ca3042 100644 --- a/src/GraphicsSystem/OffestPolyline.ts +++ b/src/GraphicsSystem/OffestPolyline.ts @@ -90,8 +90,11 @@ export class PolyOffestUtil //与源线段自交 if (c.IntersectWith(this.m_Polyline, IntersectOption.OnBothOperands).length !== 0) return false; - return (this.CheckPointDist(c.StartPoint) && this.CheckPointDist(c.EndPoint)) - && (this.CheckPointDir(c.StartPoint) || this.CheckPointDir(c.EndPoint)); + //删除在反方向的无效线段 + return this.CheckPointDir(c.StartPoint); + // return this.CheckPointDist(c.StartPoint) && this.CheckPointDist(c.EndPoint) + // return (this.CheckPointDist(c.StartPoint) && this.CheckPointDist(c.EndPoint)) + // && this.CheckPointDir(c.StartPoint); }); //处理自交的线段 @@ -235,8 +238,10 @@ export class PolyOffestUtil laterLine = offResList[FixIndex(i + 1, offResList)].curve; - //#region 1.中间丢失线段的情况下补圆弧. - if (FixIndex(startIndex + 1, this.m_Polyline.EndParam) !== endIndex) + //#region 1.中间丢失线段的情况下且没循环到尾部,补圆弧. + let isFillArc = FixIndex(startIndex + 1, this.m_Polyline.EndParam) !== endIndex; + + if (isFillArc && startIndex > endIndex) { this.fillArc(startIndex, endIndex, nextStartPt, frontLine, laterLine); continue; @@ -270,7 +275,7 @@ export class PolyOffestUtil let iPt = this.selectFitInterPt(tPts, frontLine.EndPoint); this.appendNewCuAndContour(frontLine, nextStartPt, iPt, startIndex); } - else if (iPts.length === 0)//连交点都没,补圆弧 + else if (isFillArc || iPts.length === 0)//连交点都没或者圆弧丢失补圆弧 { this.fillArc(startIndex, endIndex, nextStartPt, frontLine, laterLine); }