From 9ebfae5898ad6627e096f79b6507a7314b9e56f1 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Wed, 6 Nov 2019 17:32:02 -0500 Subject: [PATCH] Add Ray constructor that ensures direction vector is normalized --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4cb527d..c98757a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,20 @@ use nalgebra::{RealField, Vector3}; -#[derive(Clone,Debug)] +#[derive(Clone, Debug)] struct Ray { origin: Vector3, direction: Vector3, } +impl Ray { + fn new(origin: Vector3, direction: Vector3) -> Ray { + Ray { + origin, + direction: direction.normalize(), + } + } +} + impl Ray { fn point_at(&self, t: T) -> Vector3 { return self.origin + self.direction * t;