修正点在多段线方向计算错误的问题.

pull/68/head
ChenX 6 years ago
parent b501960bf5
commit 2f34bf9e54

@ -1,8 +1,10 @@
import { CADFile } from '../../src/DatabaseServices/CADFile';
import { Polyline } from '../../src/DatabaseServices/Polyline';
import { GetPointAtCurveDir } from '../../src/Common/CurveUtils';
import { Vector3 } from 'three';
import { Vector3, Vector2 } from 'three';
import { Factory } from '../../src/DatabaseServices/CADFactory';
Factory(Polyline);
test('2个大圆中间', () =>
{
let f = new CADFile();
@ -36,6 +38,20 @@ test('点在端点且端点平行', () =>
expect(isR).toBeTruthy();
});
test('点在和端点平行', () =>
{
let pl = new Polyline();
pl.AddVertexAt(0, new Vector2(0, 0));
pl.AddVertexAt(1, new Vector2(0, 5));
pl.AddVertexAt(2, new Vector2(0, 10));
let p = new Vector3(5, 5, 0);
let isR = GetPointAtCurveDir(pl, p);
expect(isR).toBeTruthy();
});
test('点在端点上且点在圆心上', () =>
{
@ -201,4 +217,27 @@ test('点在圆弧的弦中心上', () =>
pt = new Vector3().fromArray([5, 5.5, 0]);
isR = GetPointAtCurveDir(pl, pt);
expect(isR).toBeTruthy();
pt = new Vector3().fromArray([6, 10, 0]);
isR = GetPointAtCurveDir(pl, pt);
expect(isR).toBeTruthy();
});
test('圆弧过大导致直线小角错误', () =>
{
let f = new CADFile();
f.Data =
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.028011204481791063, 0.028011204481792618, 0, 1], 2, 4, [-2241.358078364921, -214.80916327845875], -1.1401903887488165, [-2190.503423306555, -220.10318099746846], -1.1044015866963386, [-2231.667025600985, -212.01859443849355], 0, [-2241.358078364921, -214.80916327845875], 0, false]]
f.Read();
let pl = f.ReadObject() as Polyline;
let pt = new Vector3().fromArray([-2246.7733894227954, -220.1844621837422, 0]);
let isR = GetPointAtCurveDir(pl, pt);
expect(isR).toBeFalsy();
pt = new Vector3().fromArray([-2184.668414731696, -221.35723534211996, 0]);
//[1,["Circle",1,1,4,false,7,-1,[1,0,0,0,0,1,0,0,0,0,1,0,-2184,-221.357,0,1],1,1]]
isR = GetPointAtCurveDir(pl, pt);
expect(isR).toBeFalsy();
});

@ -17,7 +17,7 @@ function loadFile(data)
}
return cus;
}
// file.only
function EntityToMatchSnapshot(ens: Entity[])
{
let f = new CADFile();

@ -282,33 +282,27 @@ export function GetPointAtCurveDir(cu: Curve, pt: Vector3): boolean
if (npInCir !== 0) return npInCir < 0;
let p = cu.GetPointAtParam(floorParam);
let fp = cu.GetPointAtParam(fIndex);
let np = cu.GetPointAtParam(nIndex);
let fDer = cu.GetFistDeriv(fIndex + 0.99).normalize();
let nDer = cu.GetFistDeriv(floorParam + 0.01).normalize();
let l1 = new Line(fp, p);
let l2 = new Line(p, np);
let l1 = new Line(p.clone().sub(fDer), p);
let l2 = new Line(p, p.clone().add(nDer));
let cp1 = l1.GetClosestPointTo(pt, true);
let cp2 = l2.GetClosestPointTo(pt, true);
//小角的叉积.
let across = l1.GetFistDeriv(0).normalize().cross(l2.GetFistDeriv(0).normalize());
if (equal(fDer, nDer.clone().negate()))
return true;
if (equal(fDer, nDer))
return fDer.cross(pt.clone().sub(cp1)).z < 0;
//当2线平行时
if (equaln(across.z, 0, 1e-6))
{
return l1.GetFistDeriv(0).cross(pt.clone().sub(cp1)).z < 0;
}
else
{
let adir = Math.sign(across.z);
//判断点是否在小角内.
if (
Math.sign(l1.GetFistDeriv(0).cross(pt.clone().sub(cp1)).z) === adir
&& Math.sign(l2.GetFistDeriv(0).cross(pt.clone().sub(cp2)).z) === adir
)
return adir < 0;
else return adir > 0;
}
let adir = Math.sign(fDer.clone().cross(nDer).z);
//判断点是否在小角内.
if (
Math.sign(fDer.cross(pt.clone().sub(cp1)).z) === adir
&& Math.sign(nDer.cross(pt.clone().sub(cp2)).z) === adir
)
return adir < 0;
else return adir > 0;
}
let dri = cu.GetFistDeriv(cparam);
let cross = dri.cross(pt.clone().sub(cp));

@ -1,7 +1,11 @@
module.exports = function (wallaby)
export default function (wallaby)
{
return {
delays: {
run: 300
},
files: [
'tsconfig.json', // <--
'src/**/*.ts*',

Loading…
Cancel
Save