@nodescript/stdlib
Version:
Standard Node Definitions
32 lines (31 loc) • 852 B
JavaScript
export const module = {
version: '1.0.4',
moduleName: 'Math / Map Range',
description: `
Computes a linear mapping of specified value from one range to another.
`,
params: {
value: {
schema: { type: 'number', default: 0.5 },
},
fromMin: {
schema: { type: 'number', default: 0 },
},
fromMax: {
schema: { type: 'number', default: 1 },
},
toMin: {
schema: { type: 'number', default: 0 },
},
toMax: {
schema: { type: 'number', default: 1 },
},
},
result: {
schema: { type: 'number' },
}
};
export const compute = params => {
const { value, fromMin, fromMax, toMin, toMax } = params;
return toMin + (value - fromMin) * (toMax - toMin) / (fromMax - fromMin);
};