Merge branch 'pl_optimize_pr' of https://gitee.com/BearCAD/WebThreeJs into pl_optimize_pr

pull/68/head
Zoe 6 years ago
commit e1f50fa1ba

@ -129,3 +129,11 @@ test('最近点', () =>
expect(circle.GetClosestPointTo(new Vector3(8, 0, 0), true)/*?*/).toMatchSnapshot();//10,0,0. expect(circle.GetClosestPointTo(new Vector3(8, 0, 0), true)/*?*/).toMatchSnapshot();//10,0,0.
}); });
test('最近点2', () =>
{
let circle = new Circle(new Vector3(5, 0, 0), 5);
let pt = circle.GetClosestPointTo(new Vector3(5), true);
expect(pt).toMatchSnapshot();
});

@ -1,12 +1,12 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { IntersectLAndLFor3D, IntersectCircleAndCircle, IntersectOption } from '../../src/GraphicsSystem/IntersectWith';
import { Vector3 } from 'three'; import { Vector3 } from 'three';
import { Arc } from '../../src/DatabaseServices/Arc';
import { CADFile } from '../../src/DatabaseServices/CADFile'; import { CADFile } from '../../src/DatabaseServices/CADFile';
import { Curve } from '../../src/DatabaseServices/Curve';
import { Circle } from '../../src/DatabaseServices/Circle'; import { Circle } from '../../src/DatabaseServices/Circle';
import { Arc } from '../../src/DatabaseServices/Arc'; import { Curve } from '../../src/DatabaseServices/Curve';
import { Line } from '../../src/DatabaseServices/Line'; import { Line } from '../../src/DatabaseServices/Line';
import { IntersectCircleAndCircle, IntersectLAndLFor3D, IntersectOption } from '../../src/GraphicsSystem/IntersectWith';
test('相交测试', () => test('相交测试', () =>
{ {
@ -116,4 +116,14 @@ function testLineAndCirIntersect(data)
expect(pts).toMatchSnapshot(); expect(pts).toMatchSnapshot();
} }
test('直线和圆 圆心和直线重合的时候', () =>
{
let c = new Circle(new Vector3(0, 0, 0), 1);
let l = new Line(new Vector3(), new Vector3());
let pts = c.IntersectWith(l, IntersectOption.ExtendBoth);
expect(pts.length).toBe(0);
});

@ -1,10 +1,10 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { Box3, EllipseCurve, Geometry, Matrix4, Object3D, Vector3 } from 'three'; import { Box3, EllipseCurve, Geometry, Object3D, Vector3 } from 'three';
import { arrayFirst, arraySortByNumber, arrayRemoveDuplicateBySort, arrayLast } from '../Common/ArrayExt'; import { arrayLast, arrayRemoveDuplicateBySort } from '../Common/ArrayExt';
import { ColorMaterial } from '../Common/ColorPalette'; import { ColorMaterial } from '../Common/ColorPalette';
import { clamp } from '../Common/Utils'; import { clamp } from '../Common/Utils';
import { Arc } from '../DatabaseServices/Arc'; import { Arc } from '../DatabaseServices/Arc';
import { angle, equaln, polar, MoveMatrix } from '../Geometry/GeUtils'; import { MoveMatrix, angle, equaln, polar } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum'; import { RenderType } from '../GraphicsSystem/Enum';
import { IntersectCircleAndArc, IntersectCircleAndCircle, IntersectLineAndCircle, IntersectOption, IntersectPolylineAndCurve, reverseIntersectOption } from '../GraphicsSystem/IntersectWith'; import { IntersectCircleAndArc, IntersectCircleAndCircle, IntersectLineAndCircle, IntersectOption, IntersectPolylineAndCurve, reverseIntersectOption } from '../GraphicsSystem/IntersectWith';
import { Factory } from './CADFactory'; import { Factory } from './CADFactory';
@ -293,6 +293,7 @@ export class Circle extends Curve
} }
GetClosestPointTo(pt: Vector3, extend: boolean): Vector3 GetClosestPointTo(pt: Vector3, extend: boolean): Vector3
{ {
if (pt.distanceToSquared(this.Center) == 0) return this.GetPointAtParam(0);
let l = new Line(this.Center, pt); let l = new Line(this.Center, pt);
let pts = l.IntersectWith(this, IntersectOption.ExtendBoth); let pts = l.IntersectWith(this, IntersectOption.ExtendBoth);
let ptIns = pt.distanceTo(pts[0]) < pt.distanceTo(pts[1]) ? pts[0] : pts[1]; let ptIns = pt.distanceTo(pts[0]) < pt.distanceTo(pts[1]) ? pts[0] : pts[1];

@ -154,6 +154,8 @@ function IntersectLineAndCircleOrArc(line: Line, circle: Circle | Arc)
let radius = circle.Radius; let radius = circle.Radius;
let a = endPoint.distanceToSquared(startPoint); let a = endPoint.distanceToSquared(startPoint);
if (a == 0)
return [];
let lineV = endPoint.clone().sub(startPoint); let lineV = endPoint.clone().sub(startPoint);
let lineToCir = startPoint.clone().sub(center); let lineToCir = startPoint.clone().sub(center);

Loading…
Cancel
Save