|
@@ -21,22 +21,27 @@ Object.assign( Triangle, {
|
|
|
|
|
|
var v0 = new Vector3();
|
|
|
|
|
|
- return function normal( a, b, c, optionalTarget ) {
|
|
|
+ return function normal( a, b, c, target ) {
|
|
|
|
|
|
- var result = optionalTarget || new Vector3();
|
|
|
+ if ( target === undefined ) {
|
|
|
|
|
|
- result.subVectors( c, b );
|
|
|
+ console.warn( 'THREE.Triangle: .normal() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ target.subVectors( c, b );
|
|
|
v0.subVectors( a, b );
|
|
|
- result.cross( v0 );
|
|
|
+ target.cross( v0 );
|
|
|
|
|
|
- var resultLengthSq = result.lengthSq();
|
|
|
- if ( resultLengthSq > 0 ) {
|
|
|
+ var targetLengthSq = target.lengthSq();
|
|
|
+ if ( targetLengthSq > 0 ) {
|
|
|
|
|
|
- return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
|
|
|
+ return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- return result.set( 0, 0, 0 );
|
|
|
+ return target.set( 0, 0, 0 );
|
|
|
|
|
|
};
|
|
|
|
|
@@ -50,7 +55,7 @@ Object.assign( Triangle, {
|
|
|
var v1 = new Vector3();
|
|
|
var v2 = new Vector3();
|
|
|
|
|
|
- return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
|
|
|
+ return function barycoordFromPoint( point, a, b, c, target ) {
|
|
|
|
|
|
v0.subVectors( c, a );
|
|
|
v1.subVectors( b, a );
|
|
@@ -64,14 +69,19 @@ Object.assign( Triangle, {
|
|
|
|
|
|
var denom = ( dot00 * dot11 - dot01 * dot01 );
|
|
|
|
|
|
- var result = optionalTarget || new Vector3();
|
|
|
+ if ( target === undefined ) {
|
|
|
+
|
|
|
+ console.warn( 'THREE.Triangle: .barycoordFromPoint() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
// collinear or singular triangle
|
|
|
if ( denom === 0 ) {
|
|
|
|
|
|
// arbitrary location outside of triangle?
|
|
|
// not sure if this is the best idea, maybe should be returning undefined
|
|
|
- return result.set( - 2, - 1, - 1 );
|
|
|
+ return target.set( - 2, - 1, - 1 );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -80,7 +90,7 @@ Object.assign( Triangle, {
|
|
|
var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
|
|
|
|
|
|
// barycentric coordinates must always sum to 1
|
|
|
- return result.set( 1 - u - v, v, u );
|
|
|
+ return target.set( 1 - u - v, v, u );
|
|
|
|
|
|
};
|
|
|
|
|
@@ -92,9 +102,9 @@ Object.assign( Triangle, {
|
|
|
|
|
|
return function containsPoint( point, a, b, c ) {
|
|
|
|
|
|
- var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
|
|
|
+ Triangle.barycoordFromPoint( point, a, b, c, v1 );
|
|
|
|
|
|
- return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
|
|
|
+ return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
|
|
|
|
|
|
};
|
|
|
|
|
@@ -156,30 +166,41 @@ Object.assign( Triangle.prototype, {
|
|
|
|
|
|
}(),
|
|
|
|
|
|
- midpoint: function ( optionalTarget ) {
|
|
|
+ midpoint: function ( target ) {
|
|
|
+
|
|
|
+ if ( target === undefined ) {
|
|
|
+
|
|
|
+ console.warn( 'THREE.Triangle: .midpoint() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
|
|
|
- var result = optionalTarget || new Vector3();
|
|
|
- return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
|
|
|
+ }
|
|
|
+
|
|
|
+ return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
|
|
|
|
|
|
},
|
|
|
|
|
|
- normal: function ( optionalTarget ) {
|
|
|
+ normal: function ( target ) {
|
|
|
|
|
|
- return Triangle.normal( this.a, this.b, this.c, optionalTarget );
|
|
|
+ return Triangle.normal( this.a, this.b, this.c, target );
|
|
|
|
|
|
},
|
|
|
|
|
|
- plane: function ( optionalTarget ) {
|
|
|
+ plane: function ( target ) {
|
|
|
+
|
|
|
+ if ( target === undefined ) {
|
|
|
|
|
|
- var result = optionalTarget || new Plane();
|
|
|
+ console.warn( 'THREE.Triangle: .plane() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- return result.setFromCoplanarPoints( this.a, this.b, this.c );
|
|
|
+ return target.setFromCoplanarPoints( this.a, this.b, this.c );
|
|
|
|
|
|
},
|
|
|
|
|
|
- barycoordFromPoint: function ( point, optionalTarget ) {
|
|
|
+ barycoordFromPoint: function ( point, target ) {
|
|
|
|
|
|
- return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
|
|
|
+ return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, target );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -202,9 +223,15 @@ Object.assign( Triangle.prototype, {
|
|
|
var projectedPoint = new Vector3();
|
|
|
var closestPoint = new Vector3();
|
|
|
|
|
|
- return function closestPointToPoint( point, optionalTarget ) {
|
|
|
+ return function closestPointToPoint( point, target ) {
|
|
|
+
|
|
|
+ if ( target === undefined ) {
|
|
|
+
|
|
|
+ console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
|
|
|
+ target = new Vector3();
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- var result = optionalTarget || new Vector3();
|
|
|
var minDistance = Infinity;
|
|
|
|
|
|
// project the point onto the plane of the triangle
|
|
@@ -218,11 +245,11 @@ Object.assign( Triangle.prototype, {
|
|
|
|
|
|
// if so, this is the closest point
|
|
|
|
|
|
- result.copy( projectedPoint );
|
|
|
+ target.copy( projectedPoint );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
|
|
|
+ // if not, the point falls outside the triangle. the target is the closest point to the triangle's edges or vertices
|
|
|
|
|
|
edgeList[ 0 ].set( this.a, this.b );
|
|
|
edgeList[ 1 ].set( this.b, this.c );
|
|
@@ -238,7 +265,7 @@ Object.assign( Triangle.prototype, {
|
|
|
|
|
|
minDistance = distance;
|
|
|
|
|
|
- result.copy( closestPoint );
|
|
|
+ target.copy( closestPoint );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -246,7 +273,7 @@ Object.assign( Triangle.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
- return result;
|
|
|
+ return target;
|
|
|
|
|
|
};
|
|
|
|