summaryrefslogtreecommitdiff
path: root/src/calculus.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/calculus.rs')
-rw-r--r--src/calculus.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/calculus.rs b/src/calculus.rs
index e1e9caf..568eb60 100644
--- a/src/calculus.rs
+++ b/src/calculus.rs
@@ -105,6 +105,20 @@ pub mod calculus {
z: self.z / mag,
}
}
+
+ pub fn is_near_zero(&self) -> bool {
+ self.x.abs() < f32::EPSILON &&
+ self.y.abs() < f32::EPSILON &&
+ self.z.abs() < f32::EPSILON
+ }
+
+ pub fn reflect(&self, normal: &Self) -> Self {
+ self.sub(
+ &normal.scalar_mul(
+ 2.0 * self.dot_prod(&normal)
+ )
+ )
+ }
}
pub struct Ray {
@@ -117,6 +131,10 @@ pub mod calculus {
// Get parametric location
self.origin.add(&self.direction.scalar_mul(t))
}
+
+ pub fn reflect(&self, normal: &Vec3) -> Vec3 {
+ self.direction.reflect(&normal)
+ }
}
pub fn deg2rad(deg: f32) -> f32 {