From 4f14a166a690da2593a6ca6dea204a201e5b6dd1 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 6 Jun 2023 17:48:46 -0500 Subject: [PATCH] Fix: Nearest root within tolerance I found the fucker. The rays were bouncing incorrectly because I wasn't holding a value the way I should have. I thought I was being clever and using Rusts's ability to redeclare variables. But, no. That value is meant to be modified when the first conditional passes. The outcomes are 3 possibilities, where one is an early return. Shadowing the value that way meant I was giving back garbage. I don't know why this didn't have any obviously bad effects prior to making the dielectric material. --- src/sphere.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sphere.rs b/src/sphere.rs index b1c5977..17beb81 100644 --- a/src/sphere.rs +++ b/src/sphere.rs @@ -27,9 +27,9 @@ impl Hittable for Sphere { let sqrtd = discriminant.sqrt(); // nearest root that lies within tolerance - let root = (-half_b - sqrtd) / a; + let mut root = (-half_b - sqrtd) / a; if root < t_min || root > t_max { - let root = (-half_b + sqrtd) / a; + root = (-half_b + sqrtd) / a; if root < t_min || root > t_max { return None; }