diff --git a/src/graphics_api_impl.rs b/src/graphics_api_impl.rs index f0f07e9..5d61e31 100644 --- a/src/graphics_api_impl.rs +++ b/src/graphics_api_impl.rs @@ -32,8 +32,8 @@ impl AglApi for GraphicsRenderer { let x2 = coords_end.x; let y2 = coords_end.y; - let dx = x2 - x1; - let dy = y2 - y1; + let dx = x2.wrapping_sub(x1); + let dy = y2.wrapping_sub(y1); for x in x1..x2 { let y = y1 + dy * (x - x1) / dx; @@ -63,7 +63,9 @@ impl AglApi for GraphicsRenderer { thickness: u32, color: RGBA, ) { - todo!(); + self.put_line(coords_1, coords_2, thickness, color); + self.put_line(coords_2, coords_3, thickness, color); + self.put_line(coords_3, coords_1, thickness, color); } fn paint_cursor(&mut self, coords: Point) { diff --git a/src/main.rs b/src/main.rs index 0bda1e5..702f0c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,6 +83,20 @@ fn main() { }, "Hello".to_string(), ); + + xyz.put_triangle( + Point { x: 10, y: 40 }, + Point { x: 30, y: 100 }, + Point { x: 10, y: 90 }, + 8, + RGBA { + r: 8, + g: 7, + b: 7, + a: 255, + }, + ); + // update pixels for x in 0..600 * 400 { buffer[x] = [xyz.buff[x].r, xyz.buff[x].g, xyz.buff[x].b, xyz.buff[x].a]