Parcourir la source

Moved arrayMin and arrayMax out of _Math. See #10603.

Mr.doob il y a 8 ans
Parent
commit
933f4cae14
4 fichiers modifiés avec 44 ajouts et 42 suppressions
  1. 3 2
      src/core/BufferGeometry.js
  2. 0 38
      src/math/Math.js
  3. 2 2
      src/renderers/webgl/WebGLObjects.js
  4. 39 0
      src/utils.js

+ 3 - 2
src/core/BufferGeometry.js

@@ -8,6 +8,7 @@ import { Object3D } from './Object3D';
 import { Matrix4 } from '../math/Matrix4';
 import { Matrix3 } from '../math/Matrix3';
 import { _Math } from '../math/Math';
+import { arrayMax } from '../utils';
 import { GeometryIdCount } from './Geometry';
 
 /**
@@ -54,7 +55,7 @@ BufferGeometry.prototype = {
 
 		if ( Array.isArray( index ) ) {
 
-			this.index = new ( _Math.arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
+			this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
 
 		} else {
 
@@ -516,7 +517,7 @@ BufferGeometry.prototype = {
 
 		if ( geometry.indices.length > 0 ) {
 
-			var TypeArray = _Math.arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
+			var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
 			var indices = new TypeArray( geometry.indices.length * 3 );
 			this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
 

+ 0 - 38
src/math/Math.js

@@ -45,44 +45,6 @@ var _Math = {
 
 	}(),
 
-	// http://stackoverflow.com/questions/1669190/javascript-min-max-array-values/13440842#13440842
-
-	arrayMin: function ( array ) {
-
-		var length = array.length, min = Infinity;
-
-		while ( length -- ) {
-
-			if ( array[ length ] < min ) {
-
-				min = array[ length ];
-
-			}
-
-		}
-
-		return min;
-
-	},
-
-	arrayMax: function ( array ) {
-
-		var length = array.length, max = - Infinity;
-
-		while ( length -- ) {
-
-			if ( array[ length ] > max ) {
-
-				max = array[ length ];
-
-			}
-
-		}
-
-		return max;
-
-	},
-
 	clamp: function ( value, min, max ) {
 
 		return Math.max( min, Math.min( max, value ) );

+ 2 - 2
src/renderers/webgl/WebGLObjects.js

@@ -3,7 +3,7 @@
  */
 
 import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute';
-import { _Math } from '../../math/Math';
+import { arrayMax } from '../../utils';
 import { WebGLGeometries } from './WebGLGeometries';
 
 function WebGLObjects( gl, properties, info ) {
@@ -235,7 +235,7 @@ function WebGLObjects( gl, properties, info ) {
 
 		// console.timeEnd( 'wireframe' );
 
-		var attribute = new ( _Math.arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
+		var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
 
 		updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
 

+ 39 - 0
src/utils.js

@@ -0,0 +1,39 @@
+// http://stackoverflow.com/questions/1669190/javascript-min-max-array-values/13440842#13440842
+
+function arrayMin( array ) {
+
+	var length = array.length, min = Infinity;
+
+	while ( length -- ) {
+
+		if ( array[ length ] < min ) {
+
+			min = array[ length ];
+
+		}
+
+	}
+
+	return min;
+
+}
+
+function arrayMax( array ) {
+
+	var length = array.length, max = - Infinity;
+
+	while ( length -- ) {
+
+		if ( array[ length ] > max ) {
+
+			max = array[ length ];
+
+		}
+
+	}
+
+	return max;
+
+}
+
+export { arrayMin, arrayMax };