phaser/src/math/Wrap.js

27 lines
647 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2017-10-06 05:16:31 +00:00
/**
* Wrap the given `value` between `min` and `max.
2017-10-06 05:16:31 +00:00
*
* @function Phaser.Math.Wrap
* @since 3.0.0
*
* @param {number} value - The value to wrap.
* @param {number} min - The minimum value.
* @param {number} max - The maximum value.
2017-10-06 05:16:31 +00:00
*
* @return {number} The wrapped value.
2017-10-06 05:16:31 +00:00
*/
var Wrap = function (value, min, max)
{
var range = max - min;
return (min + ((((value - min) % range) + range) % range));
};
module.exports = Wrap;