@@ -244,8 +244,8 @@ Phaser.Math = {
244244
245245 if ( typeof radians === "undefined" ) { radians = true ; }
246246
247- var rd = ( radians ) ? GameMath . PI : 180 ;
248- return this . wrap ( angle , rd , - rd ) ;
247+ var rd = ( radians ) ? Math . PI : 180 ;
248+ return this . wrap ( angle , - rd , rd ) ;
249249
250250 } ,
251251
@@ -257,7 +257,7 @@ Phaser.Math = {
257257
258258 if ( typeof radians === "undefined" ) { radians = true ; }
259259
260- var rd = ( radians ) ? GameMath . PI : 180 ;
260+ var rd = ( radians ) ? Math . PI : 180 ;
261261 a1 = this . normalizeAngle ( a1 , radians ) ;
262262 a2 = this . normalizeAngle ( a2 , radians ) ;
263263
@@ -387,15 +387,39 @@ Phaser.Math = {
387387
388388 } ,
389389
390- /**
391- * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
392- * <p>Values must be positive integers, and are passed through Math.abs</p>
393- *
394- * @param value The value to add the amount to
395- * @param amount The amount to add to the value
396- * @param max The maximum the value is allowed to be
397- * @return The wrapped value
398- */
390+ /**
391+ * Ensures that the value always stays between min and max, by wrapping the value around.
392+ * <p>max should be larger than min, or the function will return 0</p>
393+ *
394+ * @param value The value to wrap
395+ * @param min The minimum the value is allowed to be
396+ * @param max The maximum the value is allowed to be
397+ * @return The wrapped value
398+ */
399+ wrap : function ( value , min , max ) {
400+
401+ var range = max - min ;
402+ if ( range <= 0 )
403+ {
404+ return 0 ;
405+ }
406+ var result = ( value - min ) % range ;
407+ if ( result < 0 )
408+ {
409+ result += range ;
410+ }
411+ return result + min ;
412+ } ,
413+
414+ /**
415+ * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
416+ * <p>Values must be positive integers, and are passed through Math.abs</p>
417+ *
418+ * @param value The value to add the amount to
419+ * @param amount The amount to add to the value
420+ * @param max The maximum the value is allowed to be
421+ * @return The wrapped value
422+ */
399423 wrapValue : function ( value , amount , max ) {
400424
401425 var diff ;
0 commit comments