diff --git a/primitives.zig b/primitives.zig index 6e4e3a0..42ec7aa 100644 --- a/primitives.zig +++ b/primitives.zig @@ -56,17 +56,18 @@ pub fn LinkedList() type { self.length += 1; } pub fn next(self: *Self) Point { - var current: ?*Node = undefined; - if (self.current != null) { - current = self.current; - self.current = self.current.?.next; - } else { - current = self.head; - self.current = self.head; - } + var elem: ?*Node = undefined; - return current.?.point; + if (self.current == null) { + elem = self.head; + self.current = self.head.?.next; + } else { + elem = self.current; + self.current = self.current.?.next; + } + return elem.?.point; } + pub fn dump(self: *Self) ![]Point { const allocator = self.allocator; var node = self.head; @@ -101,25 +102,10 @@ test "test linked list" { const points: []Point = try polygon.dump(); for (points) |point| { - std.debug.print("x:{}\n", .{point.x}); - std.debug.print("y:{}\n", .{point.y}); - std.debug.print("z:{}\n", .{point.z}); + std.debug.print("Point dump:{}\n", .{point}); } std.debug.print("next:{}\n", .{polygon.next()}); std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); - std.debug.print("next:{}\n", .{polygon.next()}); } pub fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void {