feat(utils): implemented basic math op traits for Vector3

This commit is contained in:
antifallobst 2023-11-30 23:53:17 +01:00
parent d74879d339
commit a583049532
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
1 changed files with 38 additions and 14 deletions

View File

@ -1,6 +1,26 @@
use std::ops::{Add, Sub};
pub struct Vector2 { pub struct Vector2 {
x: f32, pub x: f32,
y: 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 { impl Default for Vector3 {
@ -13,21 +33,25 @@ impl Default for Vector3 {
} }
} }
impl Vector2 { impl Add for Vector3 {
pub fn new(x: f32, y: f32) -> Self { type Output = Self;
Self { x, y } 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 { impl Sub for Vector3 {
x: f32, type Output = Vector3;
y: f32, fn sub(self, rhs: Self) -> Self::Output {
z: f32, Self::Output {
} x: self.x - rhs.x,
y: self.y - rhs.y,
impl Default for Vector2 { z: self.z - rhs.z,
fn default() -> Self { }
Self { x: 0_f32, y: 0_f32 }
} }
} }