diff options
Diffstat (limited to 'evc/src/debug.rs')
-rw-r--r-- | evc/src/debug.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/evc/src/debug.rs b/evc/src/debug.rs index 7b27b83..cbc598e 100644 --- a/evc/src/debug.rs +++ b/evc/src/debug.rs @@ -1,4 +1,4 @@ -use crate::{frame::Frame, pixel::Pixel, view::View}; +use crate::{frame::Frame, pixel::Pixel, vec2::Vec2, view::View}; impl View<&mut Frame> { pub fn draw_box(&mut self, color: Pixel) { @@ -14,6 +14,28 @@ impl View<&mut Frame> { } } } + +impl Frame { + pub fn draw_line(&mut self, start: Vec2, end: Vec2, color: Pixel) { + let (sx, sy) = (start.x as f32, start.y as f32); + let (ex, ey) = (end.x as f32, end.y as f32); + let (dx, dy) = (ex - sx, ey - sy); + let len = (dx * dx + dy * dy).sqrt(); + let (nx, ny) = (dx / len, dy / len); + let (mut cx, mut cy) = (sx, sy); + let mut lc = 0.0; + while lc < len { + self[Vec2 { + x: cx as isize, + y: cy as isize, + }] = color; + lc += 0.5; + cx += nx * 0.5; + cy += ny * 0.5; + } + } +} + impl Pixel { pub const RED: Pixel = Pixel { r: 255, g: 0, b: 0 }; pub const GREEN: Pixel = Pixel { r: 0, g: 255, b: 0 }; |