diff options
Diffstat (limited to '')
| -rw-r--r-- | core/src/vector.rs | 21 | 
1 files changed, 16 insertions, 5 deletions
diff --git a/core/src/vector.rs b/core/src/vector.rs index f45daab9..92bf64ff 100644 --- a/core/src/vector.rs +++ b/core/src/vector.rs @@ -1,15 +1,26 @@  /// A 2D vector.  #[derive(Debug, Clone, Copy, PartialEq)] -pub struct Vector { -    pub x: f32, -    pub y: f32, +pub struct Vector<T = f32> { +    pub x: T, +    pub y: T,  } -impl Vector { +impl<T> Vector<T> {      /// Creates a new [`Vector`] with the given components.      ///      /// [`Vector`]: struct.Vector.html -    pub fn new(x: f32, y: f32) -> Self { +    pub fn new(x: T, y: T) -> Self {          Self { x, y }      }  } + +impl<T> std::ops::Add for Vector<T> +where +    T: std::ops::Add<Output = T>, +{ +    type Output = Self; + +    fn add(self, b: Self) -> Self { +        Self::new(self.x + b.x, self.y + b.y) +    } +}  | 
