voxel-zone/common/src/space/three_dimensional/vec3generic.rs

42 lines
916 B
Rust

#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use std::ops::Add;
use block_mesh::ilattice::prelude::Vec3A;
#[derive(Eq, PartialEq, Hash, Debug, Default, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Vec3Generic<T> {
pub x: T,
pub y: T,
pub z: T,
}
impl From<Vec3A> for Vec3Generic<i32> {
fn from(v: Vec3A) -> Self {
Self {
x: (v.x.round()) as i32,
y: v.y.round() as i32,
z: v.z.round() as i32,
}
}
}
impl Into<[u32; 3]> for Vec3Generic<i32> {
fn into(self) -> [u32; 3] {
[self.x as u32, self.y as u32, self.z as u32]
}
}
impl Add<Self> for Vec3Generic<i32> {
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,
}
}
}