From 99d37947496695b20c3a5db7464710a821b26a7a Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 26 Jul 2024 20:39:39 +0100 Subject: Helper to convert a value in (min, max) to an equivalent in (0, width) --- src/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') 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) { -- cgit v1.2.3-13-gbd6f