Răsfoiți Sursa

Math: Renamed nearestPowerOfTwo() to floorPowerOfTwo() and nextPowerOfTwo() to ceilPowerOfTwo(). See 31e8e610b6ad86aca97c24c71fd4ebc6b5bfa259

Mr.doob 7 ani în urmă
părinte
comite
a264642204

+ 4 - 4
docs/api/math/Math.html

@@ -70,11 +70,11 @@
 		Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
 		</div>
 
-		<h3>[method:Integer nearestPowerOfTwo]( [page:Number n] )</h3>
-		<div>Returns the nearest power of 2 that is smaller or equal to [page:Number n].</div>
+		<h3>[method:Integer ceilPowerOfTwo]( [page:Number n] )</h3>
+		<div>Returns the smallest power of 2 that is greater than or equal to [page:Number n].</div>
 
-		<h3>[method:Integer nextPowerOfTwo]( [page:Number n] )</h3>
-		<div>Returns the nearest power of 2 that is bigger than [page:Number n].</div>
+		<h3>[method:Integer floorPowerOfTwo]( [page:Number n] )</h3>
+		<div>Returns the largest power of 2 that is less than or equal to [page:Number n].</div>
 
 		<h3>[method:Float radToDeg]( [page:Float radians] )</h3>
 		<div>Converts radians to degrees.</div>

+ 22 - 4
src/Three.Legacy.js

@@ -420,12 +420,30 @@ Line3.prototype.center = function ( optionalTarget ) {
 
 };
 
-_Math.random16 = function () {
+Object.assign( _Math, {
 
-	console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
-	return Math.random();
+	random16: function () {
 
-};
+		console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
+		return Math.random();
+
+	},
+
+	nearestPowerOfTwo: function ( value ) {
+
+		console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
+		return _Math.floorPowerOfTwo( value );
+
+	},
+
+	nextPowerOfTwo: function ( value ) {
+
+		console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
+		return _Math.ceilPowerOfTwo( value );
+
+	}
+
+} );
 
 Object.assign( Matrix3.prototype, {
 

+ 4 - 12
src/math/Math.js

@@ -142,23 +142,15 @@ var _Math = {
 
 	},
 
-	nearestPowerOfTwo: function ( value ) {
+	ceilPowerOfTwo: function ( value ) {
 
-		return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
+		return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
 
 	},
 
-	nextPowerOfTwo: function ( value ) {
-
-		value --;
-		value |= value >> 1;
-		value |= value >> 2;
-		value |= value >> 4;
-		value |= value >> 8;
-		value |= value >> 16;
-		value ++;
+	floorPowerOfTwo: function ( value ) {
 
-		return value;
+		return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
 
 	}
 

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -1717,7 +1717,7 @@ function WebGLRenderer( parameters ) {
 
 
 						var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
-						size = _Math.nextPowerOfTwo( Math.ceil( size ) );
+						size = _Math.ceilPowerOfTwo( size );
 						size = Math.max( size, 4 );
 
 						var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel

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

@@ -48,8 +48,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 		if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
 
 			var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
-			canvas.width = _Math.nearestPowerOfTwo( image.width );
-			canvas.height = _Math.nearestPowerOfTwo( image.height );
+			canvas.width = _Math.floorPowerOfTwo( image.width );
+			canvas.height = _Math.floorPowerOfTwo( image.height );
 
 			var context = canvas.getContext( '2d' );
 			context.drawImage( image, 0, 0, canvas.width, canvas.height );