MCPcopy Index your code
hub / github.com/processing/p5.js / #createIdentityMatrix

Method #createIdentityMatrix

src/math/Matrices/Matrix.js:1619–1633  ·  view source on GitHub ↗

* Creates identity matrix * This method updates the current matrix with the result of the multiplication. * * @private

(dimension)

Source from the content-addressed store, hash-verified

1617 * @private
1618 */
1619 #createIdentityMatrix(dimension) {
1620 // This it to prevent loops in the most common 3x3 and 4x4 cases
1621 // TODO: check performance if it actually helps
1622 if (dimension === 3)
1623 return new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 1, 0, 0, 0, 1]);
1624 if (dimension === 4)
1625 return new GLMAT_ARRAY_TYPE([
1626 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
1627 ]);
1628 const identityMatrix = new GLMAT_ARRAY_TYPE(dimension * dimension).fill(0);
1629 for (let i = 0; i < dimension; i++) {
1630 identityMatrix[i * dimension + i] = 1;
1631 }
1632 return identityMatrix;
1633 }
1634
1635 /**
1636 * Multiplies the current 4x4 matrix with another 4x4 matrix.

Callers 2

constructorMethod · 0.95
resetMethod · 0.95

Calls 1

fillMethod · 0.45

Tested by

no test coverage detected