mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-09 14:32:07 -05:00
Implement a few math utilities
This commit is contained in:
parent
19da0b0032
commit
7db38e8422
1 changed files with 20 additions and 0 deletions
20
src/util/math-util.js
Normal file
20
src/util/math-util.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
function MathUtil () {}
|
||||||
|
|
||||||
|
MathUtil.degToRad = function (deg) {
|
||||||
|
return (Math.PI * (90 - deg)) / 180;
|
||||||
|
};
|
||||||
|
|
||||||
|
MathUtil.radToDeg = function (rad) {
|
||||||
|
return rad * 180 / Math.PI;
|
||||||
|
};
|
||||||
|
|
||||||
|
MathUtil.clamp = function (n, min, max) {
|
||||||
|
return Math.min(Math.max(n, min), max);
|
||||||
|
};
|
||||||
|
|
||||||
|
MathUtil.wrapClamp = function (n, min, max) {
|
||||||
|
var range = (max - min) + 1;
|
||||||
|
return n - Math.floor((n - min) / range) * range;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = MathUtil;
|
Loading…
Reference in a new issue