diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-04-20 19:32:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-04-20 19:33:04 +0900 |
| commit | da9a510c32c9a1d6fc2e82e23d0b6b1f1a6a7f83 (patch) | |
| tree | 5046292a6b479465ce58c73e4484861a6972bfb1 /src/rtw | |
| parent | c64077509a2a5e7af8816653e4ea22c4bbeeaff2 (diff) | |
| download | RayTracingInOneWeekend.zig-da9a510c32c9a1d6fc2e82e23d0b6b1f1a6a7f83.tar.gz RayTracingInOneWeekend.zig-da9a510c32c9a1d6fc2e82e23d0b6b1f1a6a7f83.tar.zst RayTracingInOneWeekend.zig-da9a510c32c9a1d6fc2e82e23d0b6b1f1a6a7f83.zip | |
refactor: prefer using qualified name
Diffstat (limited to 'src/rtw')
| -rw-r--r-- | src/rtw/hittable.zig | 26 | ||||
| -rw-r--r-- | src/rtw/material.zig | 6 | ||||
| -rw-r--r-- | src/rtw/perlin.zig | 17 |
3 files changed, 21 insertions, 28 deletions
diff --git a/src/rtw/hittable.zig b/src/rtw/hittable.zig index 3816b4a..447d552 100644 --- a/src/rtw/hittable.zig +++ b/src/rtw/hittable.zig @@ -1,8 +1,4 @@ const std = @import("std"); -const debug = std.debug; -const math = std.math; -const pi = math.pi; -const ArrayList = std.ArrayList; const Rc = @import("../rc.zig").Rc; @@ -164,10 +160,10 @@ const Sphere = struct { } fn getSphereUv(p: Point3, u: *f64, v: *f64) void { - const phi = math.atan2(-p.z, p.x) + pi; - const theta = math.acos(-p.y); - u.* = phi / (2.0 * pi); - v.* = theta / pi; + const phi = std.math.atan2(-p.z, p.x) + std.math.pi; + const theta = std.math.acos(-p.y); + u.* = phi / (2.0 * std.math.pi); + v.* = theta / std.math.pi; } fn deinit(sphere: *const Sphere) void { @@ -247,7 +243,7 @@ const MovingSphere = struct { }; const HittableList = struct { - objects: ArrayList(Hittable), + objects: std.ArrayList(Hittable), fn hit(list: HittableList, r: Ray, t_min: f64, t_max: f64, record: *HitRecord) bool { var hit_anything = false; @@ -294,7 +290,7 @@ const BvhNode = struct { box: Aabb, fn init( - objects: ArrayList(*Hittable), + objects: std.ArrayList(*Hittable), start: usize, end: usize, time0: f64, @@ -538,7 +534,7 @@ const Box = struct { sides: HittableList, pub fn init(p0: Point3, p1: Point3, material: Rc(Material), allocator: anytype) !Box { - var sides = ArrayList(Hittable).init(allocator); + var sides = std.ArrayList(Hittable).init(allocator); 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() } }); @@ -617,13 +613,13 @@ const RotateY = struct { bbox: Aabb, pub fn init(object: Rc(Hittable), t: f64) Self { - const sin_t = math.sin(t); - const cos_t = math.cos(t); + const sin_t = std.math.sin(t); + const cos_t = std.math.cos(t); var bbox: Aabb = undefined; _ = object.get().boudingBox(0, 0, &bbox); - var min: Point3 = .{ .x = math.inf(f64), .y = math.inf(f64), .z = math.inf(f64) }; - var max: Point3 = .{ .x = -math.inf(f64), .y = -math.inf(f64), .z = -math.inf(f64) }; + var min: Point3 = .{ .x = std.math.inf(f64), .y = std.math.inf(f64), .z = std.math.inf(f64) }; + var max: Point3 = .{ .x = -std.math.inf(f64), .y = -std.math.inf(f64), .z = -std.math.inf(f64) }; var i: u32 = 0; while (i < 2) : (i += 1) { diff --git a/src/rtw/material.zig b/src/rtw/material.zig index c1f33ee..f901f26 100644 --- a/src/rtw/material.zig +++ b/src/rtw/material.zig @@ -1,6 +1,4 @@ const std = @import("std"); -const debug = std.debug; -const math = std.math; const Ray = @import("ray.zig").Ray; const vec = @import("vec.zig"); @@ -66,7 +64,7 @@ pub const MetalMaterial = struct { fuzz: f64, fn scatter(mat: MetalMaterial, r_in: Ray, record: HitRecord, attenuation: *Color, scattered: *Ray, rng: Random) bool { - debug.assert(mat.fuzz <= 1.0); + std.debug.assert(mat.fuzz <= 1.0); const reflected = reflect(r_in.dir.normalized(), record.normal); scattered.* = .{ .origin = record.p, .dir = reflected.add(randomPointInUnitSphere(rng).mul(mat.fuzz)), .time = r_in.time }; attenuation.* = mat.albedo; @@ -96,7 +94,7 @@ pub const DielectricMaterial = struct { fn reflectance(cos: f64, refraction_idx: f64) f64 { const r0 = (1.0 - refraction_idx) / (1.0 + refraction_idx); const r1 = r0 * r0; - return r1 + (1.0 - r1) * math.pow(f64, 1.0 - cos, 5.0); + return r1 + (1.0 - r1) * std.math.pow(f64, 1.0 - cos, 5.0); } }; diff --git a/src/rtw/perlin.zig b/src/rtw/perlin.zig index 77a075d..cb23e11 100644 --- a/src/rtw/perlin.zig +++ b/src/rtw/perlin.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const ArrayList = std.ArrayList; const rand = @import("rand.zig"); const Random = rand.Random; @@ -11,17 +10,17 @@ const Vec3 = @import("vec.zig").Vec3; pub const Perlin = struct { const POINT_COUNT = 256; - randomVec: ArrayList(Vec3), - permX: ArrayList(usize), - permY: ArrayList(usize), - permZ: ArrayList(usize), + randomVec: std.ArrayList(Vec3), + permX: std.ArrayList(usize), + permY: std.ArrayList(usize), + permZ: std.ArrayList(usize), pub fn init(allocator: std.mem.Allocator, rng: Random) !Perlin { var perlin = Perlin{ - .randomVec = try ArrayList(Vec3).initCapacity(allocator, POINT_COUNT), - .permX = try ArrayList(usize).initCapacity(allocator, POINT_COUNT), - .permY = try ArrayList(usize).initCapacity(allocator, POINT_COUNT), - .permZ = try ArrayList(usize).initCapacity(allocator, POINT_COUNT), + .randomVec = try std.ArrayList(Vec3).initCapacity(allocator, POINT_COUNT), + .permX = try std.ArrayList(usize).initCapacity(allocator, POINT_COUNT), + .permY = try std.ArrayList(usize).initCapacity(allocator, POINT_COUNT), + .permZ = try std.ArrayList(usize).initCapacity(allocator, POINT_COUNT), }; var i: usize = 0; |
