summaryrefslogtreecommitdiff
path: root/engine/src/data_types
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-09-13 20:29:18 +0200
committerHampusM <hampus@hampusmat.com>2026-09-14 09:58:48 +0200
commit62490a4fa76265c36870935338861d16b4498472 (patch)
tree841e0c8c82c9ea5196ba024476fe8d80f1e143f9 /engine/src/data_types
parentc0922efdf70ce2e830178e41b39d7424ed727d84 (diff)
feat(engine): add finite assert in Vec3::normalize
Diffstat (limited to 'engine/src/data_types')
-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.