Add glMatrix

This commit is contained in:
schmelczerandras 2020-07-22 20:00:57 +02:00
parent 582979d3ed
commit e88b4589d2
26 changed files with 211 additions and 358 deletions

View file

@ -0,0 +1,49 @@
declare global {
interface Array<T> {
x: number;
y: number;
}
interface Float32Array {
x: number;
y: number;
}
}
export const applyArrayPlugins = () => {
Object.defineProperty(Array.prototype, 'x', {
get: function () {
return this[0];
},
set: function (value) {
this[0] = value;
},
});
Object.defineProperty(Array.prototype, 'y', {
get: function () {
return this[1];
},
set: function (value) {
this[1] = value;
},
});
Object.defineProperty(Float32Array.prototype, 'x', {
get: function () {
return this[0];
},
set: function (value) {
this[0] = value;
},
});
Object.defineProperty(Float32Array.prototype, 'y', {
get: function () {
return this[1];
},
set: function (value) {
this[1] = value;
},
});
};

View file

@ -0,0 +1,4 @@
export const clamp = (value: number, min: number, max: number): number =>
Math.min(max, Math.max(min, value));
export const clamp01 = (value: number): number => clamp(value, 0, 1);