From b53ea71eb0a66a6afecdfff6b47d724bb22e6441 Mon Sep 17 00:00:00 2001 From: bijan2005 Date: Tue, 8 Dec 2020 11:25:26 -0500 Subject: [PATCH] Optimized bounding sphere intersection test --- src/object/bound.rs | 9 +-------- src/object/sphere.rs | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/object/bound.rs b/src/object/bound.rs index b1a4832..7988305 100644 --- a/src/object/bound.rs +++ b/src/object/bound.rs @@ -18,17 +18,10 @@ pub struct Bound { impl Bound { pub fn is_intersected(&self, ray: Ray) -> bool { - if self.bypass { return true; } let l = ray.origin - self.center; - - let b_2 = ray.direction.dot(&l); - let c = l.norm_squared() - self.radius * self.radius; - - let discr = b_2 * b_2 * c; - - discr >= 0.0 + l.norm_squared() >= self.radius * self.radius } pub fn contains(&self, point: &Point3) -> bool { distance(&self.center, point) < self.radius } diff --git a/src/object/sphere.rs b/src/object/sphere.rs index 7f4af73..9cf01f3 100644 --- a/src/object/sphere.rs +++ b/src/object/sphere.rs @@ -51,7 +51,7 @@ impl Surface for Sphere { let l = ray.origin - self.center; let b = 2.0 * ray.direction.dot(&l); - let c = l.normsquared() - self.radius * self.radius; + let c = l.norm_squared() - self.radius * self.radius; let (mut t0, mut t1) = solve_quadratic(b, c)?;