From 2f34bf9e543458eb2b18260f8d7c3fc5da7b73fb Mon Sep 17 00:00:00 2001 From: ChenX Date: Wed, 20 Jun 2018 17:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=82=B9=E5=9C=A8=E5=A4=9A?= =?UTF-8?q?=E6=AE=B5=E7=BA=BF=E6=96=B9=E5=90=91=E8=AE=A1=E7=AE=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/Polyline/PtInPolylineDir.test.ts | 41 ++++++++++++++++++++++- __test__/Polyline/offset.test.ts | 2 +- src/Common/CurveUtils.ts | 38 +++++++++------------ wallaby.conf.js | 6 +++- 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/__test__/Polyline/PtInPolylineDir.test.ts b/__test__/Polyline/PtInPolylineDir.test.ts index d89ac619d..b0f1a76c3 100644 --- a/__test__/Polyline/PtInPolylineDir.test.ts +++ b/__test__/Polyline/PtInPolylineDir.test.ts @@ -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(); }); diff --git a/__test__/Polyline/offset.test.ts b/__test__/Polyline/offset.test.ts index adf1bf0bd..04fbc275f 100644 --- a/__test__/Polyline/offset.test.ts +++ b/__test__/Polyline/offset.test.ts @@ -17,7 +17,7 @@ function loadFile(data) } return cus; } -// file.only + function EntityToMatchSnapshot(ens: Entity[]) { let f = new CADFile(); diff --git a/src/Common/CurveUtils.ts b/src/Common/CurveUtils.ts index 65635bc0c..e2c3313c9 100644 --- a/src/Common/CurveUtils.ts +++ b/src/Common/CurveUtils.ts @@ -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)); diff --git a/wallaby.conf.js b/wallaby.conf.js index 8c89d2f25..fee567cba 100644 --- a/wallaby.conf.js +++ b/wallaby.conf.js @@ -1,7 +1,11 @@ -module.exports = function (wallaby) +export default function (wallaby) { return { + delays: { + run: 300 + }, + files: [ 'tsconfig.json', // <-- 'src/**/*.ts*',