Copy utils

This commit is contained in:
Andras Schmelczer 2023-04-29 21:18:27 +01:00
parent d8a3ae7528
commit a3f76f5c77
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
14 changed files with 141 additions and 3 deletions

21
src/utils/array.ts Normal file
View file

@ -0,0 +1,21 @@
/** @internal */
const setIndexAlias = (name: string, index: number, type: any) => {
if (!Object.prototype.hasOwnProperty.call(type.prototype, name)) {
Object.defineProperty(type.prototype, name, {
get() {
return this[index];
},
set(value) {
this[index] = value;
},
});
}
};
/** @internal */
export const applyArrayPlugins = () => {
setIndexAlias('x', 0, Array);
setIndexAlias('y', 1, Array);
setIndexAlias('x', 0, Float32Array);
setIndexAlias('y', 1, Float32Array);
};