common.js 1.6 KB

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