summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/data_types/vector.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/engine/src/data_types/vector.rs b/engine/src/data_types/vector.rs
index dfe9a99..64c6b53 100644
--- a/engine/src/data_types/vector.rs
+++ b/engine/src/data_types/vector.rs
@@ -143,16 +143,18 @@ impl Vec3<f32>
}
/// Normalizes the vector, returning a unit vector.
+ ///
+ /// // Panics
+ /// When debug assertions are enabled, if the length is zero or not finite,
+ /// this functions panics.
#[must_use]
pub fn normalize(&self) -> Self
{
- let length = self.length();
+ let length_recip = 1.0 / self.length();
- Self {
- x: self.x / length,
- y: self.y / length,
- z: self.z / length,
- }
+ debug_assert!(length_recip.is_finite());
+
+ *self * length_recip
}
/// Returns the cross product of this and another vector.