From be6b66d9be75da684c6ce47446d0ad87d99cd397 Mon Sep 17 00:00:00 2001 From: ChenX_AMD Date: Tue, 19 Jun 2018 21:45:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=82=B9=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E5=86=85=E7=AE=97=E6=B3=95=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Polyline/PointInPolyline.test.ts | 15 +++++++++++++++ src/DatabaseServices/PointInPolyline.ts | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/__test__/Polyline/PointInPolyline.test.ts b/__test__/Polyline/PointInPolyline.test.ts index a31786ee5..a20f06791 100644 --- a/__test__/Polyline/PointInPolyline.test.ts +++ b/__test__/Polyline/PointInPolyline.test.ts @@ -164,4 +164,19 @@ describe("", () => expect(pl.PtInCurve(p)).toBeFalsy(); }); + + test('精度过低导致的错误', () => + { + let f = new CADFile(); + f.Data = + [1, ["Polyline", 1, 1, 18237, false, 2, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.7938671363300003, 0.39666461398798525, 0, 1], 2, 5, [12.414545456418505, 8.796498405316765], 0, [12.015990240675425, 8.743859037199755], 0, [12.23362472371057, 8.552710046188702], 0, [12.233990240675425, 8.552758322014249], 0, [12.414545456418505, 8.796498405316765], 0, false]] + + let p = new Vector3().fromArray([13.027857377005425, 8.947146562082409, 0]); + + f.Read(); + let pl = f.ReadObject() as Polyline; + + pl.PtInCurve(p);//? + }); + }) diff --git a/src/DatabaseServices/PointInPolyline.ts b/src/DatabaseServices/PointInPolyline.ts index b407e663a..06f7ab7cf 100644 --- a/src/DatabaseServices/PointInPolyline.ts +++ b/src/DatabaseServices/PointInPolyline.ts @@ -84,13 +84,13 @@ export function IsPointInPolyLine(pl: Polyline, pt: Vector3): boolean if (equal(pti, cu.StartPoint)) { let der = cu.GetFistDeriv(0); - if (der.x < -1e-3) //左边+ 右边0 + if (der.x < -1e-4) //左边+ 右边0 crossings++; } else if (equal(pti, cu.EndPoint)) { let der = cu.GetFistDeriv(1); - if (der.x > 1e-3) //左边+ 右边0 + if (der.x > 1e-4) //左边+ 右边0 crossings++; } else