diff --git a/main.zig b/main.zig index a8cf970..705a949 100644 --- a/main.zig +++ b/main.zig @@ -141,6 +141,7 @@ fn fillBuffer() !void { _ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 30, .z = 0 }); _ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 40, .z = 0 }); _ = try bresenham(buffer, w, Point{ .x = 30, .y = 30, .z = 0 }, Point{ .x = 60, .y = 10, .z = 0 }); + _ = try bresenham(buffer, w, Point{ .x = 60, .y = 30, .z = 0 }, Point{ .x = 70, .y = 5, .z = 0 }); try file.writeAll(buffer); } fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void { @@ -195,6 +196,16 @@ fn bresenham(buf: []u8, w: Winsize, p1: Point, p2: Point) !void { er -= dx; } } + } else if (@abs(dy) > dx and dy < 0) { + while (y >= p2.y) : (y -= 1) { + print("[bresenham4]x:{},y:{},er:{},dx:{},dy:{}\n", .{ x, y, er, dx, dy }); + _ = try pixel(buf, w, x, y, '4'); + er += dx; + if (2 * er >= dy) { + x += 1; + er += dy; + } + } } }