diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-26 20:39:39 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-26 20:46:34 +0100 |
commit | 99d37947496695b20c3a5db7464710a821b26a7a (patch) | |
tree | cd60529607f4524f860d7636a1160a5b9bccd75d /src/main.cpp | |
parent | 096c1089ca5ff836c52fee95451480e0a293155b (diff) | |
download | cw_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)
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 7 |
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) { |