修正点在多段线内部算法没有正确的判断相切,导致算法在某些情况下出错,请参考测试代码.

pull/72/head
ChenX 6 years ago
parent c05c2cd72e
commit 783adfb1cc

@ -2,6 +2,7 @@ import { Vector2, Vector3 } from 'three';
import { IsPointInPolyLine } from '../../src/DatabaseServices/PointInPolyline';
import { Polyline } from '../../src/DatabaseServices/Polyline';
import { CADFile } from '../../src/DatabaseServices/CADFile';
test('点在多段线内', () =>
@ -141,4 +142,26 @@ describe("", () =>
expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy();
});
test('点在曲线外精度问题', () =>
{
let plData = [["Polyline", 1, 1, 4317, false, 3, -1,
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
2, 5,
[-3, 3.6739403974420594e-16], 0.9999999999999999,
[3, 3.6739403974420594e-16], 0, [3, 10], 0.9999999999999999,
[-3, 10], 0, [-3, -3.6739403974420594e-16], 0,
false]];
let f = new CADFile();
f.Data = plData;
let pl = f.ReadObject(undefined) as Polyline;
let p = new Vector3(-3, -0.16000000000000014, 0);
expect(pl.PtInCurve(p)).toBeFalsy();
});
})

@ -55,7 +55,7 @@ export class CADFile
this.Write(tempFile.Data);
tempFile.Destroy();//GC
}
ReadObject(db: Database, obj?: CADObject): CADObject
ReadObject(db?: Database, obj?: CADObject): CADObject
{
let data = this.Read();
let tempFile = new CADFile();

@ -81,7 +81,7 @@ 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-3) //左边+ 右边0
crossings++;
}
else if (equal(pti, cu.EndPoint))
@ -124,7 +124,7 @@ function IsPointInPolygon(pt: Vector3, pts: Vector2[])
/* This is done to ensure that we get the same result when
the line goes from left to right and right to left */
if (x1 > x2)[x1, x2] = [x2, x1];
if (x1 > x2) [x1, x2] = [x2, x1];
/* First check if the ray is possible to cross the line */
if (px > x1 && px <= x2 && (py < pti.y || py <= ptn.y))

Loading…
Cancel
Save