feat: Add global function to map values
This commit is contained in:
parent
56633b364e
commit
ee43638cbc
1 changed files with 16 additions and 0 deletions
|
|
@ -523,6 +523,22 @@ function capitalizeFirstLetter(text) {
|
|||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
|
||||
function mapRange(value, inMin, inMax, outMin, outMax, reverse = false, clamp = false) {
|
||||
let min = outMin;
|
||||
let max = outMax;
|
||||
|
||||
if (reverse) {
|
||||
[min, max] = [max, min];
|
||||
}
|
||||
|
||||
const mapped = (value - inMin) * (max - min) / (inMax - inMin) + min;
|
||||
|
||||
if (clamp) {
|
||||
return Math.max(Math.min(min, max), Math.min(Math.max(min, max), mapped));
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// CONCEPTS
|
||||
|
||||
// NOTE: Benutzt private Zuweisungen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue