mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-07 11:28:28 +00:00
Implement Vector
addition
This commit is contained in:
parent
1137726ea8
commit
508e1bbff6
@ -1,5 +1,7 @@
|
|||||||
use std::{cmp::Ordering, ops};
|
use std::{cmp::Ordering, ops};
|
||||||
|
|
||||||
|
use iter_fixed::IntoIteratorFixed;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct Point {
|
pub struct Point {
|
||||||
pub coords: Vector,
|
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)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct Scalar {
|
pub struct Scalar {
|
||||||
value: f64,
|
value: f64,
|
||||||
|
Loading…
Reference in New Issue
Block a user