From 33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 7 Feb 2021 14:25:06 +0100 Subject: Abstracted lambertian into material --- src/core/vector3.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/core/vector3.rs') diff --git a/src/core/vector3.rs b/src/core/vector3.rs index ef067aa..ff5a678 100644 --- a/src/core/vector3.rs +++ b/src/core/vector3.rs @@ -1,7 +1,7 @@ //! Implements 3d vectors //! //! Also add more 3d math things needed for shading and 3d calculations. -use crate::{Float, Number}; +use crate::{Float, Number, NEAR_ZERO}; use std::ops::{Mul, Sub, Add, DivAssign, Neg}; use std::fmt; @@ -149,4 +149,13 @@ impl Vector3f { ) } + + /// Check if vector is close to [0, 0, 0] + /// + /// This is based on the NEAR_ZERO constant + pub fn near_zero(&self) -> bool { + (self.x.abs() < NEAR_ZERO) && + (self.y.abs() < NEAR_ZERO) && + (self.z.abs() < NEAR_ZERO) + } } -- cgit v1.2.3