aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 20:39:39 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 20:46:34 +0100
commit99d37947496695b20c3a5db7464710a821b26a7a (patch)
treecd60529607f4524f860d7636a1160a5b9bccd75d
parent096c1089ca5ff836c52fee95451480e0a293155b (diff)
downloadcw_tree-99d37947496695b20c3a5db7464710a821b26a7a.tar.gz
cw_tree-99d37947496695b20c3a5db7464710a821b26a7a.tar.bz2
cw_tree-99d37947496695b20c3a5db7464710a821b26a7a.zip
Helper to convert a value in (min, max) to an equivalent in (0, width)
-rw-r--r--src/main.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 065f98a..f33fb55 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -47,6 +47,13 @@ Node leftmost_node(const NodeAllocator &allocator)
return node;
}
+constexpr word_t clamp_to_width(long double value, long double min,
+ long double max)
+{
+ // translate v in [min, max] -> v' in [0, WIDTH]
+ // [min, max] -> [0, max-min] -> [0, WIDTH]
+ return WIDTH / (max - min) * (value - min);
+}
int main(void)
{