diff --git a/lithium-utils/src/lib.rs b/lithium-utils/src/lib.rs index 4ddb1e0..a5ed86f 100644 --- a/lithium-utils/src/lib.rs +++ b/lithium-utils/src/lib.rs @@ -1,6 +1,26 @@ +use std::ops::{Add, Sub}; + pub struct Vector2 { - x: f32, - y: f32, + pub x: f32, + pub y: f32, +} + +impl Default for Vector2 { + fn default() -> Self { + Self { x: 0_f32, y: 0_f32 } + } +} + +impl Vector2 { + pub fn new(x: f32, y: f32) -> Self { + Self { x, y } + } +} + +pub struct Vector3 { + pub x: f32, + pub y: f32, + pub z: f32, } impl Default for Vector3 { @@ -13,21 +33,25 @@ impl Default for Vector3 { } } -impl Vector2 { - pub fn new(x: f32, y: f32) -> Self { - Self { x, y } +impl Add for Vector3 { + type Output = Self; + fn add(self, rhs: Self) -> Self::Output { + Self::Output { + x: self.x + rhs.x, + y: self.y + rhs.y, + z: self.z + rhs.z, + } } } -pub struct Vector3 { - x: f32, - y: f32, - z: f32, -} - -impl Default for Vector2 { - fn default() -> Self { - Self { x: 0_f32, y: 0_f32 } +impl Sub for Vector3 { + type Output = Vector3; + fn sub(self, rhs: Self) -> Self::Output { + Self::Output { + x: self.x - rhs.x, + y: self.y - rhs.y, + z: self.z - rhs.z, + } } }