matricesDiffer.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. */
  9. 'use strict';
  10. /**
  11. * Unrolls an array comparison specially for matrices. Prioritizes
  12. * checking of indices that are most likely to change so that the comparison
  13. * bails as early as possible.
  14. *
  15. * @param {MatrixMath.Matrix} one First matrix.
  16. * @param {MatrixMath.Matrix} two Second matrix.
  17. * @return {boolean} Whether or not the two matrices differ.
  18. */
  19. const matricesDiffer = function(one, two) {
  20. if (one === two) {
  21. return false;
  22. }
  23. return (
  24. !one ||
  25. !two ||
  26. one[12] !== two[12] ||
  27. one[13] !== two[13] ||
  28. one[14] !== two[14] ||
  29. one[5] !== two[5] ||
  30. one[10] !== two[10] ||
  31. one[0] !== two[0] ||
  32. one[1] !== two[1] ||
  33. one[2] !== two[2] ||
  34. one[3] !== two[3] ||
  35. one[4] !== two[4] ||
  36. one[6] !== two[6] ||
  37. one[7] !== two[7] ||
  38. one[8] !== two[8] ||
  39. one[9] !== two[9] ||
  40. one[11] !== two[11] ||
  41. one[15] !== two[15]
  42. );
  43. };
  44. module.exports = matricesDiffer;