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.
This commit is contained in:
13
src/main.cpp
13
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};
|
||||
|
||||
Reference in New Issue
Block a user