diff --git a/docs/api/math/Triangle.html b/docs/api/math/Triangle.html
index 658f9cc4bd6fa89c6b866aded4d7f4a9b68afc82..a078c20c18ccaf91c7c111392341867a889f5766 100644
--- a/docs/api/math/Triangle.html
+++ b/docs/api/math/Triangle.html
@@ -51,10 +51,10 @@
[method:Float area]()
Return the area of the triangle.
- [method:Vector3 barycoordFromPoint]( [param:Vector3 point], [param:Vector3 optionalTarget] )
+ [method:Vector3 barycoordFromPoint]( [param:Vector3 point], [param:Vector3 target] )
[page:Vector3 point] - [page:Vector3]
- [page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.
+ [page:Vector3 target] — the result will be copied into this Vector3.
Return a [link:https://en.wikipedia.org/wiki/Barycentric_coordinate_system barycentric coordinate]
from the given vector.
@@ -67,10 +67,10 @@
Returns a new triangle with the same [page:.a a], [page:.b b] and [page:.c c] properties as this one.
- [method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 optionalTarget] )
+ [method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 target] )
point - [page:Vector3]
- [page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.
+ [page:Vector3 target] — the result will be copied into this Vector3.
Returns the closest point on the triangle to [page:Vector3 point].
@@ -100,23 +100,23 @@
Determines whether or not this triangle intersects [page:Box3 box].
- [method:Vector3 midpoint]( [param:Vector3 optionalTarget] )
+ [method:Vector3 midpoint]( [param:Vector3 target] )
- [page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.
+ [page:Vector3 target] — the result will be copied into this Vector3.
Calculate the midpoint of the triangle.
- [method:Vector3 normal]( [param:Vector3 optionalTarget] )
+ [method:Vector3 normal]( [param:Vector3 target] )
- [page:Vector3 optionalTarget] - (optional) if specified, the result will be copied into this [page:Vector3], otherwise a new [page:Vector3] will be created.
+ [page:Vector3 target] — the result will be copied into this Vector3.
Calculate the [link:https://en.wikipedia.org/wiki/Normal_(geometry) normal vector] of the triangle.
- [method:Plane plane]( [param:Plane optionalTarget] )
+ [method:Plane plane]( [param:Plane target] )
- [page:Plane optionalTarget] - (optional) if specified, the result will be copied into this [page:Plane], otherwise a new [page:Plane] will be created.
+ [page:Vector3 target] — the result will be copied into this Vector3.
Create a [page:Plane plane] based on the triangle. .
diff --git a/src/math/Triangle.js b/src/math/Triangle.js
index 76fd3696fa9df6416f16a27676d48a96ef096177..7ff3fcecd23ddc3213a199757d1f7eb1c140f478 100644
--- a/src/math/Triangle.js
+++ b/src/math/Triangle.js
@@ -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;
};