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-03 14:30:21 +0100
commit32e719a517a6fea113f3e66e350c9aa60ddd98b9 (patch)
tree3db7367b59a981dd51135122254d72dc9299eb74 /src/core/vector3.rs
parentdf6a266e5823a7fc4cca3060ec86d35f2125cd0d (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 e3aa9a6..915765d 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 {