aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/rtw/hittable.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-10-04 16:59:54 +0900
committernsfisis <nsfisis@gmail.com>2025-10-04 16:59:54 +0900
commitd95640d95cd58bd392ee4e8ad0b0a26b65b0adce (patch)
tree808d84c182506389a925d47e70814fa0192a1ffb /src/rtw/hittable.zig
parenta7bfa9de653db0e221ec55c261bb7677ef26d08a (diff)
downloadRayTracingInOneWeekend.zig-d95640d95cd58bd392ee4e8ad0b0a26b65b0adce.tar.gz
RayTracingInOneWeekend.zig-d95640d95cd58bd392ee4e8ad0b0a26b65b0adce.tar.zst
RayTracingInOneWeekend.zig-d95640d95cd58bd392ee4e8ad0b0a26b65b0adce.zip
feat: update zig to 0.15.1HEADmain
Diffstat (limited to 'src/rtw/hittable.zig')
-rw-r--r--src/rtw/hittable.zig31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/rtw/hittable.zig b/src/rtw/hittable.zig
index 7ba5dfe..edf8f7f 100644
--- a/src/rtw/hittable.zig
+++ b/src/rtw/hittable.zig
@@ -72,15 +72,15 @@ pub const Hittable = union(enum) {
};
}
- pub fn deinit(self: *const Self) void {
+ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
return switch (self.*) {
.sphere => |slf| slf.deinit(),
.movingSphere => |slf| slf.deinit(),
- .list => |slf| slf.deinit(),
+ .list => |*slf| slf.deinit(allocator),
.xyRect => |slf| slf.deinit(),
.xzRect => |slf| slf.deinit(),
.yzRect => |slf| slf.deinit(),
- .box => |slf| slf.deinit(),
+ .box => |*slf| slf.deinit(allocator),
.translate => |slf| slf.deinit(),
.rotateY => |slf| slf.deinit(),
};
@@ -259,11 +259,12 @@ const HittableList = struct {
return true;
}
- fn deinit(list: *const HittableList) void {
+ fn deinit(list: *HittableList, allocator: std.mem.Allocator) void {
for (list.objects.items) |object| {
- object.deinit();
+ var hoge: Hittable = object;
+ hoge.deinit(allocator);
}
- list.objects.deinit();
+ list.objects.deinit(allocator);
}
};
@@ -432,14 +433,14 @@ const Box = struct {
sides: HittableList,
pub fn init(p0: Point3, p1: Point3, material: Rc(Material), allocator: anytype) !Box {
- var sides = std.ArrayList(Hittable).init(allocator);
+ var sides = try std.ArrayList(Hittable).initCapacity(allocator, 6);
- try sides.append(.{ .xyRect = .{ .x0 = p0.x, .x1 = p1.x, .y0 = p0.y, .y1 = p1.y, .k = p1.z, .material = material } });
- try sides.append(.{ .xyRect = .{ .x0 = p0.x, .x1 = p1.x, .y0 = p0.y, .y1 = p1.y, .k = p0.z, .material = material.clone() } });
- try sides.append(.{ .xzRect = .{ .x0 = p0.x, .x1 = p1.x, .z0 = p0.z, .z1 = p1.z, .k = p1.y, .material = material.clone() } });
- try sides.append(.{ .xzRect = .{ .x0 = p0.x, .x1 = p1.x, .z0 = p0.z, .z1 = p1.z, .k = p0.y, .material = material.clone() } });
- try sides.append(.{ .yzRect = .{ .y0 = p0.y, .y1 = p1.y, .z0 = p0.z, .z1 = p1.z, .k = p1.x, .material = material.clone() } });
- try sides.append(.{ .yzRect = .{ .y0 = p0.y, .y1 = p1.y, .z0 = p0.z, .z1 = p1.z, .k = p0.x, .material = material.clone() } });
+ try sides.append(allocator, .{ .xyRect = .{ .x0 = p0.x, .x1 = p1.x, .y0 = p0.y, .y1 = p1.y, .k = p1.z, .material = material } });
+ try sides.append(allocator, .{ .xyRect = .{ .x0 = p0.x, .x1 = p1.x, .y0 = p0.y, .y1 = p1.y, .k = p0.z, .material = material.clone() } });
+ try sides.append(allocator, .{ .xzRect = .{ .x0 = p0.x, .x1 = p1.x, .z0 = p0.z, .z1 = p1.z, .k = p1.y, .material = material.clone() } });
+ try sides.append(allocator, .{ .xzRect = .{ .x0 = p0.x, .x1 = p1.x, .z0 = p0.z, .z1 = p1.z, .k = p0.y, .material = material.clone() } });
+ try sides.append(allocator, .{ .yzRect = .{ .y0 = p0.y, .y1 = p1.y, .z0 = p0.z, .z1 = p1.z, .k = p1.x, .material = material.clone() } });
+ try sides.append(allocator, .{ .yzRect = .{ .y0 = p0.y, .y1 = p1.y, .z0 = p0.z, .z1 = p1.z, .k = p0.x, .material = material.clone() } });
return .{
.min = p0,
@@ -464,8 +465,8 @@ const Box = struct {
return true;
}
- pub fn deinit(box: *const Box) void {
- box.sides.deinit();
+ pub fn deinit(box: *Box, allocator: std.mem.Allocator) void {
+ box.sides.deinit(allocator);
}
};