common.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Common utilities
  3. * @module glMatrix
  4. */
  5. // Configuration Constants
  6. export var EPSILON = 0.000001;
  7. export var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  8. export var RANDOM = Math.random;
  9. /**
  10. * Sets the type of array used when creating new vectors and matrices
  11. *
  12. * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array
  13. */
  14. export function setMatrixArrayType(type) {
  15. ARRAY_TYPE = type;
  16. }
  17. var degree = Math.PI / 180;
  18. /**
  19. * Convert Degree To Radian
  20. *
  21. * @param {Number} a Angle in Degrees
  22. */
  23. export function toRadian(a) {
  24. return a * degree;
  25. }
  26. /**
  27. * Tests whether or not the arguments have approximately the same value, within an absolute
  28. * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less
  29. * than or equal to 1.0, and a relative tolerance is used for larger values)
  30. *
  31. * @param {Number} a The first number to test.
  32. * @param {Number} b The second number to test.
  33. * @returns {Boolean} True if the numbers are approximately equal, false otherwise.
  34. */
  35. export function equals(a, b) {
  36. return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
  37. }
  38. if (!Math.hypot) Math.hypot = function () {
  39. var y = 0,
  40. i = arguments.length;
  41. while (i--) {
  42. y += arguments[i] * arguments[i];
  43. }
  44. return Math.sqrt(y);
  45. };