Skip to content

Commit

Permalink
Merge pull request #7405 from holomorfo/matrix-api
Browse files Browse the repository at this point in the history
[p5.js 2.0] Vector n-dimentional and Matrix Interface
  • Loading branch information
limzykenneth authored Dec 17, 2024
2 parents 90df6cc + c24eecd commit b89ac5b
Show file tree
Hide file tree
Showing 17 changed files with 3,920 additions and 2,145 deletions.
1,322 changes: 1,322 additions & 0 deletions src/math/Matrices/Matrix.js

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions src/math/Matrices/MatrixInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export let GLMAT_ARRAY_TYPE = Array;
export let isMatrixArray = (x) => Array.isArray(x);
if (typeof Float32Array !== "undefined") {
GLMAT_ARRAY_TYPE = Float32Array;
isMatrixArray = (x) => Array.isArray(x) || x instanceof Float32Array;
}
export class MatrixInterface {
// Private field to store the matrix
#matrix = null;
constructor(...args) {
if (this.constructor === MatrixInterface) {
throw new Error("Class is of abstract type and can't be instantiated");
}
const methods = [
"add",
"setElement",
"reset",
"set",
"get",
"copy",
"clone",
"diagonal",
"row",
"column",
"transpose",
"mult",
"multiplyVec",
"invert",
"createSubMatrix3x3",
"inverseTranspose4x4",
"apply",
"scale",
"rotate4x4",
"translate",
"rotateX",
"rotateY",
"rotateZ",
"perspective",
"ortho",
"multiplyVec4",
"multiplyPoint",
"multiplyAndNormalizePoint",
"multiplyDirection",
"multiplyVec3",
];

methods.forEach((method) => {
if (this[method] === undefined) {
throw new Error(`${method}() method must be implemented`);
}
});
}
}
Loading

0 comments on commit b89ac5b

Please sign in to comment.