amamic1803 / tinydraw-rs

A small 2D drawing library in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small bug when drawing horizontal lines

antis81 opened this issue · comments

Trying out the tinydraw crate for some simple drawing task… There I noticed that when drawing completely horizontal lines only half of the line is visible. Here is a little code example visualizing this behaviour.

fn main() {                                                                                                                                                                                                                                                                     
    let width: u32 = 1920;
    let height: u32 = 1080;
    // let h_center = width / 2;
    let v_center = height / 2;
    let background: [u8; 3] = [64, 64, 128];
    let mut image = tinydraw::ImageRGB8::new(width as usize, height as usize, background);

    let bug_color: [u8; 3] = [255, 0, 0];
    image.draw_line(
        0,
        v_center as usize,
        width as usize,
        v_center as usize,
        bug_color,
        1,
        0.5,
    );

    let okay_color: [u8; 3] = [0, 255, 0];
    image.draw_line(
        0,
        v_center as usize - 50,
        width as usize,
        v_center as usize - 51, // FIXME: should also be -50
        okay_color,
        1,
        0.5,
    );

    image.to_png("output.png").unwrap();
}

And here is how it looks like.

output

The horizontal red line stops somewhere in the middle. The green line is just for reference and "fakes" a horizontal line (sets 1px off between y1 and y2).

I will take a look at it after Christmas. Was planning to make an update with some new features anyway. Thank you for reporting those issues.