Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[p5.js 2.0] Vector n-dimentional and Matrix Interface #7405

Merged
merged 9 commits into from
Dec 17, 2024
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
Loading