From 0b25dcbe5801ef13d5075ea99b5c21367426ee85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bor=20Gro=C5=A1elj=20Simi=C4=87?= Date: Mon, 31 Jan 2022 01:20:01 +0100 Subject: [PATCH] all: drop some workarounds that are not needed anymore --- color.ha | 14 +++++++------- main.ha | 12 ++++++------ util.ha | 5 +++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/color.ha b/color.ha index 2bb6e98..08a498a 100644 --- a/color.ha +++ b/color.ha @@ -1,4 +1,4 @@ -use math::{sqrtf64}; +use math::{sqrtf64, nextafterf64}; export type color = struct { r: f64, @@ -19,16 +19,16 @@ export type rgb = struct { }; export fn torgb(c: color, scale: f64) rgb = rgb { - r = (clamp(sqrtf64(c.r * scale), 0.0, 0.9999) * 256f64): int: u8, // TODO drop the int cast - g = (clamp(sqrtf64(c.g * scale), 0.0, 0.9999) * 256f64): int: u8, // TODO nextafter() - b = (clamp(sqrtf64(c.b * scale), 0.0, 0.9999) * 256f64): int: u8, + r = (clamp(sqrtf64(c.r * scale), 0.0, nextafterf64(1.0, 0.0)) * 256.0): u8, + g = (clamp(sqrtf64(c.g * scale), 0.0, nextafterf64(1.0, 0.0)) * 256.0): u8, + b = (clamp(sqrtf64(c.b * scale), 0.0, nextafterf64(1.0, 0.0)) * 256.0): u8, }; export fn fromrgb(c: rgb) color = { let c = color { - r = c.r: i32: f64 / 256f64, - g = c.g: i32: f64 / 256f64, - b = c.b: i32: f64 / 256f64, + r = c.r: f64 / 256f64, + g = c.g: f64 / 256f64, + b = c.b: f64 / 256f64, }; return color { r = c.r * c.r, diff --git a/main.ha b/main.ha index 92337e1..e4d685e 100644 --- a/main.ha +++ b/main.ha @@ -147,7 +147,7 @@ export fn main() void = { let from = V(13.0, 2.0, 3.0); let at = V(0.0, 0.0, 0.0); let c = make_camera(from, at, V(0.0, 1.0, 0.0), - 20.0, width: i64: f64 / height: i64: f64, 0.1, 10.0); + 20.0, width: f64 / height: f64, 0.1, 10.0); let scene = init_scene(); @@ -156,16 +156,16 @@ export fn main() void = { for (let j = begin; j < end; j += 1) { fmt::errorf("\rProgress: begin: {} current: {} end: {} | {}%", begin, j, end, - ((j - begin): i64: f64 / (end - begin): i64: f64 * 100.0): int)!; + ((j - begin): f64 / (end - begin): f64 * 100.0): int)!; for (let i = 0z; i < width; i += 1) { for (let k = 0u; k < samples; k += 1) { - let u = i: int: f64; + let u = i: f64; u += random(0.0, 1.0); - u /= (width: int: f64 - 1.0); + u /= (width: f64 - 1.0); - let v = j: int: f64; + let v = j: f64; v += random(0.0, 1.0); - v /= (height: int: f64 - 1.0); + v /= (height: f64 - 1.0); let r = get_ray_for(&c, u, v); let c = compute_color(scene, &r, max_bounce); diff --git a/util.ha b/util.ha index 85a33a7..54d1d38 100644 --- a/util.ha +++ b/util.ha @@ -1,12 +1,13 @@ +use math; use math::random; use types; let rng: math::random::random = 0u64; export fn random(min: f64, max: f64) f64 = { - // TODO: drop the signed cast let n = math::random::next(&rng); - return min + (max - min) * (n: i64: f64 / types::I64_MAX: f64); + return min + (max - min) * + math::nextafterf64(n: f64 / types::I64_MAX: f64, 0.0); }; export fn clamp(x: f64, min: f64, max: f64) f64 = -- 2.45.2