aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 20:46:39 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 20:46:39 +0100
commit01468f793fb0566caab9daf0a6a39532f7808b8c (patch)
tree9ff7a9468bcd6136a41222bc30233062b84ee021 /src/main.cpp
parent3a911db3127165cfb0837457ebd9df1d421d86bc (diff)
downloadcw_tree-01468f793fb0566caab9daf0a6a39532f7808b8c.tar.gz
cw_tree-01468f793fb0566caab9daf0a6a39532f7808b8c.tar.bz2
cw_tree-01468f793fb0566caab9daf0a6a39532f7808b8c.zip
recursive function to draw tree in a number line
Draws the current node by converting its norm value (which is in (lower, upper)) to a screen value, drawing a line there. It then recurs on the children of the node.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index aae5b72..cec3b5e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -63,6 +63,19 @@ void draw_fraction(Fraction f, word_t x, word_t y)
DrawText(s.c_str(), x - width / 2, y - FONT_SIZE, FONT_SIZE, WHITE);
}
+void draw_node_number_line(index_t index, const NodeAllocator &allocator,
+ long double lower, long double upper)
+{
+ if (index.has_value())
+ {
+ Node n = allocator.getVal(index.value());
+ word_t x = clamp_to_width(n.value.norm, lower, upper);
+ DrawLine(x, LINE_TOP, x, LINE_BOTTOM, index.value() == 0 ? GREEN : RED);
+ draw_node_number_line(n.left, allocator, lower, upper);
+ draw_node_number_line(n.right, allocator, lower, upper);
+ }
+}
+
int main(void)
{
// NodeAllocator allocator{256};