aboutsummaryrefslogtreecommitdiff
path: root/src/core/vector3.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-02 20:39:32 +0100
committerJulian T <julian@jtle.dk>2021-02-02 20:39:32 +0100
commit2b4adacea3c76b8b33dc5f50d296dd4a61107c16 (patch)
tree905b672e4005b29dad5807060ae3a966d4a3d264 /src/core/vector3.rs
parentd79d5d18c8281cce1e782892e5f85680906481dd (diff)
Added documentation for many of the modules
Diffstat (limited to 'src/core/vector3.rs')
-rw-r--r--src/core/vector3.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/vector3.rs b/src/core/vector3.rs
index 05bd977..48025ed 100644
--- a/src/core/vector3.rs
+++ b/src/core/vector3.rs
@@ -1,3 +1,6 @@
+//! Implements 3d vectors
+//!
+//! Also add more 3d math things needed for shading and 3d calculations.
use crate::{Float, Number};
use std::ops::{Sub, Add, DivAssign};
@@ -55,6 +58,9 @@ impl<T: Number> DivAssign<T> for Vector3<T> {
}
impl Vector3f {
+ /// Calculates the length times itself
+ ///
+ /// This is faster than using len * len as the square is ommited
pub fn len_squared(&self) -> Float {
self.x * self.x + self.y * self.y + self.z * self.z
}
@@ -67,6 +73,16 @@ impl Vector3f {
self.x * op.x + self.y * op.y + self.z * op.z
}
+ /// Inplace normal instead of creating a new vector
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use pathtrace::core::Vector3f;
+ /// let mut v = Vector3f::new_xyz(10.0, 0.0, 0.0);
+ /// v.norm_in();
+ /// assert!(v.x == 1.0);
+ /// ```
pub fn norm_in(&mut self) {
let len = self.len();
if len == 0.0 {