modeling/src/maths/mat4/isIdentity.js

  1. /**
  2. * Determine whether the given matrix is the identity transform.
  3. * This is equivalent to (but much faster than):
  4. *
  5. * mat4.equals(mat4.create(), matrix)
  6. *
  7. * @param {mat4} matrix - the matrix
  8. * @returns {Boolean} true if matrix is the identity transform
  9. * @alias module:modeling/maths/mat4.isIdentity
  10. * @example
  11. * if (mat4.isIdentity(mymatrix)) ...
  12. */
  13. const isIdentity = (matrix) => (
  14. matrix[0] === 1 && matrix[1] === 0 && matrix[2] === 0 && matrix[3] === 0 &&
  15. matrix[4] === 0 && matrix[5] === 1 && matrix[6] === 0 && matrix[7] === 0 &&
  16. matrix[8] === 0 && matrix[9] === 0 && matrix[10] === 1 && matrix[11] === 0 &&
  17. matrix[12] === 0 && matrix[13] === 0 && matrix[14] === 0 && matrix[15] === 1
  18. )
  19. module.exports = isIdentity