You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/__test__/Polyline/PointInPolyline.test.ts

183 lines
4.3 KiB

import { Vector2, Vector3 } from 'three';
import { IsPointInPolyLine } from '../../src/DatabaseServices/PointInPolyline';
import { Polyline } from '../../src/DatabaseServices/Polyline';
6 years ago
import { CADFile } from '../../src/DatabaseServices/CADFile';
test('点在多段线内', () =>
{
let pl = new Polyline([
{
pt: new Vector2(0, 0),
bul: 0
},
{
pt: new Vector2(10, 0),
bul: 0
},
{
pt: new Vector2(10, 10),
bul: 0
},
{
pt: new Vector2(8, 10),
bul: 0
},
{
pt: new Vector2(8, 5),
bul: 0
},
{
pt: new Vector2(4, 5),
bul: 0
},
{
pt: new Vector2(4, 10),
bul: 0
},
{
pt: new Vector2(0, 10),
bul: 0
},
]);
pl.CloseMark = true;
let bIn = IsPointInPolyLine(pl, new Vector3(8, 3));//?
expect(bIn).toBeTruthy();
});
describe("", () =>
{
test('退化', () =>
{
let pl = new Polyline(
[
{
pt: new Vector2(0, 0),
bul: 0
},
{
pt: new Vector2(10, 0),
bul: 0
},
{
pt: new Vector2(5, 5),
bul: 0
},
])
pl.CloseMark = true;
expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy();
});
test('退化2', () =>
{
//右边中间 <
let pl = new Polyline(
[
{
pt: new Vector2(0, 0),
bul: 0
},
{
pt: new Vector2(10, 0),
bul: 0
},
{
pt: new Vector2(5, 5),
bul: 0
},
{
pt: new Vector2(10, 10),
bul: 0
},
{
pt: new Vector2(0, 10),
bul: 0
},
])
pl.CloseMark = true;
expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy();
});
test('左边中间', () =>
{
//左边中间
let pl = new Polyline([
{
pt: new Vector2(0, 0),
bul: 0
},
{
pt: new Vector2(10, 0),
bul: 0
},
{
pt: new Vector2(10, 10),
bul: 0
},
{
pt: new Vector2(0, 10),
bul: 0
},
{
pt: new Vector2(0, 8),
bul: 0
},
{
pt: new Vector2(5, 5),
bul: 0
}]
)
pl.CloseMark = true;
expect(IsPointInPolyLine(pl, new Vector3(5, 2))).toBeTruthy();
});
6 years ago
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();
});
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);//?
});
})