|
|
@ -1,8 +1,7 @@
|
|
|
|
import { Vector2, Vector3 } from 'three';
|
|
|
|
import { Vector2, Vector3 } from 'three';
|
|
|
|
|
|
|
|
|
|
|
|
import { Polyline } from '../../src/DatabaseServices/Polyline';
|
|
|
|
|
|
|
|
import { equal, equaln } from '../../src/Geometry/GeUtils';
|
|
|
|
|
|
|
|
import { CADFile } from '../../src/DatabaseServices/CADFile';
|
|
|
|
import { CADFile } from '../../src/DatabaseServices/CADFile';
|
|
|
|
|
|
|
|
import { Polyline } from '../../src/DatabaseServices/Polyline';
|
|
|
|
|
|
|
|
import { equaln, equalv3 } from '../../src/Geometry/GeUtils';
|
|
|
|
|
|
|
|
|
|
|
|
test("多段线点获取参数", () =>
|
|
|
|
test("多段线点获取参数", () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -88,12 +87,12 @@ describe('多段线', () =>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
expect(equal(pl.GetPointAtParam(1), new Vector3(5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtParam(1), new Vector3(5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtParam(0.5), new Vector3(2.5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtParam(0.5), new Vector3(2.5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtParam(-0.5), new Vector3(-2.5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtParam(-0.5), new Vector3(-2.5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtParam(4.5), new Vector3(0, 5, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtParam(4.5), new Vector3(0, 5, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtParam(5), new Vector3(0, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtParam(5), new Vector3(0, 0, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtParam(5.5), new Vector3(0, -5, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtParam(5.5), new Vector3(0, -5, 0))).toBeTruthy();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
test("多段线参数获取弧长", () =>
|
|
|
|
test("多段线参数获取弧长", () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -158,11 +157,11 @@ describe('多段线', () =>
|
|
|
|
bul: 0
|
|
|
|
bul: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
])
|
|
|
|
expect(equal(pl.GetPointAtDistance(5), new Vector3(5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtDistance(5), new Vector3(5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtDistance(2.5), new Vector3(2.5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtDistance(2.5), new Vector3(2.5, 0, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtDistance(5 + Math.PI * 2.5), new Vector3(5, 5, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtDistance(5 + Math.PI * 2.5), new Vector3(5, 5, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtDistance(5 + Math.PI * 2.5 * 2), new Vector3(5, 10, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtDistance(5 + Math.PI * 2.5 * 2), new Vector3(5, 10, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetPointAtDistance(0), new Vector3(0, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetPointAtDistance(0), new Vector3(0, 0, 0))).toBeTruthy();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
test("多段线距离获取参数", () =>
|
|
|
|
test("多段线距离获取参数", () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -305,10 +304,10 @@ describe('多段线', () =>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
])
|
|
|
|
pl3.Extend(1.5);
|
|
|
|
pl3.Extend(1.5);
|
|
|
|
expect(equal(pl3.EndPoint, new Vector3(-2.5, 2.5, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl3.EndPoint, new Vector3(-2.5, 2.5, 0))).toBeTruthy();
|
|
|
|
pl3.Extend(1 + 1 / 3);
|
|
|
|
pl3.Extend(1 + 1 / 3);
|
|
|
|
// expect(pl3.EndPoint).toEqual(new Vector3(0, 0, 0));
|
|
|
|
// expect(pl3.EndPoint).toEqual(new Vector3(0, 0, 0));
|
|
|
|
expect(equal(pl3.EndPoint /*?*/, new Vector3(0, 0, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl3.EndPoint /*?*/, new Vector3(0, 0, 0))).toBeTruthy();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
test("多段线延伸,闭合", () =>
|
|
|
|
test("多段线延伸,闭合", () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -408,8 +407,8 @@ describe('多段线', () =>
|
|
|
|
expect(pl.GetClosestPointTo(new Vector3(), true)).toEqual(new Vector3());
|
|
|
|
expect(pl.GetClosestPointTo(new Vector3(), true)).toEqual(new Vector3());
|
|
|
|
expect(pl.GetClosestPointTo(new Vector3(3.5, 2.5), true)).toEqual(new Vector3(3.5, 0, 0));
|
|
|
|
expect(pl.GetClosestPointTo(new Vector3(3.5, 2.5), true)).toEqual(new Vector3(3.5, 0, 0));
|
|
|
|
expect(pl.GetClosestPointTo(new Vector3(1.5, 3.5), true)).toEqual(new Vector3(0, 3.5, 0));
|
|
|
|
expect(pl.GetClosestPointTo(new Vector3(1.5, 3.5), true)).toEqual(new Vector3(0, 3.5, 0));
|
|
|
|
expect(equal(pl.GetClosestPointTo(new Vector3(1.5, 3.5), true), new Vector3(0, 3.5, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetClosestPointTo(new Vector3(1.5, 3.5), true), new Vector3(0, 3.5, 0))).toBeTruthy();
|
|
|
|
expect(equal(pl.GetClosestPointTo(new Vector3(-0.5, -1), true), new Vector3(0, -1, 0))).toBeTruthy();
|
|
|
|
expect(equalv3(pl.GetClosestPointTo(new Vector3(-0.5, -1), true), new Vector3(0, -1, 0))).toBeTruthy();
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
test("多段线包围盒", () =>
|
|
|
|
test("多段线包围盒", () =>
|
|
|
@ -529,3 +528,30 @@ test('最近点参数刚好在端点上', () =>
|
|
|
|
|
|
|
|
|
|
|
|
expect(equaln(param, 1)).toBeTruthy();
|
|
|
|
expect(equaln(param, 1)).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function loadFile(data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let file = new CADFile();
|
|
|
|
|
|
|
|
file.Data = data;
|
|
|
|
|
|
|
|
let cus: Polyline[] = [];
|
|
|
|
|
|
|
|
let count = file.Read();
|
|
|
|
|
|
|
|
for (let i = 0; i < count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cus.push(file.ReadObject(undefined) as Polyline);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return cus;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//https://gitee.com/BearCAD/WebThreeJs/issues/IKWGF#note_977523
|
|
|
|
|
|
|
|
test('点在线上精度', () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let data =
|
|
|
|
|
|
|
|
[1, ["Polyline", 1, 1, 4, false, 2, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 6.283029954893735, -0.21450491241551983, 0, 1], 2, 5, [-6.290104635739899, 3.3748564511765324], -0.10216571300036131, [-6.136537456708874, 3.2958817075766764], 0, [-6.236783847999098, 3.0649817075766763], 0.44141445079284647, [-6.5210046357398985, 3.121255471298752], 0, [-6.290104635739899, 3.3748564511765324], 0, false]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pl = loadFile(data)[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pt = new Vector3().fromArray([-0.23760717950533072, 2.9070744830224284, 0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(pl.PtOnCurve(pt)).toBeFalsy();
|
|
|
|
|
|
|
|
});
|
|
|
|