From 054a3d459f676a3a674a036f88e2e7dcc30a4ab3 Mon Sep 17 00:00:00 2001 From: STP Date: Fri, 17 Nov 2023 14:11:22 -0500 Subject: [PATCH] Added epsilon to t to ensure rayremains within box --- src/ray.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ray.rs b/src/ray.rs index b10d480..cf60b28 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -1,18 +1,17 @@ -use crate::EPSILON; +use crate::{EPSILON, EPSILON_VECTOR}; -use nalgebra::{Matrix4, Point3, Vector3}; +use nalgebra::{Matrix4, Point3, Unit, Vector3}; pub struct Ray { pub a: Point3, - pub b: Vector3, + pub b: Unit>, } impl Ray { - pub fn new(a: Point3, b: Vector3) -> Ray { - let b = b.normalize(); + pub fn new(a: Point3, b: Unit>) -> Ray { Ray { a, b } } pub fn at_t(&self, t: f32) -> Point3 { - self.a + self.b * t + self.a + self.b.as_ref() * (t + EPSILON) } }