Source: common.js

  1. /**
  2. * Common utilities
  3. * @module glMatrix
  4. */
  5. // Configuration Constants
  6. export const EPSILON = 0.000001;
  7. export let ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
  8. export const RANDOM = Math.random;
  9. /**
  10. * Sets the type of array used when creating new vectors and matrices
  11. *
  12. * @param {Type} type Array type, such as Float32Array or Array
  13. */
  14. export function setMatrixArrayType(type) {
  15. ARRAY_TYPE = type;
  16. }
  17. const 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. }