WIP: implement part 1
This commit is contained in:
parent
b55a6d61da
commit
393f80f314
1 changed files with 45 additions and 0 deletions
|
|
@ -169,5 +169,50 @@ const Region = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion {
|
||||||
|
return try .init(allocator, self.width, self.height);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmptyRegion = struct {
|
||||||
|
grid: [][]bool,
|
||||||
|
filled_spaces: usize,
|
||||||
|
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
pub fn init(allocator: std.mem.Allocator, width: u8, height: u8) !Self {
|
||||||
|
const h = try allocator.alloc([]bool, height);
|
||||||
|
for (0..height) |i| {
|
||||||
|
const w = try allocator.alloc(u8, width);
|
||||||
|
@memset(w, false);
|
||||||
|
h[i] = w;
|
||||||
|
}
|
||||||
|
return .{
|
||||||
|
.grid = h,
|
||||||
|
.filled_spaces = 0,
|
||||||
|
.allocator = allocator,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: Self) void {
|
||||||
|
for (self.grid) |row| {
|
||||||
|
self.allocator.free(row);
|
||||||
|
}
|
||||||
|
self.allocator.free(self.grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fits(self: Self, present: Present) bool {
|
||||||
|
std.debug.assert(self.grid.len > 0);
|
||||||
|
const size = self.grid.len * self.grid[0].len;
|
||||||
|
if ((size - self.filled_spaces) < present.shape.count()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implementation
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue