LoRaWAN-Signal-Mapping/common/Math.mjs

24 lines
647 B
JavaScript
Raw Permalink Normal View History

"use strict";
function normalise(value, { min : input_min, max: input_max }, { min : output_min, max: output_max }) {
return (
((value - input_min) / (input_max - input_min)) * (output_max - output_min)
) + output_min
}
/**
* Clamps a value to fit within the specified bounds.
* @param {number} value The number to clamp.
* @param {number} min The minimum value the number can be.
* @param {number} max The maximum value the number can be.
* @return {number} The clamped number.
*/
function clamp(value, min, max) {
if(value > max) return max;
if(value < min) return min;
return value;
}
export { normalise, clamp };