diff --git a/codegen/templates/quat.rs b/codegen/templates/quat.rs index e89bec94..3100b17d 100644 --- a/codegen/templates/quat.rs +++ b/codegen/templates/quat.rs @@ -57,7 +57,12 @@ use core::arch::wasm32::*; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; -use core::ops::{Add, Deref, Div, Mul, MulAssign, Neg, Sub}; +use core::ops::{ + {% if not is_scalar %} + Deref, DerefMut, + {% endif %} + Add, Div, Mul, MulAssign, Neg, Sub +}; {% if is_sse2 %} union UnionCast { @@ -90,10 +95,10 @@ pub const fn {{ self_t | lower }}(x: {{ scalar_t }}, y: {{ scalar_t }}, z: {{ sc #[cfg_attr(not(any(feature = "scalar-math", target_arch = "spirv")), repr(C, align(16)))] {%- endif %} pub struct {{ self_t }}{ - x: {{ scalar_t }}, - y: {{ scalar_t }}, - z: {{ scalar_t }}, - w: {{ scalar_t }}, + pub x: {{ scalar_t }}, + pub y: {{ scalar_t }}, + pub z: {{ scalar_t }}, + pub w: {{ scalar_t }}, } {%- else %} #[repr(transparent)] @@ -1135,7 +1140,6 @@ impl From<{{ self_t }}> for {{ simd_t }} { {% endif %} } } -{% endif %} impl Deref for {{ self_t }} { type Target = crate::deref::Vec4<{{ scalar_t }}>; @@ -1145,3 +1149,10 @@ impl Deref for {{ self_t }} { } } +impl DerefMut for {{ self_t }} { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { &mut *(self as *mut Self).cast() } + } +} +{% endif %} diff --git a/src/f32/scalar/quat.rs b/src/f32/scalar/quat.rs index 07f3b167..c4360c11 100644 --- a/src/f32/scalar/quat.rs +++ b/src/f32/scalar/quat.rs @@ -11,7 +11,7 @@ use num_traits::Float; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; -use core::ops::{Add, Deref, Div, Mul, MulAssign, Neg, Sub}; +use core::ops::{Add, Div, Mul, MulAssign, Neg, Sub}; /// Creates a quaternion from `x`, `y`, `z` and `w` values. /// @@ -33,10 +33,10 @@ pub const fn quat(x: f32, y: f32, z: f32, w: f32) -> Quat { repr(C, align(16)) )] pub struct Quat { - x: f32, - y: f32, - z: f32, - w: f32, + pub x: f32, + pub y: f32, + pub z: f32, + pub w: f32, } impl Quat { @@ -844,11 +844,3 @@ impl From for [f32; 4] { [q.x, q.y, q.z, q.w] } } - -impl Deref for Quat { - type Target = crate::deref::Vec4; - #[inline] - fn deref(&self) -> &Self::Target { - unsafe { &*(self as *const Self).cast() } - } -} diff --git a/src/f32/sse2/quat.rs b/src/f32/sse2/quat.rs index 82d2905f..78112747 100644 --- a/src/f32/sse2/quat.rs +++ b/src/f32/sse2/quat.rs @@ -16,7 +16,7 @@ use core::arch::x86_64::*; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; -use core::ops::{Add, Deref, Div, Mul, MulAssign, Neg, Sub}; +use core::ops::{Add, Deref, DerefMut, Div, Mul, MulAssign, Neg, Sub}; union UnionCast { a: [f32; 4], @@ -909,3 +909,10 @@ impl Deref for Quat { unsafe { &*(self as *const Self).cast() } } } + +impl DerefMut for Quat { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { &mut *(self as *mut Self).cast() } + } +} diff --git a/src/f32/wasm32/quat.rs b/src/f32/wasm32/quat.rs index 8e0bf8ba..5ccef684 100644 --- a/src/f32/wasm32/quat.rs +++ b/src/f32/wasm32/quat.rs @@ -13,7 +13,7 @@ use core::arch::wasm32::*; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; -use core::ops::{Add, Deref, Div, Mul, MulAssign, Neg, Sub}; +use core::ops::{Add, Deref, DerefMut, Div, Mul, MulAssign, Neg, Sub}; /// Creates a quaternion from `x`, `y`, `z` and `w` values. /// @@ -899,3 +899,10 @@ impl Deref for Quat { unsafe { &*(self as *const Self).cast() } } } + +impl DerefMut for Quat { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { &mut *(self as *mut Self).cast() } + } +} diff --git a/src/f64/dquat.rs b/src/f64/dquat.rs index c20a34ea..ed141f08 100644 --- a/src/f64/dquat.rs +++ b/src/f64/dquat.rs @@ -11,7 +11,7 @@ use num_traits::Float; #[cfg(not(target_arch = "spirv"))] use core::fmt; use core::iter::{Product, Sum}; -use core::ops::{Add, Deref, Div, Mul, MulAssign, Neg, Sub}; +use core::ops::{Add, Div, Mul, MulAssign, Neg, Sub}; /// Creates a quaternion from `x`, `y`, `z` and `w` values. /// @@ -29,10 +29,10 @@ pub const fn dquat(x: f64, y: f64, z: f64, w: f64) -> DQuat { /// operations are applied. #[derive(Clone, Copy)] pub struct DQuat { - x: f64, - y: f64, - z: f64, - w: f64, + pub x: f64, + pub y: f64, + pub z: f64, + pub w: f64, } impl DQuat { @@ -826,11 +826,3 @@ impl From for [f64; 4] { [q.x, q.y, q.z, q.w] } } - -impl Deref for DQuat { - type Target = crate::deref::Vec4; - #[inline] - fn deref(&self) -> &Self::Target { - unsafe { &*(self as *const Self).cast() } - } -}