diff --git a/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap b/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap new file mode 100644 index 000000000..89cfbec09 --- /dev/null +++ b/__test__/Polyline/__snapshots__/offsetbug.test.ts.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`补充bug测试#IKWGF 1`] = `1.1376402440608806`; + +exports[`补充bug测试#IKWGF 2`] = `0.44573816538516137`; + +exports[`补充bug测试#IKWGF 3`] = `10.733056812077686`; + +exports[`补充bug测试#IKWGF 4`] = `12.786755410504352`; + +exports[`补充bug测试#IKWGF 5`] = `0.6246933329215183`; + +exports[`补充bug测试#IKWGF 6`] = `10.586543051841131`; + +exports[`补充bug测试#IKWGF 7`] = `14.066950838248612`; + +exports[`补充bug测试#IKWGF 8`] = `2.16930889523746`; + +exports[`补充bug测试#IKWGF 9`] = `11.890848111457423`; + +exports[`补充bug测试#IKWGF 10`] = `1.0803373815793473`; + +exports[`补充bug测试#IKWGF 11`] = `0.3947454693903588`; + +exports[`补充bug测试#IKWGF 12`] = `10.698715561269278`; diff --git a/__test__/Polyline/offsetbug.test.ts b/__test__/Polyline/offsetbug.test.ts new file mode 100644 index 000000000..48fe4a19d --- /dev/null +++ b/__test__/Polyline/offsetbug.test.ts @@ -0,0 +1,62 @@ +import { Factory } from "../../src/DatabaseServices/CADFactory"; +import { CADFile } from "../../src/DatabaseServices/CADFile"; +import { Curve } from "../../src/DatabaseServices/Curve"; +import { Polyline } from "../../src/DatabaseServices/Polyline"; +Factory(Polyline); +function loadFile(data) +{ + let file = new CADFile(); + file.Data = data; + let cus: Curve[] = []; + let count = file.Read(); + for (let i = 0; i < count; i++) + { + cus.push(file.ReadObject(undefined) as Curve); + } + return cus; +} +test('补充bug测试#IKWGF', () => +{ + //https://gitee.com/BearCAD/WebThreeJs/issues/IKWGF + let data = + [1, ["Polyline", 1, 1, 28, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1.073087818696886, -6.460623229461753, 0, 1], 2, 13, [2.913294797687863, 5.657009425680781], -0.10216571300036134, [3.0668619767188887, 5.578034682080925], 0, [4.6094463694365295, 5.578034682080925], -2.632498680881094, [4.609446369436524, 3.627167630057804], 0, [2.4566473988439355, 3.627167630057804], 0, [2.4566473988439355, 3.627167630057804], 0, [2.4566473988439355, 4.990312071734102], -0.11795690250598688, [2.37813156168231, 5.1728323699421965], 0, [1.8884393063583844, 5.1728323699421965], 0, [1.8884393063583844, 5.1728323699421965], 0, [1.8884393063583844, 6.15606936416185], 0, [2.913294797687864, 6.15606936416185], 0, [2.913294797687864, 5.657009425680784], 0, false]]; + + let pl = loadFile(data)[0]; + + //situation 1 + let cus = pl.GetOffsetCurves(0.3743); + expect(cus.length).toBe(3); + expect(cus[0].Length).toMatchSnapshot(); + expect(cus[1].Length).toMatchSnapshot(); + expect(cus[2].Length).toMatchSnapshot(); + + //situation 2 + cus = pl.GetOffsetCurves(0.3602); + expect(cus.length).toBe(1); + expect(cus[0].Length).toMatchSnapshot(); + + //situation 3 + cus = pl.GetOffsetCurves(0.4269); + expect(cus.length).toBe(2); + expect(cus[0].Length).toMatchSnapshot(); + expect(cus[1].Length).toMatchSnapshot(); + + //situation 4 + cus = pl.GetOffsetCurves(0.2286); + expect(cus.length).toBe(1); + expect(cus[0].Length).toMatchSnapshot(); + + //situation 5 + cus = pl.GetOffsetCurves(0.2309); + expect(cus.length).toBe(2); + expect(cus[0].Length).toMatchSnapshot(); + expect(cus[1].Length).toMatchSnapshot(); + + //situation 6 + cus = pl.GetOffsetCurves(0.3792); + expect(cus.length).toBe(3); + expect(cus[0].Length).toMatchSnapshot(); + expect(cus[1].Length).toMatchSnapshot(); + expect(cus[2].Length).toMatchSnapshot(); + +}) diff --git a/src/DatabaseServices/Polyline.ts b/src/DatabaseServices/Polyline.ts index 1a04f492c..97f3409fa 100644 --- a/src/DatabaseServices/Polyline.ts +++ b/src/DatabaseServices/Polyline.ts @@ -243,7 +243,7 @@ export class Polyline extends Curve //曲线是否闭合 get IsClose(): boolean { - return this.CloseMark || equal(this.StartPoint, this.EndPoint, 1e-5); + return this.CloseMark || (equal(this.StartPoint, this.EndPoint, 1e-5)) && this.EndParam > 1; } set CloseMark(v: boolean) { diff --git a/src/GraphicsSystem/OffsetPolyline.ts b/src/GraphicsSystem/OffsetPolyline.ts index 366639a82..762166a0d 100644 --- a/src/GraphicsSystem/OffsetPolyline.ts +++ b/src/GraphicsSystem/OffsetPolyline.ts @@ -55,9 +55,9 @@ export class PolyOffsetUtil this.m_Contours.push(Contour.CreateContour([cir1])); this.m_Contours.push(Contour.CreateContour([cir2])); } - //连接修剪并构建轮廓 this.TrimAndBuildContour(offres); + // 裁剪并优化的曲线 let { boxCurves, outputCus } = this.trimByContours(this.m_RetCurves); @@ -140,8 +140,11 @@ export class PolyOffsetUtil let c2StartPt = c2.StartPoint; let c2EndPt = c2.EndPoint; + //同心圆弧 + let equalArc = c1 instanceof Arc && c2 instanceof Arc && equal(c1.Center, c2.Center); + //被包含的直线删掉 - if (c1 instanceof Line && c2 instanceof Line) + if ((c1 instanceof Line && c2 instanceof Line) || equalArc) { //c1完全在c2内 if (c2.PtOnCurve(c1StartPt) && c2.PtOnCurve(c1EndPt)) @@ -163,21 +166,16 @@ export class PolyOffsetUtil let isLink = [c1StartPt, c1EndPt].some(p => equal(p, c2StartPt) || equal(p, c2EndPt)); if (isLink) continue; - let pts = c1.IntersectWith(c2, IntersectOption.OnBothOperands); - if (pts.length > 0) + if (equalArc || c1.IntersectWith(c2, IntersectOption.OnBothOperands).length > 0) { - //按照从左到右,从上到下,分别取前后部分,即去掉中间部分 - [c1, c2].forEach((c, index) => + let isJoin = c1.Join(c2); + if (isJoin) { - let cs = c.GetSplitCurvesByPts(pts); - if (cs.length === 2) - { - let box = SortEntityByBox(cs, true); - outputCus[index === 0 ? i : j] = cs[index] - boxCurves.set(cs[index], box.get(cs[index])); - } - }) - + boxCurves.set(c1, c1.BoundingBox); + outputCus.splice(j, 1); + j--; + continue; + } } } }