Implement Vector addition

This commit is contained in:
Hanno Braun 2024-11-21 19:32:42 +01:00
parent 1137726ea8
commit 508e1bbff6

View File

@ -1,5 +1,7 @@
use std::{cmp::Ordering, ops};
use iter_fixed::IntoIteratorFixed;
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Point {
pub coords: Vector,
@ -32,6 +34,26 @@ where
}
}
impl<T> ops::Add<T> for Vector
where
T: Into<Vector>,
{
type Output = Self;
fn add(self, other: T) -> Self::Output {
let other = other.into();
let components = self
.components
.into_iter_fixed()
.zip(other.components)
.map(|(a, b)| a + b)
.collect();
Self { components }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Scalar {
value: f64,