use derive_cmp_ops::*;
use glium::uniforms::AsUniformValue;
use super::{vec3::Vec3, uvec2::{uvec2, UVec2}, uvec4::{uvec4, UVec4}};
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, CmpAdd, CmpAddAssign, CmpDiv,
CmpDivAssign, CmpMul, CmpMulAssign, CmpRem, CmpRemAssign, CmpSub, CmpSubAssign)]
pub struct UVec3 {
pub x: u32,
pub y: u32,
pub z: u32
}
impl UVec3 {
pub const ZERO: Self = uvec3(0, 0, 0);
pub const ONE: Self = uvec3(1, 1, 1);
pub const X: Self = uvec3(1, 0, 0);
pub const Y: Self = uvec3(0, 1, 0);
pub const Z: Self = uvec3(0, 0, 1);
pub fn new(x: u32, y: u32, z: u32) -> Self {
Self { x, y, z }
}
pub fn extend(self, w: u32) -> UVec4{
uvec4(self.x, self.y, self.z, w)
}
pub fn truncate(self) -> UVec2{
uvec2(self.x, self.y)
}
pub fn splat(value: u32) -> Self{
Self::new(value, value, value)
}
pub fn length_squared(self) -> u32 {
self.x*self.x + self.y*self.y + self.z*self.z
}
pub fn distance_squared(self, other: UVec3) -> u32 {
(self - other).length_squared()
}
pub fn dot(self, other: UVec3) -> u32 {
self.x * other.x + self.y * other.y + self.z * other.z
}
pub fn cross(&self, other: UVec3) -> UVec3{
uvec3(
self.y*other.z - self.z*other.y,
self.z*other.x - self.x*other.z,
self.x*other.y - self.y*other.x
)
}
pub fn scale(self, scalar: u32) -> UVec3{
Self::new(self.x * scalar, self.y * scalar, self.z * scalar)
}
}
impl AsUniformValue for UVec3{
fn as_uniform_value(&self) -> glium::uniforms::UniformValue<'_> {
glium::uniforms::UniformValue::UnsignedIntVec3([self.x, self.y, self.z])
}
}
impl From<Vec3> for UVec3 {
fn from(value: Vec3) -> Self {
Self { x: value.x as u32, y: value.y as u32, z: value.z as u32 }
}
}
impl From<(u32, u32, u32)> for UVec3 {
fn from(value: (u32, u32, u32)) -> Self {
Self { x: value.0, y: value.1, z: value.2 }
}
}
impl From<[u32; 3]> for UVec3 {
fn from(value: [u32; 3]) -> Self {
Self { x: value[0], y: value[1], z: value[2] }
}
}
pub const fn uvec3(x: u32, y: u32, z: u32) -> UVec3{
UVec3 { x, y, z }
}