From 4c7337a694f9e0353f84f42d2787d322eeb376ec Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Sun, 7 Sep 2025 12:29:06 -0700 Subject: [PATCH] revert line impl --- src/main.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0f8d254..fdf631e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,39 +112,27 @@ fn _bench(fb: &mut TGAImage) { } } -fn line(a: Point2i, b: Point2i, color: TGAColor, fb: &mut TGAImage) { - let verts = line_verts(a, b); - for v in verts.into_iter() { - fb.set(v.x as u32, v.y as u32, color); - } -} - -fn line_verts(mut a: Point2i, mut b: Point2i) -> Vec { +fn line(mut a: Point2i, mut b: Point2i, color: TGAColor, fb: &mut TGAImage) { let is_steep = (a.x - b.x).abs() < (a.y - b.y).abs(); if is_steep { std::mem::swap(&mut a.x, &mut a.y); std::mem::swap(&mut b.x, &mut b.y); } if a.x > b.x { - std::mem::swap(&mut a.x, &mut b.x); - std::mem::swap(&mut a.y, &mut b.y); + std::mem::swap(&mut a, &mut b); } - let mut verts: Vec = Vec::new(); - let step = (b.y - a.y) as f32 / (b.x - a.x) as f32; let mut y = a.y as f32; for x in (a.x)..b.x { - let p = if is_steep { - Point2i::new(y.round_ties_even() as i32, x) + let (px, py) = if is_steep { + (y.round_ties_even() as i32, x) } else { - Point2i::new(x, y.round_ties_even() as i32) + (x, y.round_ties_even() as i32) }; - verts.push(p); + fb.set(px as u32, py as u32, color); y += step; } - - verts } fn triangle_lines(a: Point2i, b: Point2i, c: Point2i, color: TGAColor, fb: &mut TGAImage) {