修正一些精度问题导致的无法通过测试

pull/76/head
chenx_dev251 6 years ago
parent f8018f4217
commit 839c323f60

@ -8,6 +8,8 @@ Vector3 {
}
`;
exports[`多段线 多段线点获取弧长 1`] = `35.70780177742267`;
exports[`多段线 存在大圆弧的多段线面积 1`] = `-24.019436375469752`;
exports[`多段线 最近点精度 1`] = `

@ -228,7 +228,7 @@ describe('多段线', () =>
expect(pl.GetDistAtPoint(new Vector3(5, 0, 0))).toBe(5);
expect(pl.GetDistAtPoint(new Vector3(7.5, 2.5, 0))).toBe(5 + Math.PI / 2 * 2.5);
expect(pl.GetDistAtPoint(new Vector3(7.5, 2.5, 0))).toBe(5 + Math.PI / 2 * 2.5);
expect(equaln(pl.Length, 20 + 2 * Math.PI * 2.5)).toBeTruthy();
expect(pl.Length).toMatchSnapshot();
})
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))//直线
if (equaln(pl.GetBuilgeAt(i), 0, 1e-7))//直线
{
let sp = pl.GetPointAtParam(i);
let ep = pl.GetPointAtParam(i + 1);
@ -79,7 +79,7 @@ export function IsPointInPolyLine(pl: Polyline, pt: Vector3): boolean
continue;
//线垂直Y轴
let derX = ep.x - sp.x;
if (equaln(derX, 0))
if (equaln(derX, 0, 1e-7))
continue;
//起点

@ -22,7 +22,7 @@ export function rotatePoint(pt: Vector3, ang: number): Vector3
return pt;
}
export function equaln(v1: number, v2: number, fuzz = 1e-3)
export function equaln(v1: number, v2: number, fuzz = 1e-5)
{
return Math.abs(v1 - v2) < fuzz;
}

Loading…
Cancel
Save