diff options
Diffstat (limited to 'evc/src/debug.rs')
-rw-r--r-- | evc/src/debug.rs | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/evc/src/debug.rs b/evc/src/debug.rs index c3ea7d0..96f5777 100644 --- a/evc/src/debug.rs +++ b/evc/src/debug.rs @@ -24,24 +24,18 @@ impl View<&mut Frame> { impl Frame { pub fn draw_line(&mut self, start: Vec2<f32>, end: Vec2<f32>, 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 diff = end - start; + let len = (diff.x * diff.x + diff.y * diff.y).sqrt(); + let normal = Vec2 { + x: diff.x / len, + y: diff.y / len, + }; + let mut cursor = start.clone(); let mut lc = 0.0; while lc < len { - self.set( - Vec2 { - x: cx as isize, - y: cy as isize, - }, - color, - ); + self.set(cursor.into(), color); lc += 0.5; - cx += nx * 0.5; - cy += ny * 0.5; + cursor = cursor + normal.scale(0.5); } } } @@ -91,17 +85,22 @@ pub fn draw_debug(block: &Block, mut target: View<&mut Frame>) { x: map_scalar8(r.translation.x), y: map_scalar8(r.translation.y), }; - let tl = mat.transform(translation) + target.offset.into(); - let tr = - mat.transform(translation + target.size.x_only().into()) + target.offset.into(); - let bl = - mat.transform(translation + target.size.y_only().into()) + target.offset.into(); - let br = mat.transform(translation + target.size.into()) + target.offset.into(); + let halfsize = Into::<Vec2<f32>>::into(target.size).scale(0.5); + let transform = |p| translation + mat.transform(p - halfsize) + halfsize; + let (tl, tr, bl, br) = ( + transform(Vec2::<f32>::ZERO) + target.offset.into(), + transform(target.size.x_only().into()) + target.offset.into(), + transform(target.size.y_only().into()) + target.offset.into(), + transform(target.size.into()) + target.offset.into(), + ); + if tl.y != tr.y || tl.x != bl.x { + eprintln!("{tl:?} {tr:?} {bl:?} {br:?}"); + } + target.draw_box(Pixel::CYAN); target.frame.draw_line(tl, tr, Pixel::MAGENTA); target.frame.draw_line(tr, br, Pixel::MAGENTA); target.frame.draw_line(bl, br, Pixel::MAGENTA); target.frame.draw_line(tl, bl, Pixel::MAGENTA); - target.draw_box(Pixel::CYAN); } - } + }; } |