all files / src/ math.js

16.67% Statements 1/6
16.67% Branches 2/12
25% Functions 1/4
16.67% Lines 1/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                                           
// Based on THREE.JS
function clamp (x, a, b) {
  return (x < a) ? a : ((x > b) ? b : x);
}
 
function degToRad (degrees) {
  const degreeToRadiansFactor = Math.PI / 180;
 
 
  return degrees * degreeToRadiansFactor;
}
 
function radToDeg (radians) {
  const radianToDegreesFactor = 180 / Math.PI;
 
 
  return radians * radianToDegreesFactor;
}
 
// Returns sign of number
function sign (x) {
  return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
}
 
export {
  clamp,
  degToRad,
  radToDeg,
  sign
};