2
0
Эх сурвалжийг харах

Math: Align syntax of module scope variables.

Mugen87 6 жил өмнө
parent
commit
c7152b174b
5 өөрчлөгдсөн 225 нэмэгдсэн , 225 устгасан
  1. 66 66
      src/math/Box3.js
  2. 6 6
      src/math/Math.js
  3. 53 53
      src/math/Matrix4.js
  4. 40 40
      src/math/Ray.js
  5. 60 60
      src/math/Triangle.js

+ 66 - 66
src/math/Box3.js

@@ -5,14 +5,14 @@ import { Vector3 } from './Vector3.js';
  * @author WestLangley / http://github.com/WestLangley
  */
 
-var points;
-var vector;
+var _points;
+var _vector;
 
-var v0, v1, v2;
-var f0, f1, f2;
-var center;
-var extents;
-var triangleNormal;
+var _v0, _v1, _v2;
+var _f0, _f1, _f2;
+var _center;
+var _extents;
+var _triangleNormal;
 
 function Box3( min, max ) {
 
@@ -116,9 +116,9 @@ Object.assign( Box3.prototype, {
 
 	setFromCenterAndSize: function ( center, size ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
-		var halfSize = vector.copy( size ).multiplyScalar( 0.5 );
+		var halfSize = _vector.copy( size ).multiplyScalar( 0.5 );
 
 		this.min.copy( center ).sub( halfSize );
 		this.max.copy( center ).add( halfSize );
@@ -222,7 +222,7 @@ Object.assign( Box3.prototype, {
 
 	expandByObject: function ( object ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
 		var i, l;
 
@@ -241,10 +241,10 @@ Object.assign( Box3.prototype, {
 
 				for ( i = 0, l = vertices.length; i < l; i ++ ) {
 
-					vector.copy( vertices[ i ] );
-					vector.applyMatrix4( object.matrixWorld );
+					_vector.copy( vertices[ i ] );
+					_vector.applyMatrix4( object.matrixWorld );
 
-					this.expandByPoint( vector );
+					this.expandByPoint( _vector );
 
 				}
 
@@ -256,9 +256,9 @@ Object.assign( Box3.prototype, {
 
 					for ( i = 0, l = attribute.count; i < l; i ++ ) {
 
-						vector.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
+						_vector.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
 
-						this.expandByPoint( vector );
+						this.expandByPoint( _vector );
 
 					}
 
@@ -329,13 +329,13 @@ Object.assign( Box3.prototype, {
 
 	intersectsSphere: function ( sphere ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
 		// Find the point on the AABB closest to the sphere center.
-		this.clampPoint( sphere.center, vector );
+		this.clampPoint( sphere.center, _vector );
 
 		// If that point is inside the sphere, the AABB and sphere intersect.
-		return vector.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
+		return _vector.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
 
 	},
 
@@ -388,23 +388,23 @@ Object.assign( Box3.prototype, {
 
 	intersectsTriangle: function ( triangle ) {
 
-		if ( v0 === undefined ) {
+		if ( _v0 === undefined ) {
 
 			// triangle centered vertices
 
-			v0 = new Vector3();
-			v1 = new Vector3();
-			v2 = new Vector3();
+			_v0 = new Vector3();
+			_v1 = new Vector3();
+			_v2 = new Vector3();
 
 			// triangle edge vectors
 
-			f0 = new Vector3();
-			f1 = new Vector3();
-			f2 = new Vector3();
+			_f0 = new Vector3();
+			_f1 = new Vector3();
+			_f2 = new Vector3();
 
-			center = new Vector3();
-			extents = new Vector3();
-			triangleNormal = new Vector3();
+			_center = new Vector3();
+			_extents = new Vector3();
+			_triangleNormal = new Vector3();
 
 		}
 
@@ -415,28 +415,28 @@ Object.assign( Box3.prototype, {
 		}
 
 		// compute box center and extents
-		this.getCenter( center );
-		extents.subVectors( this.max, center );
+		this.getCenter( _center );
+		_extents.subVectors( this.max, _center );
 
 		// translate triangle to aabb origin
-		v0.subVectors( triangle.a, center );
-		v1.subVectors( triangle.b, center );
-		v2.subVectors( triangle.c, center );
+		_v0.subVectors( triangle.a, _center );
+		_v1.subVectors( triangle.b, _center );
+		_v2.subVectors( triangle.c, _center );
 
 		// compute edge vectors for triangle
-		f0.subVectors( v1, v0 );
-		f1.subVectors( v2, v1 );
-		f2.subVectors( v0, v2 );
+		_f0.subVectors( _v1, _v0 );
+		_f1.subVectors( _v2, _v1 );
+		_f2.subVectors( _v0, _v2 );
 
 		// test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
 		// make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
 		// axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
 		var axes = [
-			0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
-			f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
-			- f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
+			0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
+			_f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
+			- _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
 		];
-		if ( ! satForAxes( axes, v0, v1, v2, extents ) ) {
+		if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
 
 			return false;
 
@@ -444,7 +444,7 @@ Object.assign( Box3.prototype, {
 
 		// test 3 face normals from the aabb
 		axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
-		if ( ! satForAxes( axes, v0, v1, v2, extents ) ) {
+		if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
 
 			return false;
 
@@ -452,10 +452,10 @@ Object.assign( Box3.prototype, {
 
 		// finally testing the face normal of the triangle
 		// use already existing triangle edge vectors here
-		triangleNormal.crossVectors( f0, f1 );
-		axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
+		_triangleNormal.crossVectors( _f0, _f1 );
+		axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
 
-		return satForAxes( axes, v0, v1, v2, extents );
+		return satForAxes( axes, _v0, _v1, _v2, _extents );
 
 	},
 
@@ -474,9 +474,9 @@ Object.assign( Box3.prototype, {
 
 	distanceToPoint: function ( point ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
-		var clampedPoint = vector.copy( point ).clamp( this.min, this.max );
+		var clampedPoint = _vector.copy( point ).clamp( this.min, this.max );
 
 		return clampedPoint.sub( point ).length();
 
@@ -484,7 +484,7 @@ Object.assign( Box3.prototype, {
 
 	getBoundingSphere: function ( target ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
 		if ( target === undefined ) {
 
@@ -495,7 +495,7 @@ Object.assign( Box3.prototype, {
 
 		this.getCenter( target.center );
 
-		target.radius = this.getSize( vector ).length() * 0.5;
+		target.radius = this.getSize( _vector ).length() * 0.5;
 
 		return target;
 
@@ -524,9 +524,9 @@ Object.assign( Box3.prototype, {
 
 	applyMatrix4: function ( matrix ) {
 
-		if ( points === undefined ) {
+		if ( _points === undefined ) {
 
-			points = [
+			_points = [
 				new Vector3(),
 				new Vector3(),
 				new Vector3(),
@@ -543,16 +543,16 @@ Object.assign( Box3.prototype, {
 		if ( this.isEmpty() ) return this;
 
 		// NOTE: I am using a binary pattern to specify all 2^3 combinations below
-		points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
-		points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
-		points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
-		points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
-		points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
-		points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
-		points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
-		points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
+		_points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
+		_points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
+		_points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
+		_points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
+		_points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
+		_points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
+		_points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
+		_points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
 
-		this.setFromPoints( points );
+		this.setFromPoints( _points );
 
 		return this;
 
@@ -575,23 +575,23 @@ Object.assign( Box3.prototype, {
 
 } );
 
-var testAxis;
+var _testAxis;
 
 function satForAxes( axes, v0, v1, v2, extents ) {
 
-	if ( testAxis === undefined ) testAxis = new Vector3();
+	if ( _testAxis === undefined ) _testAxis = new Vector3();
 
 	var i, j;
 
 	for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
 
-		testAxis.fromArray( axes, i );
+		_testAxis.fromArray( axes, i );
 		// project the aabb onto the seperating axis
-		var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
+		var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
 		// project all 3 vertices of the triangle onto the seperating axis
-		var p0 = v0.dot( testAxis );
-		var p1 = v1.dot( testAxis );
-		var p2 = v2.dot( testAxis );
+		var p0 = v0.dot( _testAxis );
+		var p1 = v1.dot( _testAxis );
+		var p2 = v2.dot( _testAxis );
 		// actual test, basically see if either of the most extreme of the triangle points intersects r
 		if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
 

+ 6 - 6
src/math/Math.js

@@ -3,11 +3,11 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
-var lut = [];
+var _lut = [];
 
 for ( var i = 0; i < 256; i ++ ) {
 
-	lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
+	_lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
 
 }
 
@@ -24,10 +24,10 @@ var _Math = {
 		var d1 = Math.random() * 0xffffffff | 0;
 		var d2 = Math.random() * 0xffffffff | 0;
 		var d3 = Math.random() * 0xffffffff | 0;
-		var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
-			lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
-			lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
-			lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
+		var uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
+			_lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
+			_lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
+			_lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
 
 		// .toUpperCase() here flattens concatenated strings to save heap memory space.
 		return uuid.toUpperCase();

+ 53 - 53
src/math/Matrix4.js

@@ -13,9 +13,9 @@ import { Vector3 } from './Vector3.js';
  * @author WestLangley / http://github.com/WestLangley
  */
 
-var v1, m1;
-var zero, one;
-var x, y, z;
+var _v1, _m1;
+var _zero, _one;
+var _x, _y, _z;
 
 function Matrix4() {
 
@@ -125,16 +125,16 @@ Object.assign( Matrix4.prototype, {
 
 	extractRotation: function ( m ) {
 
-		if ( v1 === undefined ) v1 = new Vector3();
+		if ( _v1 === undefined ) _v1 = new Vector3();
 
 		// this method does not support reflection matrices
 
 		var te = this.elements;
 		var me = m.elements;
 
-		var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
-		var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
-		var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
+		var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
+		var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
+		var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
 
 		te[ 0 ] = me[ 0 ] * scaleX;
 		te[ 1 ] = me[ 1 ] * scaleX;
@@ -290,67 +290,67 @@ Object.assign( Matrix4.prototype, {
 
 	makeRotationFromQuaternion: function ( q ) {
 
-		if ( zero === undefined ) {
+		if ( _zero === undefined ) {
 
-			zero = new Vector3( 0, 0, 0 );
-			one = new Vector3( 1, 1, 1 );
+			_zero = new Vector3( 0, 0, 0 );
+			_one = new Vector3( 1, 1, 1 );
 
 		}
 
-		return this.compose( zero, q, one );
+		return this.compose( _zero, q, _one );
 
 	},
 
 	lookAt: function ( eye, target, up ) {
 
-		if ( x === undefined ) {
+		if ( _x === undefined ) {
 
-			x = new Vector3();
-			y = new Vector3();
-			z = new Vector3();
+			_x = new Vector3();
+			_y = new Vector3();
+			_z = new Vector3();
 
 		}
 
 		var te = this.elements;
 
-		z.subVectors( eye, target );
+		_z.subVectors( eye, target );
 
-		if ( z.lengthSq() === 0 ) {
+		if ( _z.lengthSq() === 0 ) {
 
 			// eye and target are in the same position
 
-			z.z = 1;
+			_z.z = 1;
 
 		}
 
-		z.normalize();
-		x.crossVectors( up, z );
+		_z.normalize();
+		_x.crossVectors( up, _z );
 
-		if ( x.lengthSq() === 0 ) {
+		if ( _x.lengthSq() === 0 ) {
 
 			// up and z are parallel
 
 			if ( Math.abs( up.z ) === 1 ) {
 
-				z.x += 0.0001;
+				_z.x += 0.0001;
 
 			} else {
 
-				z.z += 0.0001;
+				_z.z += 0.0001;
 
 			}
 
-			z.normalize();
-			x.crossVectors( up, z );
+			_z.normalize();
+			_x.crossVectors( up, _z );
 
 		}
 
-		x.normalize();
-		y.crossVectors( z, x );
+		_x.normalize();
+		_y.crossVectors( _z, _x );
 
-		te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
-		te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
-		te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
+		te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
+		te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
+		te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
 
 		return this;
 
@@ -430,17 +430,17 @@ Object.assign( Matrix4.prototype, {
 
 	applyToBufferAttribute: function ( attribute ) {
 
-		if ( v1 === undefined ) v1 = new Vector3();
+		if ( _v1 === undefined ) _v1 = new Vector3();
 
 		for ( var i = 0, l = attribute.count; i < l; i ++ ) {
 
-			v1.x = attribute.getX( i );
-			v1.y = attribute.getY( i );
-			v1.z = attribute.getZ( i );
+			_v1.x = attribute.getX( i );
+			_v1.y = attribute.getY( i );
+			_v1.z = attribute.getZ( i );
 
-			v1.applyMatrix4( this );
+			_v1.applyMatrix4( this );
 
-			attribute.setXYZ( i, v1.x, v1.y, v1.z );
+			attribute.setXYZ( i, _v1.x, _v1.y, _v1.z );
 
 		}
 
@@ -782,18 +782,18 @@ Object.assign( Matrix4.prototype, {
 
 	decompose: function ( position, quaternion, scale ) {
 
-		if ( m1 === undefined ) {
+		if ( _m1 === undefined ) {
 
-			m1 = new Matrix4();
-			v1 = new Vector3();
+			_m1 = new Matrix4();
+			_v1 = new Vector3();
 
 		}
 
 		var te = this.elements;
 
-		var sx = v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
-		var sy = v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
-		var sz = v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
+		var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
+		var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
+		var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
 
 		// if determine is negative, we need to invert one scale
 		var det = this.determinant();
@@ -804,25 +804,25 @@ Object.assign( Matrix4.prototype, {
 		position.z = te[ 14 ];
 
 		// scale the rotation part
-		m1.copy( this );
+		_m1.copy( this );
 
 		var invSX = 1 / sx;
 		var invSY = 1 / sy;
 		var invSZ = 1 / sz;
 
-		m1.elements[ 0 ] *= invSX;
-		m1.elements[ 1 ] *= invSX;
-		m1.elements[ 2 ] *= invSX;
+		_m1.elements[ 0 ] *= invSX;
+		_m1.elements[ 1 ] *= invSX;
+		_m1.elements[ 2 ] *= invSX;
 
-		m1.elements[ 4 ] *= invSY;
-		m1.elements[ 5 ] *= invSY;
-		m1.elements[ 6 ] *= invSY;
+		_m1.elements[ 4 ] *= invSY;
+		_m1.elements[ 5 ] *= invSY;
+		_m1.elements[ 6 ] *= invSY;
 
-		m1.elements[ 8 ] *= invSZ;
-		m1.elements[ 9 ] *= invSZ;
-		m1.elements[ 10 ] *= invSZ;
+		_m1.elements[ 8 ] *= invSZ;
+		_m1.elements[ 9 ] *= invSZ;
+		_m1.elements[ 10 ] *= invSZ;
 
-		quaternion.setFromRotationMatrix( m1 );
+		quaternion.setFromRotationMatrix( _m1 );
 
 		scale.x = sx;
 		scale.y = sy;

+ 40 - 40
src/math/Ray.js

@@ -4,9 +4,9 @@ import { Vector3 } from './Vector3.js';
  * @author bhouston / http://clara.io
  */
 
-var vector;
-var segCenter, segDir, diff;
-var diff, edge1, edge2, normal;
+var _vector;
+var _segCenter, _segDir, _diff;
+var _diff, _edge1, _edge2, _normal;
 
 function Ray( origin, direction ) {
 
@@ -64,9 +64,9 @@ Object.assign( Ray.prototype, {
 
 	recast: function ( t ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
-		this.origin.copy( this.at( t, vector ) );
+		this.origin.copy( this.at( t, _vector ) );
 
 		return this;
 
@@ -103,9 +103,9 @@ Object.assign( Ray.prototype, {
 
 	distanceSqToPoint: function ( point ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
-		var directionDistance = vector.subVectors( point, this.origin ).dot( this.direction );
+		var directionDistance = _vector.subVectors( point, this.origin ).dot( this.direction );
 
 		// point behind the ray
 
@@ -115,19 +115,19 @@ Object.assign( Ray.prototype, {
 
 		}
 
-		vector.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
+		_vector.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
 
-		return vector.distanceToSquared( point );
+		return _vector.distanceToSquared( point );
 
 	},
 
 	distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
 
-		if ( segCenter === undefined ) {
+		if ( _segCenter === undefined ) {
 
-			segCenter = new Vector3();
-			segDir = new Vector3();
-			diff = new Vector3();
+			_segCenter = new Vector3();
+			_segDir = new Vector3();
+			_diff = new Vector3();
 
 		}
 
@@ -138,15 +138,15 @@ Object.assign( Ray.prototype, {
 		// - The closest point on the ray
 		// - The closest point on the segment
 
-		segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
-		segDir.copy( v1 ).sub( v0 ).normalize();
-		diff.copy( this.origin ).sub( segCenter );
+		_segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
+		_segDir.copy( v1 ).sub( v0 ).normalize();
+		_diff.copy( this.origin ).sub( _segCenter );
 
 		var segExtent = v0.distanceTo( v1 ) * 0.5;
-		var a01 = - this.direction.dot( segDir );
-		var b0 = diff.dot( this.direction );
-		var b1 = - diff.dot( segDir );
-		var c = diff.lengthSq();
+		var a01 = - this.direction.dot( _segDir );
+		var b0 = _diff.dot( this.direction );
+		var b1 = - _diff.dot( _segDir );
+		var c = _diff.lengthSq();
 		var det = Math.abs( 1 - a01 * a01 );
 		var s0, s1, sqrDist, extDet;
 
@@ -240,7 +240,7 @@ Object.assign( Ray.prototype, {
 
 		if ( optionalPointOnSegment ) {
 
-			optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
+			optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
 
 		}
 
@@ -250,11 +250,11 @@ Object.assign( Ray.prototype, {
 
 	intersectSphere: function ( sphere, target ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
-		vector.subVectors( sphere.center, this.origin );
-		var tca = vector.dot( this.direction );
-		var d2 = vector.dot( vector ) - tca * tca;
+		_vector.subVectors( sphere.center, this.origin );
+		var tca = _vector.dot( this.direction );
+		var d2 = _vector.dot( _vector ) - tca * tca;
 		var radius2 = sphere.radius * sphere.radius;
 
 		if ( d2 > radius2 ) return null;
@@ -424,9 +424,9 @@ Object.assign( Ray.prototype, {
 
 	intersectsBox: function ( box ) {
 
-		if ( vector === undefined ) vector = new Vector3();
+		if ( _vector === undefined ) _vector = new Vector3();
 
-		return this.intersectBox( box, vector ) !== null;
+		return this.intersectBox( box, _vector ) !== null;
 
 	},
 
@@ -434,27 +434,27 @@ Object.assign( Ray.prototype, {
 
 		// Compute the offset origin, edges, and normal.
 
-		if ( diff === undefined ) {
+		if ( _diff === undefined ) {
 
-			diff = new Vector3();
-			edge1 = new Vector3();
-			edge2 = new Vector3();
-			normal = new Vector3();
+			_diff = new Vector3();
+			_edge1 = new Vector3();
+			_edge2 = new Vector3();
+			_normal = new Vector3();
 
 		}
 
 		// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
 
-		edge1.subVectors( b, a );
-		edge2.subVectors( c, a );
-		normal.crossVectors( edge1, edge2 );
+		_edge1.subVectors( b, a );
+		_edge2.subVectors( c, a );
+		_normal.crossVectors( _edge1, _edge2 );
 
 		// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
 		// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
 		//   |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
 		//   |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
 		//   |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
-		var DdN = this.direction.dot( normal );
+		var DdN = this.direction.dot( _normal );
 		var sign;
 
 		if ( DdN > 0 ) {
@@ -473,8 +473,8 @@ Object.assign( Ray.prototype, {
 
 		}
 
-		diff.subVectors( this.origin, a );
-		var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
+		_diff.subVectors( this.origin, a );
+		var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
 
 		// b1 < 0, no intersection
 		if ( DdQxE2 < 0 ) {
@@ -483,7 +483,7 @@ Object.assign( Ray.prototype, {
 
 		}
 
-		var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
+		var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
 
 		// b2 < 0, no intersection
 		if ( DdE1xQ < 0 ) {
@@ -500,7 +500,7 @@ Object.assign( Ray.prototype, {
 		}
 
 		// Line intersects triangle, check if ray does.
-		var QdN = - sign * diff.dot( normal );
+		var QdN = - sign * _diff.dot( _normal );
 
 		// t < 0, no intersection
 		if ( QdN < 0 ) {

+ 60 - 60
src/math/Triangle.js

@@ -5,8 +5,8 @@ import { Vector3 } from './Vector3.js';
  * @author mrdoob / http://mrdoob.com/
  */
 
-var v0, v1, v2, v3;
-var vab, vac, vbc, vap, vbp, vcp;
+var _v0, _v1, _v2, _v3;
+var _vab, _vac, _vbc, _vap, _vbp, _vcp;
 
 function Triangle( a, b, c ) {
 
@@ -20,7 +20,7 @@ Object.assign( Triangle, {
 
 	getNormal: function ( a, b, c, target ) {
 
-		if ( v0 === undefined ) v0 = new Vector3();
+		if ( _v0 === undefined ) _v0 = new Vector3();
 
 		if ( target === undefined ) {
 
@@ -30,8 +30,8 @@ Object.assign( Triangle, {
 		}
 
 		target.subVectors( c, b );
-		v0.subVectors( a, b );
-		target.cross( v0 );
+		_v0.subVectors( a, b );
+		target.cross( _v0 );
 
 		var targetLengthSq = target.lengthSq();
 		if ( targetLengthSq > 0 ) {
@@ -48,23 +48,23 @@ Object.assign( Triangle, {
 	// based on: http://www.blackpawn.com/texts/pointinpoly/default.html
 	getBarycoord: function ( point, a, b, c, target ) {
 
-		if ( v1 === undefined ) {
+		if ( _v1 === undefined ) {
 
-			 v0 = new Vector3();
-			 v1 = new Vector3();
-			 v2 = new Vector3();
+			_v0 = new Vector3();
+			_v1 = new Vector3();
+			_v2 = new Vector3();
 
 		}
 
-		v0.subVectors( c, a );
-		v1.subVectors( b, a );
-		v2.subVectors( point, a );
+		_v0.subVectors( c, a );
+		_v1.subVectors( b, a );
+		_v2.subVectors( point, a );
 
-		var dot00 = v0.dot( v0 );
-		var dot01 = v0.dot( v1 );
-		var dot02 = v0.dot( v2 );
-		var dot11 = v1.dot( v1 );
-		var dot12 = v1.dot( v2 );
+		var dot00 = _v0.dot( _v0 );
+		var dot01 = _v0.dot( _v1 );
+		var dot02 = _v0.dot( _v2 );
+		var dot11 = _v1.dot( _v1 );
+		var dot12 = _v1.dot( _v2 );
 
 		var denom = ( dot00 * dot11 - dot01 * dot01 );
 
@@ -95,24 +95,24 @@ Object.assign( Triangle, {
 
 	containsPoint: function ( point, a, b, c ) {
 
-		if ( v3 === undefined ) v3 = new Vector3();
+		if ( _v3 === undefined ) _v3 = new Vector3();
 
-		Triangle.getBarycoord( point, a, b, c, v3 );
+		Triangle.getBarycoord( point, a, b, c, _v3 );
 
-		return ( v3.x >= 0 ) && ( v3.y >= 0 ) && ( ( v3.x + v3.y ) <= 1 );
+		return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
 
 	},
 
 	getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
 
-		if ( v3 === undefined ) v3 = new Vector3();
+		if ( _v3 === undefined ) _v3 = new Vector3();
 
-		this.getBarycoord( point, p1, p2, p3, v3 );
+		this.getBarycoord( point, p1, p2, p3, _v3 );
 
 		target.set( 0, 0 );
-		target.addScaledVector( uv1, v3.x );
-		target.addScaledVector( uv2, v3.y );
-		target.addScaledVector( uv3, v3.z );
+		target.addScaledVector( uv1, _v3.x );
+		target.addScaledVector( uv2, _v3.y );
+		target.addScaledVector( uv3, _v3.z );
 
 		return target;
 
@@ -120,18 +120,18 @@ Object.assign( Triangle, {
 
 	isFrontFacing: function ( a, b, c, direction ) {
 
-		if ( v1 === undefined ) {
+		if ( _v1 === undefined ) {
 
-			v0 = new Vector3();
-			v1 = new Vector3();
+			_v0 = new Vector3();
+			_v1 = new Vector3();
 
 		}
 
-		v0.subVectors( c, b );
-		v1.subVectors( a, b );
+		_v0.subVectors( c, b );
+		_v1.subVectors( a, b );
 
 		// strictly front facing
-		return ( v0.cross( v1 ).dot( direction ) < 0 ) ? true : false;
+		return ( _v0.cross( _v1 ).dot( direction ) < 0 ) ? true : false;
 
 	}
 
@@ -177,17 +177,17 @@ Object.assign( Triangle.prototype, {
 
 	getArea: function () {
 
-		if ( v1 === undefined ) {
+		if ( _v1 === undefined ) {
 
-			v0 = new Vector3();
-			v1 = new Vector3();
+			_v0 = new Vector3();
+			_v1 = new Vector3();
 
 		}
 
-		v0.subVectors( this.c, this.b );
-		v1.subVectors( this.a, this.b );
+		_v0.subVectors( this.c, this.b );
+		_v1.subVectors( this.a, this.b );
 
-		return v0.cross( v1 ).length() * 0.5;
+		return _v0.cross( _v1 ).length() * 0.5;
 
 	},
 
@@ -255,14 +255,14 @@ Object.assign( Triangle.prototype, {
 
 	closestPointToPoint: function ( p, target ) {
 
-		if ( vab === undefined ) {
+		if ( _vab === undefined ) {
 
-			vab = new Vector3();
-			vac = new Vector3();
-			vbc = new Vector3();
-			vap = new Vector3();
-			vbp = new Vector3();
-			vcp = new Vector3();
+			_vab = new Vector3();
+			_vac = new Vector3();
+			_vbc = new Vector3();
+			_vap = new Vector3();
+			_vbp = new Vector3();
+			_vcp = new Vector3();
 
 		}
 
@@ -282,11 +282,11 @@ Object.assign( Triangle.prototype, {
 		// basically, we're distinguishing which of the voronoi regions of the triangle
 		// the point lies in with the minimum amount of redundant computation.
 
-		vab.subVectors( b, a );
-		vac.subVectors( c, a );
-		vap.subVectors( p, a );
-		var d1 = vab.dot( vap );
-		var d2 = vac.dot( vap );
+		_vab.subVectors( b, a );
+		_vac.subVectors( c, a );
+		_vap.subVectors( p, a );
+		var d1 = _vab.dot( _vap );
+		var d2 = _vac.dot( _vap );
 		if ( d1 <= 0 && d2 <= 0 ) {
 
 			// vertex region of A; barycentric coords (1, 0, 0)
@@ -294,9 +294,9 @@ Object.assign( Triangle.prototype, {
 
 		}
 
-		vbp.subVectors( p, b );
-		var d3 = vab.dot( vbp );
-		var d4 = vac.dot( vbp );
+		_vbp.subVectors( p, b );
+		var d3 = _vab.dot( _vbp );
+		var d4 = _vac.dot( _vbp );
 		if ( d3 >= 0 && d4 <= d3 ) {
 
 			// vertex region of B; barycentric coords (0, 1, 0)
@@ -309,13 +309,13 @@ Object.assign( Triangle.prototype, {
 
 			v = d1 / ( d1 - d3 );
 			// edge region of AB; barycentric coords (1-v, v, 0)
-			return target.copy( a ).addScaledVector( vab, v );
+			return target.copy( a ).addScaledVector( _vab, v );
 
 		}
 
-		vcp.subVectors( p, c );
-		var d5 = vab.dot( vcp );
-		var d6 = vac.dot( vcp );
+		_vcp.subVectors( p, c );
+		var d5 = _vab.dot( _vcp );
+		var d6 = _vac.dot( _vcp );
 		if ( d6 >= 0 && d5 <= d6 ) {
 
 			// vertex region of C; barycentric coords (0, 0, 1)
@@ -328,17 +328,17 @@ Object.assign( Triangle.prototype, {
 
 			w = d2 / ( d2 - d6 );
 			// edge region of AC; barycentric coords (1-w, 0, w)
-			return target.copy( a ).addScaledVector( vac, w );
+			return target.copy( a ).addScaledVector( _vac, w );
 
 		}
 
 		var va = d3 * d6 - d5 * d4;
 		if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
 
-			vbc.subVectors( c, b );
+			_vbc.subVectors( c, b );
 			w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
 			// edge region of BC; barycentric coords (0, 1-w, w)
-			return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
+			return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
 
 		}
 
@@ -348,7 +348,7 @@ Object.assign( Triangle.prototype, {
 		v = vb * denom;
 		w = vc * denom;
 
-		return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
+		return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
 
 	},