From 950706fdaf3f6bc9a94d881f79dfe244261c15ad Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 26 Jul 2024 21:00:34 +0100 Subject: 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. --- src/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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}; -- cgit v1.2.3-13-gbd6f