From a34d414b9f6ad9a75612d9255330cb741493e925 Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Fri, 15 Jan 2021 16:02:39 +0800 Subject: [PATCH] =?UTF-8?q?!1390=20=E4=BF=AE=E5=A4=8D:=E8=87=AA=E4=BA=A4?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Polyline/IntersectSelf.test.ts | 30 +++++++++++++++++++++ src/DatabaseServices/3DSolid/ExtrudeHole.ts | 2 +- src/DatabaseServices/Entity/Polyline.ts | 19 +++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/__test__/Polyline/IntersectSelf.test.ts b/__test__/Polyline/IntersectSelf.test.ts index 964c4ee0a..0a8269e55 100644 --- a/__test__/Polyline/IntersectSelf.test.ts +++ b/__test__/Polyline/IntersectSelf.test.ts @@ -27,4 +27,34 @@ describe("多段线自交测试", () => let l = LoadCurvesFromFileData(data)[0] as Polyline; expect(l.IsIntersectSelf()).toBeTruthy(); }); + test("5", () => + { + let data = { "file": [1, "Polyline", 8, 2, 108, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1212.5305724196535, 482.7356638308014, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 996.7017971879932, 325.233158998051, 0, 1], 0, 2, 2, [0, 0], 0.7155775946627989, [-118.0686402962823, 0], 0, true], "basePt": { "x": 1094.461932123371, "y": 482.7356638308014, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let l = LoadCurvesFromFileData(data)[0] as Polyline; + expect(l.IsIntersectSelf()).toBeFalsy(); + }); + test("6", () => + { + let data = { "file": [1, "Polyline", 8, 2, 121, false, 1, 7, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 351.73625918131165, 368.74059237065853, 1], 0, 0, true, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 351.73625918131165, 368.74059237065853, 1], 0, 2, 5, [0, 0], 0, [600, 0], 0, [600, 891.5082590745878], 0, [50, 891.5082590745878], 0.41421356237309503, [0, 841.5082590745878], 0, true], "basePt": { "x": 0, "y": 351.73625918131165, "z": 368.74059237065853 }, "ucs": [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1] }; + let l = LoadCurvesFromFileData(data)[0] as Polyline; + expect(l.IsIntersectSelf()).toBeFalsy(); + }); + test("7", () => + { + let data = { "file": [1, "Polyline", 8, 2, 112, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5882.0163350721095, -731.8781048637103, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 3, [-575.8829196797014, 0], 0, [0, 0], 1.0114583228934644, [-546.610380563744, -20.217610565438804], 0, false], "basePt": { "x": 5306.133415392408, "y": -752.095715429149, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let l = LoadCurvesFromFileData(data)[0] as Polyline; + expect(l.IsIntersectSelf()).toBeTruthy(); + }); + test("存在0长度线段", () => + { + let data = { "file": [1, "Polyline", 8, 2, 657, false, 1, 7, 0, [6.123233995736766e-17, 3.0616169978683826e-16, 1, 0, 0, -1, 3.0616169978683826e-16, 0, 1, -1.874699728327322e-32, -6.123233995736766e-17, 0, -4.307695186480463e-12, 1515.3176391778895, -69649.98365070373, 1], 0, 0, true, [6.123233995736766e-17, 3.0616169978683826e-16, 1, 0, 0, -1, 3.0616169978683826e-16, 0, 1, -1.874699728327322e-32, -6.123233995736766e-17, 0, -4.307695186480463e-12, 1515.3176391778895, -69649.98365070373, 1], 0, 2, 27, [70350.00115102, 32.607], 0.279706873, [70369.892619953, 50.0254], 0.072615668, [70375.178451285, 70.93], 0, [70266.183079702, 70.93], 0, [70266.183079702, 87.9297], 0, [70375.17827523, 87.9297], 0.050805326, [70372.08281644, 102.8523], 0.188505204, [70358.569211378, 123.0919], 0.070936827, [70334.366200559, 129.3265], -0.030544906, [70290.698685351, 137.4962], -0.042995869, [70249.348921999, 153.2524], 0.265286301, [70220.838643761, 155.8282], 0.028618596, [70207.923905154, 143.7599], -0.147916383, [70199.453042623, 138.9386], -0.133448904, [70187.080781157, 142.1952], 0.297025308, [70170.245305009, 141.9041], 0.182683137, [70157.471986577, 115.0469], 0.100954508, [70161.26751983, 79.4298], 0.229336055, [70166.129434786, 21.2294], 0.321223029, [70180.286927378, 14.4487], 0.056105467, [70192.405227719, 18.9585], -0.310942714, [70206.574830772, 16.2486], -0.021437337, [70215.823047463, 7.2405], 0.3447941, [70240.855637261, 2.2044], 0.003242185, [70268.708331693, 13.991], -0.058997543, [70317.599075392, 26.9568], 0.02653927, [70350.001151, 32.607], 0, true], "basePt": { "x": -1.1789011248882874e-14, "y": 1356.8785152320816, "z": 507.4883358732627 }, "ucs": [6.123233995736766e-17, 3.0616169978683826e-16, 1, 0, 0, -1, 3.0616169978683826e-16, 0, 1, -1.874699728327322e-32, -6.123233995736766e-17, 0, 0, 0, 0, 1] }; + let l = LoadCurvesFromFileData(data)[0] as Polyline; + expect(l.IsIntersectSelf()).toBeFalsy(); + }); + test("相切圆弧2个交点", () => + { + let data = { "file": [1, "Polyline", 8, 2, 102, false, 1, 7, 0, [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 679.0663600848402, 19.06829661016957, 1], 0, 0, true, [0, -1, 1.224646799147353e-16, 0, 0, 1.224646799147353e-16, 1, 0, 1, 0, 0, 0, 0, 264338.06676908507, -7425.932803389861, 1], 0, 2, 8, [631.3248432089458, 314.9994999999999], 0.312964119, [537.6496864189976, 380], 0, [50, 380], 0.414213562, [0, 330.0000000000018], 0, [0, 1.8189894035458565e-12], 0, [1250, 0], 0, [1250, 249.9989999999998], 0, [725, 249.9989999999998], -0.312964119, true], "basePt": { "x": 0, "y": 679.0663600848402, "z": 19.06829661016957 }, "ucs": [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1] }; + let l = LoadCurvesFromFileData(data)[0] as Polyline; + expect(l.IsIntersectSelf()).toBeFalsy(); + }); }); diff --git a/src/DatabaseServices/3DSolid/ExtrudeHole.ts b/src/DatabaseServices/3DSolid/ExtrudeHole.ts index 2d14e5ef5..e4cb84c72 100644 --- a/src/DatabaseServices/3DSolid/ExtrudeHole.ts +++ b/src/DatabaseServices/3DSolid/ExtrudeHole.ts @@ -395,7 +395,7 @@ export class ExtrudeHole extends Hole } UpdateDrawObjectMaterial(renderType: RenderType, obj: Object3D) { - if (renderType === RenderType.Wireframe) + if (renderType === RenderType.Wireframe || renderType === RenderType.Edge) { let l = obj as LineSegments; l.material = ColorMaterial.GetLineMaterial(this.ColorIndex); diff --git a/src/DatabaseServices/Entity/Polyline.ts b/src/DatabaseServices/Entity/Polyline.ts index 7f31b4604..7960ff14b 100644 --- a/src/DatabaseServices/Entity/Polyline.ts +++ b/src/DatabaseServices/Entity/Polyline.ts @@ -1272,7 +1272,7 @@ export class Polyline extends Curve } IsIntersectSelf() { - let cus = this.Explode(); + let cus = this.Explode().filter(c => !equaln(c.Length, 0, 1e-3)); for (let i = 0; i < cus.length - 1; i++) { let c1 = cus[i]; @@ -1302,10 +1302,25 @@ export class Polyline extends Curve } } - let intPtsLen = c1.IntersectWith2(c2, 0).length; + let intPts = c1.IntersectWith2(c2, 0); + let intPtsLen = intPts.length; if (intPtsLen > 0) { + if (intPtsLen === 2 && equalv3(intPts[0].pt, intPts[1].pt, 1e-3)) + { + intPtsLen = 1; + intPts.pop(); + } + + if (intPtsLen === 2 && j === i + 1 && cus.length === 2) + { + if (intPts.every(r => equaln(r.thisParam, 0, 1e-3) || equaln(r.thisParam, 1, 1e-3))) + continue; + } + + if (j === i + 1 && intPtsLen === 1) + continue; if (this.IsClose && i === 0 && j === cus.length - 1 && intPtsLen === 1) continue; return true;