coremem_types: hide Serialize/Deserialize behind a serde feature flag
- this flag is disabled in spirv_backend. - spirv_backend currently errors in core::fmt stuff. may try hiding fmt behind a feature_flag.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use spirv_std::glam::{self, UVec3};
|
||||
use coremem_types::vec;
|
||||
use coremem_types::vecu;
|
||||
|
||||
// pub trait Nullable {
|
||||
// fn null() -> *const Self;
|
||||
@@ -8,73 +10,25 @@ use spirv_std::glam::{self, UVec3};
|
||||
#[derive(Clone, Copy, Default, PartialEq)]
|
||||
pub struct XYZStd<T>(T, T, T);
|
||||
|
||||
pub type Vec3Std = XYZStd<f32>;
|
||||
pub type UVec3Std = XYZStd<u32>;
|
||||
pub type Vec3Std = vec::Vec3<f32>;
|
||||
pub type UVec3Std = vecu::Vec3u;
|
||||
|
||||
impl<T> XYZStd<T> {
|
||||
pub fn new(x: T, y: T, z: T) -> Self {
|
||||
Self(x, y, z)
|
||||
pub trait IntoGlam {
|
||||
type Output;
|
||||
fn into_glam(self) -> Self::Output;
|
||||
}
|
||||
|
||||
impl IntoGlam for Vec3Std {
|
||||
type Output = glam::Vec3;
|
||||
fn into_glam(self) -> Self::Output {
|
||||
Self::Output::new(self.x(), self.y(), self.z())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy> XYZStd<T> {
|
||||
pub fn uniform(u: T) -> Self {
|
||||
Self(u, u, u)
|
||||
}
|
||||
|
||||
pub fn x(self) -> T {
|
||||
self.0
|
||||
}
|
||||
pub fn y(self) -> T {
|
||||
self.1
|
||||
}
|
||||
pub fn z(self) -> T {
|
||||
self.2
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: core::ops::Add<T, Output=T>> core::ops::Add<XYZStd<T>> for XYZStd<T> {
|
||||
type Output = Self;
|
||||
fn add(self, s: Self) -> Self {
|
||||
Self::new(self.0 + s.0, self.1 + s.1, self.2 + s.2)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: core::ops::Sub<T, Output=T>> core::ops::Sub<XYZStd<T>> for XYZStd<T> {
|
||||
type Output = Self;
|
||||
fn sub(self, s: Self) -> Self {
|
||||
Self::new(self.0 - s.0, self.1 - s.1, self.2 - s.2)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + core::ops::Mul<T, Output=T>> core::ops::Mul<T> for XYZStd<T> {
|
||||
type Output = Self;
|
||||
fn mul(self, s: T) -> Self {
|
||||
Self::new(self.0 * s, self.1 * s, self.2 * s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<glam::Vec3> for Vec3Std {
|
||||
fn into(self) -> glam::Vec3 {
|
||||
glam::Vec3::new(self.x(), self.y(), self.z())
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<glam::UVec3> for UVec3Std {
|
||||
fn into(self) -> glam::UVec3 {
|
||||
glam::UVec3::new(self.x(), self.y(), self.z())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: core::ops::Mul<T, Output=T>> XYZStd<T> {
|
||||
pub fn elem_mul(self, other: Self) -> Self {
|
||||
Self::new(self.0 * other.0, self.1 * other.1, self.2 * other.2)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: core::ops::Div<T, Output=T>> XYZStd<T> {
|
||||
pub fn elem_div(self, other: Self) -> Self {
|
||||
Self::new(self.0 / other.0, self.1 / other.1, self.2 / other.2)
|
||||
impl IntoGlam for UVec3Std {
|
||||
type Output = glam::UVec3;
|
||||
fn into_glam(self) -> Self::Output {
|
||||
Self::Output::new(self.x(), self.y(), self.z())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user