lithium/lithium-utils/src/lib.rs

63 lines
1.0 KiB
Rust
Raw Normal View History

use std::ops::{Add, Sub};
pub struct Vector2 {
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 {
fn default() -> Self {
Self {
x: 0_f32,
y: 0_f32,
z: 0_f32,
}
}
}
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,
}
}
}
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,
}
}
}
impl Vector3 {
pub fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
}