aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/rtw/hittable.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-04-20 19:45:36 +0900
committernsfisis <nsfisis@gmail.com>2025-04-20 19:45:36 +0900
commit76657dddd4f37f55a3912ac44d2ba8722645b1b6 (patch)
tree936903feec51b0f6f6f1f97b5b83fcdb452ebf69 /src/rtw/hittable.zig
parentdaff2a6d02ca5e7683156551cc1b9b146fa4121d (diff)
downloadRayTracingInOneWeekend.zig-76657dddd4f37f55a3912ac44d2ba8722645b1b6.tar.gz
RayTracingInOneWeekend.zig-76657dddd4f37f55a3912ac44d2ba8722645b1b6.tar.zst
RayTracingInOneWeekend.zig-76657dddd4f37f55a3912ac44d2ba8722645b1b6.zip
refactor: use anonymous enum for tagged-union
Diffstat (limited to 'src/rtw/hittable.zig')
-rw-r--r--src/rtw/hittable.zig68
1 files changed, 28 insertions, 40 deletions
diff --git a/src/rtw/hittable.zig b/src/rtw/hittable.zig
index 7240fd2..7ba5dfe 100644
--- a/src/rtw/hittable.zig
+++ b/src/rtw/hittable.zig
@@ -19,19 +19,7 @@ const Material = @import("material.zig").Material;
const HitRecord = @import("hit_record.zig").HitRecord;
const Aabb = @import("aabb.zig").Aabb;
-const HittableTag = enum {
- sphere,
- movingSphere,
- list,
- xyRect,
- xzRect,
- yzRect,
- box,
- translate,
- rotateY,
-};
-
-pub const Hittable = union(HittableTag) {
+pub const Hittable = union(enum) {
const Self = @This();
sphere: Sphere,
@@ -58,43 +46,43 @@ pub const Hittable = union(HittableTag) {
pub fn hit(self: Self, r: Ray, t_min: f64, t_max: f64, record: *HitRecord) bool {
return switch (self) {
- HittableTag.sphere => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.movingSphere => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.list => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.xyRect => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.xzRect => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.yzRect => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.box => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.translate => |slf| slf.hit(r, t_min, t_max, record),
- HittableTag.rotateY => |slf| slf.hit(r, t_min, t_max, record),
+ .sphere => |slf| slf.hit(r, t_min, t_max, record),
+ .movingSphere => |slf| slf.hit(r, t_min, t_max, record),
+ .list => |slf| slf.hit(r, t_min, t_max, record),
+ .xyRect => |slf| slf.hit(r, t_min, t_max, record),
+ .xzRect => |slf| slf.hit(r, t_min, t_max, record),
+ .yzRect => |slf| slf.hit(r, t_min, t_max, record),
+ .box => |slf| slf.hit(r, t_min, t_max, record),
+ .translate => |slf| slf.hit(r, t_min, t_max, record),
+ .rotateY => |slf| slf.hit(r, t_min, t_max, record),
};
}
fn boudingBox(self: Self, time0: f64, time1: f64, output_box: *Aabb) bool {
return switch (self) {
- HittableTag.sphere => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.movingSphere => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.list => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.xyRect => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.xzRect => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.yzRect => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.box => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.translate => |slf| slf.boudingBox(time0, time1, output_box),
- HittableTag.rotateY => |slf| slf.boudingBox(time0, time1, output_box),
+ .sphere => |slf| slf.boudingBox(time0, time1, output_box),
+ .movingSphere => |slf| slf.boudingBox(time0, time1, output_box),
+ .list => |slf| slf.boudingBox(time0, time1, output_box),
+ .xyRect => |slf| slf.boudingBox(time0, time1, output_box),
+ .xzRect => |slf| slf.boudingBox(time0, time1, output_box),
+ .yzRect => |slf| slf.boudingBox(time0, time1, output_box),
+ .box => |slf| slf.boudingBox(time0, time1, output_box),
+ .translate => |slf| slf.boudingBox(time0, time1, output_box),
+ .rotateY => |slf| slf.boudingBox(time0, time1, output_box),
};
}
pub fn deinit(self: *const Self) void {
return switch (self.*) {
- HittableTag.sphere => |slf| slf.deinit(),
- HittableTag.movingSphere => |slf| slf.deinit(),
- HittableTag.list => |slf| slf.deinit(),
- HittableTag.xyRect => |slf| slf.deinit(),
- HittableTag.xzRect => |slf| slf.deinit(),
- HittableTag.yzRect => |slf| slf.deinit(),
- HittableTag.box => |slf| slf.deinit(),
- HittableTag.translate => |slf| slf.deinit(),
- HittableTag.rotateY => |slf| slf.deinit(),
+ .sphere => |slf| slf.deinit(),
+ .movingSphere => |slf| slf.deinit(),
+ .list => |slf| slf.deinit(),
+ .xyRect => |slf| slf.deinit(),
+ .xzRect => |slf| slf.deinit(),
+ .yzRect => |slf| slf.deinit(),
+ .box => |slf| slf.deinit(),
+ .translate => |slf| slf.deinit(),
+ .rotateY => |slf| slf.deinit(),
};
}
};