summaryrefslogtreecommitdiffstats
path: root/src/misc.c
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-08-08 08:10:17 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-08-08 08:10:17 +0300
commit1d1796c97867ada2211a39b313ef6398297c7b8f (patch)
tree927e9c477d7a974fb219ed9963fced6ea8109b5c /src/misc.c
parent884bac2a767bf5bf77413c055a6484a7ea87700c (diff)
downloada3catragmx-1d1796c97867ada2211a39b313ef6398297c7b8f.tar.gz
a3catragmx-1d1796c97867ada2211a39b313ef6398297c7b8f.tar.bz2
a3catragmx-1d1796c97867ada2211a39b313ef6398297c7b8f.zip
upd: tmp
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/misc.c b/src/misc.c
new file mode 100644
index 0000000..a01a70d
--- /dev/null
+++ b/src/misc.c
@@ -0,0 +1,23 @@
+#include "misc.h"
+
+double linearConversion(double min_from, double max_from, double value,
+ double min_to, double max_to, bool clip) {
+ // prevent division by zero
+ if (max_from == min_from) {
+ return min_to;
+ }
+
+ // main formula
+ double result = min_to + (value - min_from) * (max_to - min_to) / (max_from - min_from);
+
+ // check clipping
+ if (clip) {
+ if (result < min_to) {
+ result = min_to;
+ } else if (result > max_to) {
+ result = max_to;
+ }
+ }
+
+ return result;
+}