mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-05 10:28:27 +00:00
Add Vector::dot
This commit is contained in:
parent
878f6051bc
commit
10a2036740
@ -11,17 +11,21 @@ pub struct Vector<const D: usize> {
|
||||
|
||||
impl<const D: usize> Vector<D> {
|
||||
pub fn magnitude(&self) -> Scalar {
|
||||
self.components
|
||||
.into_iter()
|
||||
.map(|coord| coord * coord)
|
||||
.reduce(|a, b| a + b)
|
||||
.unwrap_or(Scalar::zero())
|
||||
.sqrt()
|
||||
self.dot(self).sqrt()
|
||||
}
|
||||
|
||||
pub fn normalize(self) -> Self {
|
||||
self / self.magnitude()
|
||||
}
|
||||
|
||||
pub fn dot(&self, other: &Self) -> Scalar {
|
||||
self.components
|
||||
.into_iter()
|
||||
.zip(other.components)
|
||||
.map(|(a, b)| a * b)
|
||||
.reduce(|a, b| a + b)
|
||||
.unwrap_or(Scalar::zero())
|
||||
}
|
||||
}
|
||||
|
||||
impl Vector<3> {
|
||||
|
Loading…
Reference in New Issue
Block a user