Skip to content

Commit b31cd28

Browse files
committed
Only copy array when necessary
1 parent 10a2d43 commit b31cd28

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/math/Matrices/Matrix.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Vector } from '../p5.Vector';
66
import { MatrixInterface } from './MatrixInterface';
77

88
const isPerfectSquare = arr => {
9-
const sqDimention = Math.sqrt(Array.from(arr).length);
9+
const sqDimention = Math.sqrt(arr.length);
1010
if (sqDimention % 1 !== 0) {
1111
throw new Error('Array length must be a perfect square.');
1212
}
@@ -29,7 +29,7 @@ export class Matrix extends MatrixInterface {
2929
// This is default behavior when object
3030
// instantiated using createMatrix()
3131
if (isMatrixArray(args[0]) && isPerfectSquare(args[0])) {
32-
const sqDimention = Math.sqrt(Array.from(args[0]).length);
32+
const sqDimention = Math.sqrt(args[0].length);
3333
this.#sqDimention = sqDimention;
3434
this.matrix = GLMAT_ARRAY_TYPE.from(args[0]);
3535
} else if (typeof args[0] === 'number') {
@@ -568,7 +568,7 @@ export class Matrix extends MatrixInterface {
568568
_src = multMatrix.matrix;
569569
} else if (isMatrixArray(multMatrix) && isPerfectSquare(multMatrix)) {
570570
_src = multMatrix;
571-
} else if (isPerfectSquare(arguments)) {
571+
} else if (isPerfectSquare(Array.from(arguments))) {
572572
_src = Array.from(arguments);
573573
} else {
574574
return; // nothing to do.

0 commit comments

Comments
 (0)