diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-26 21:00:34 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-07-26 21:00:34 +0100 |
commit | 950706fdaf3f6bc9a94d881f79dfe244261c15ad (patch) | |
tree | 2ab974b8f2c39c1b2b764c96d4a22404d4485b0a | |
parent | 89fd8129817a245afdd758446ffb002467e0815f (diff) | |
download | cw_tree-950706fdaf3f6bc9a94d881f79dfe244261c15ad.tar.gz cw_tree-950706fdaf3f6bc9a94d881f79dfe244261c15ad.tar.bz2 cw_tree-950706fdaf3f6bc9a94d881f79dfe244261c15ad.zip |
Function to draw the complete number line
Draws a guide line, computes bounds (which we should defer), draws all
nodes in the tree then draws the bounds.
-rw-r--r-- | src/main.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 808e5ea..2fefb17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,6 +82,28 @@ void draw_node_number_line(const NodeAllocator &allocator, long double lower, } } +void draw_number_line(const NodeAllocator &allocator) +{ + // Draw a general guide number line + DrawLine(0, HEIGHT / 2, WIDTH, HEIGHT / 2, WHITE); + // Figure out the leftmost and rightmost nodes for bounds + const auto right = rightmost_node(allocator); + const auto left = leftmost_node(allocator); + const auto upper_bound = std::ceill(right.value.norm); + const auto lower_bound = std::floorl(left.value.norm); + + // Draw all the nodes + draw_node_number_line(allocator, lower_bound, upper_bound); + + // Draw the bounds, with their values, in white + word_t lower_x = clamp_to_width(left.value.norm, lower_bound, upper_bound); + word_t upper_x = clamp_to_width(right.value.norm, lower_bound, upper_bound); + draw_fraction(left.value, lower_x, 3 * HEIGHT / 8); + draw_fraction(right.value, upper_x, 3 * HEIGHT / 8); + DrawLine(lower_x, LINE_TOP, lower_x, LINE_BOTTOM, WHITE); + DrawLine(upper_x, LINE_TOP, upper_x, LINE_BOTTOM, WHITE); +} + int main(void) { // NodeAllocator allocator{256}; |