use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
impl Vec3 {
pub const ZERO: Self = Self {
x: 0.0,
y: 0.0,
z: 0.0,
};
pub const fn new(x: f32, y: f32, z: f32) -> Self {
Self { x, y, z }
}
pub fn plus(self, o: Self) -> Self {
Self::new(self.x + o.x, self.y + o.y, self.z + o.z)
}
pub fn minus(self, o: Self) -> Self {
Self::new(self.x - o.x, self.y - o.y, self.z - o.z)
}
pub fn scale(self, k: f32) -> Self {
Self::new(self.x * k, self.y * k, self.z * k)
}
pub fn length(self) -> f32 {
(self.x * self.x + self.y * self.y + self.z * self.z).sqrt()
}
pub fn distance(self, o: Self) -> f32 {
self.minus(o).length()
}
pub fn dot(self, o: Self) -> f32 {
self.x * o.x + self.y * o.y + self.z * o.z
}
}