From ee43638cbc1652c98862af4801a06063a94b0db6 Mon Sep 17 00:00:00 2001 From: sthag Date: Sun, 1 Mar 2026 11:44:19 +0100 Subject: [PATCH] feat: Add global function to map values --- source/code/hippie/app.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/code/hippie/app.js b/source/code/hippie/app.js index 81d2494..d5f077f 100644 --- a/source/code/hippie/app.js +++ b/source/code/hippie/app.js @@ -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