Source: lib/gl-matrix/dist/esm/common.js

  1. /**
  2. * @file
  3. *
  4. * Summary.
  5. * <p>High performance matrix and vector operations.</p>
  6. *
  7. * @author Brandon Jones
  8. * @author Colin MacKenzie IV
  9. * @version 3.4.0
  10. *
  11. * @copyright (c) 2015-2021, Brandon Jones, Colin MacKenzie IV.
  12. * @see <a href="/cwdc/13-webgl/lib/gl-matrix">source</a>
  13. */
  14. /**
  15. * Common utilities
  16. * @module glMatrix
  17. */
  18. // Configuration Constants
  19. export var EPSILON = 0.000001;
  20. export var ARRAY_TYPE =
  21. typeof Float32Array !== "undefined" ? Float32Array : Array;
  22. export var RANDOM = Math.random;
  23. export var ANGLE_ORDER = "zyx";
  24. /**
  25. * Sets the type of array used when creating new vectors and matrices
  26. *
  27. * @param {Float32ArrayConstructor | ArrayConstructor} type Array type, such as Float32Array or Array
  28. */
  29. export function setMatrixArrayType(type) {
  30. ARRAY_TYPE = type;
  31. }
  32. var degree = Math.PI / 180;
  33. /**
  34. * Convert Degree To Radian
  35. *
  36. * @param {Number} a Angle in Degrees
  37. */
  38. export function toRadian(a) {
  39. return a * degree;
  40. }
  41. /**
  42. * Tests whether or not the arguments have approximately the same value, within an absolute
  43. * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less
  44. * than or equal to 1.0, and a relative tolerance is used for larger values)
  45. *
  46. * @param {Number} a The first number to test.
  47. * @param {Number} b The second number to test.
  48. * @returns {Boolean} True if the numbers are approximately equal, false otherwise.
  49. */
  50. export function equals(a, b) {
  51. return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
  52. }
  53. if (!Math.hypot)
  54. Math.hypot = function () {
  55. var y = 0,
  56. i = arguments.length;
  57. while (i--) {
  58. y += arguments[i] * arguments[i];
  59. }
  60. return Math.sqrt(y);
  61. };