Prechádzať zdrojové kódy

Use euclideanModulo in MathUtils.pingPong

Marco Fugaro 4 rokov pred
rodič
commit
c214c8a5ba

+ 1 - 1
src/math/MathUtils.js

@@ -66,7 +66,7 @@ const MathUtils = {
 
 	pingPong: function ( x, length = 1 ) {
 
-		return length - Math.abs( x % ( length * 2 ) - length );
+		return length - Math.abs( MathUtils.euclideanModulo( x, length * 2 ) - length );
 
 	},
 

+ 1 - 1
test/unit/src/math/MathUtils.tests.js

@@ -157,7 +157,7 @@ export default QUnit.module( 'Maths', () => {
 
 			assert.strictEqual( MathUtils.pingPong( 2.5 ), 0.5, "Value at 2.5 is 0.5" );
 			assert.strictEqual( MathUtils.pingPong( 2.5, 2 ), 1.5, "Value at 2.5 with length of 2 is 1.5" );
-			assert.strictEqual( MathUtils.pingPong( - 2 ), 0, "Value at -2 is 0" );
+			assert.strictEqual( MathUtils.pingPong( - 1.5 ), 0.5, "Value at -1.5 is 0.5" );
 
 		} );