aboutsummaryrefslogtreecommitdiff
path: root/lvc/src/debug.rs
blob: 0e6fb7ad8868cbff312236088c080fb2fe3e27de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::{split::split, Block, Frame, Pixel, View, P2};

pub fn draw_debug(frame: &mut Frame, view: View, block: &Block) {
    match block {
        Block::Lit(_) => rect(frame, view, Pixel::GREEN),
        Block::Split(a, b) => {
            let [av, bv] = split(view);
            draw_debug(frame, av, &a);
            draw_debug(frame, bv, &b);
        }
        Block::Ref(_r) => {}
    }
}

fn rect(frame: &mut Frame, view: View, color: Pixel) {
    for x in view.a.x..view.b.x {
        frame[P2 { x, y: view.a.y }] = color;
        frame[P2 { x, y: view.b.y - 1 }] = color;
    }
    for y in view.a.y..view.b.y {
        frame[P2 { y, x: view.a.x }] = color;
        frame[P2 { y, x: view.b.x - 1 }] = color;
    }
}

impl Pixel {
    pub const RED: Pixel = Pixel { r: 255, g: 0, b: 0 };
    pub const GREEN: Pixel = Pixel { r: 0, g: 255, b: 0 };
    pub const BLUE: Pixel = Pixel { r: 0, g: 0, b: 255 };
}