修正因为精度问题导致的 点在多段线内

pull/77/MERGE
ChenX 6 years ago
parent 38b91d83ef
commit 514ddf1169

@ -192,6 +192,21 @@ describe("", () =>
expect(pl.PtInCurve(p)).toBeFalsy();
});
test('直线和圆弧相切2IKOTO', () =>
{
let f = new CADFile();
f.Data =
[1, ["Polyline", 1, 1, 667, false, 6, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [5135.438782795266, 1651.835443234731], -0.9999915853997117, [5470.58864251807, 1651.8382633987026], 0, [5370.588642280742, 1651.8413831024218], 0.9999560507337252, [5235.438782795266, 1651.835443234731], 0, [5135.438782795266, 1651.835443234731], 0, false]]
f.Read();
let pl = f.ReadObject() as Polyline;
let p = new Vector3().fromArray([5370.588642541802, -904.7955785523422, 0]);
expect(pl.PtInCurve(p)).toBeFalsy();
});
test('大圆弧', () =>
{

@ -70,7 +70,7 @@ export function IsPointInPolyLine(pl: Polyline, pt: Vector3): boolean
for (let i = 0; i < pl.EndParam; i++)
{
if (equaln(pl.GetBuilgeAt(i), 0, 1e-7))//直线
if (equaln(pl.GetBuilgeAt(i), 0, 5e-6))//直线
{
let sp = pl.GetPointAtParam(i);
let ep = pl.GetPointAtParam(i + 1);
@ -79,17 +79,17 @@ export function IsPointInPolyLine(pl: Polyline, pt: Vector3): boolean
continue;
//线垂直Y轴
let derX = ep.x - sp.x;
if (equaln(derX, 0, 1e-7))
if (equaln(derX, 0, 5e-6))
continue;
//起点
if (equaln(sp.x, pt.x, 1e-7))
if (equaln(sp.x, pt.x, 5e-6))
{
if (sp.y > pt.y && derX < 0) crossings++;
continue;
}
//终点
if (equaln(ep.x, pt.x, 1e-7))
if (equaln(ep.x, pt.x, 5e-6))
{
if (ep.y > pt.y && derX > 0) crossings++;
continue;

Loading…
Cancel
Save