use inline const constructor because it's a little bit prettier
This commit is contained in:
parent
5f2bec75f5
commit
36c769346c
@ -88,11 +88,11 @@ macro_rules! impl_vector_3_wide_cross {
|
||||
paste::item!{
|
||||
#[inline]
|
||||
pub fn [<wide_cross_ $lhs _ $rhs>](self,rhs:Vector<3,fixed_wide::fixed::Fixed<{$rhs},{$rhs*32}>>)->Vector<3,fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>>{
|
||||
Vector{array:[
|
||||
Vector::new([
|
||||
self.y.[<wide_mul_ $lhs _ $rhs>](rhs.z)-self.z.[<wide_mul_ $lhs _ $rhs>](rhs.y),
|
||||
self.z.[<wide_mul_ $lhs _ $rhs>](rhs.x)-self.x.[<wide_mul_ $lhs _ $rhs>](rhs.z),
|
||||
self.x.[<wide_mul_ $lhs _ $rhs>](rhs.y)-self.y.[<wide_mul_ $lhs _ $rhs>](rhs.x),
|
||||
]}
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,8 +130,8 @@ macro_rules! impl_matrix_wide_dot {
|
||||
#[inline]
|
||||
pub fn [<wide_dot_ $lhs _ $rhs>]<const Z:usize>(self,rhs:Matrix<Z,X,fixed_wide::fixed::Fixed<{$rhs},{$rhs*32}>>)->Matrix<Z,Y,fixed_wide::fixed::Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>>{
|
||||
let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle());
|
||||
Matrix{
|
||||
array:self.array.map(|axis|
|
||||
Matrix::new(
|
||||
self.array.map(|axis|
|
||||
core::array::from_fn(|_|
|
||||
// axis dot product with transposed rhs array
|
||||
axis.iter().zip(
|
||||
@ -141,7 +141,7 @@ macro_rules! impl_matrix_wide_dot {
|
||||
).sum()
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,11 +192,11 @@ macro_rules! impl_matrix_wide_3x3_adjugate_not_const_generic {
|
||||
impl Matrix<3,3,fixed_wide::fixed::Fixed<$n,{$n*32}>>{
|
||||
paste::item!{
|
||||
pub fn [<wide_adjugate_3x3_ $n>](self)->Matrix<3,3,fixed_wide::fixed::Fixed<{$n*2},{$n*2*32}>>{
|
||||
Matrix{array:[
|
||||
Matrix::new([
|
||||
[self.y_axis.y.[<wide_mul_ $n _ $n>](self.z_axis.z)-self.y_axis.z.[<wide_mul_ $n _ $n>](self.z_axis.y),self.x_axis.z.[<wide_mul_ $n _ $n>](self.z_axis.y)-self.x_axis.y.[<wide_mul_ $n _ $n>](self.z_axis.z),self.x_axis.y.[<wide_mul_ $n _ $n>](self.y_axis.z)-self.x_axis.z.[<wide_mul_ $n _ $n>](self.y_axis.y)],
|
||||
[self.y_axis.z.[<wide_mul_ $n _ $n>](self.z_axis.x)-self.y_axis.x.[<wide_mul_ $n _ $n>](self.z_axis.z),self.x_axis.x.[<wide_mul_ $n _ $n>](self.z_axis.z)-self.x_axis.z.[<wide_mul_ $n _ $n>](self.z_axis.x),self.x_axis.z.[<wide_mul_ $n _ $n>](self.y_axis.x)-self.x_axis.x.[<wide_mul_ $n _ $n>](self.y_axis.z)],
|
||||
[self.y_axis.x.[<wide_mul_ $n _ $n>](self.z_axis.y)-self.y_axis.y.[<wide_mul_ $n _ $n>](self.z_axis.x),self.x_axis.y.[<wide_mul_ $n _ $n>](self.z_axis.x)-self.x_axis.x.[<wide_mul_ $n _ $n>](self.z_axis.y),self.x_axis.x.[<wide_mul_ $n _ $n>](self.y_axis.y)-self.x_axis.y.[<wide_mul_ $n _ $n>](self.y_axis.x)],
|
||||
]}
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,21 +16,21 @@ macro_rules! impl_matrix {
|
||||
where
|
||||
F:Fn(T)->U
|
||||
{
|
||||
Matrix{
|
||||
array:self.array.map(|inner|inner.map(&f)),
|
||||
}
|
||||
Matrix::new(
|
||||
self.array.map(|inner|inner.map(&f)),
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
pub fn transpose(self)->Matrix<Y,X,T>{
|
||||
//how did I think of this
|
||||
let mut array_of_iterators=self.array.map(|axis|axis.into_iter());
|
||||
Matrix{
|
||||
array:core::array::from_fn(|_|
|
||||
Matrix::new(
|
||||
core::array::from_fn(|_|
|
||||
array_of_iterators.each_mut().map(|iter|
|
||||
iter.next().unwrap()
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
// MatY<VecX>.MatX<VecZ> = MatY<VecZ>
|
||||
@ -41,8 +41,8 @@ macro_rules! impl_matrix {
|
||||
U:Copy,
|
||||
{
|
||||
let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle());
|
||||
Matrix{
|
||||
array:self.array.map(|axis|
|
||||
Matrix::new(
|
||||
self.array.map(|axis|
|
||||
core::array::from_fn(|_|
|
||||
// axis dot product with transposed rhs array
|
||||
axis.iter().zip(
|
||||
@ -52,7 +52,7 @@ macro_rules! impl_matrix {
|
||||
).sum()
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>
|
||||
@ -60,17 +60,15 @@ macro_rules! impl_matrix {
|
||||
T:Copy
|
||||
{
|
||||
pub const fn from_value(value:T)->Self{
|
||||
Self{
|
||||
array:[[value;X];Y]
|
||||
}
|
||||
Self::new([[value;X];Y])
|
||||
}
|
||||
}
|
||||
|
||||
impl<const X:usize,const Y:usize,T:Default> Default for Matrix<X,Y,T>{
|
||||
fn default()->Self{
|
||||
Self{
|
||||
array:core::array::from_fn(|_|core::array::from_fn(|_|Default::default()))
|
||||
}
|
||||
Self::new(
|
||||
core::array::from_fn(|_|core::array::from_fn(|_|Default::default()))
|
||||
)
|
||||
}
|
||||
}
|
||||
#[cfg(feature="fixed_wide")]
|
||||
|
@ -16,9 +16,9 @@ macro_rules! impl_vector {
|
||||
where
|
||||
F:Fn(T)->U
|
||||
{
|
||||
Vector{
|
||||
array:self.array.map(f),
|
||||
}
|
||||
Vector::new(
|
||||
self.array.map(f)
|
||||
)
|
||||
}
|
||||
#[inline]
|
||||
pub fn map_zip<F,U,V>(self,other:Vector<N,U>,f:F)->Vector<N,V>
|
||||
@ -26,25 +26,23 @@ macro_rules! impl_vector {
|
||||
F:Fn((T,U))->V,
|
||||
{
|
||||
let mut iter=self.array.into_iter().zip(other.array);
|
||||
Vector{
|
||||
array:core::array::from_fn(|_|f(iter.next().unwrap())),
|
||||
}
|
||||
Vector::new(
|
||||
core::array::from_fn(|_|f(iter.next().unwrap())),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl<const N:usize,T:Copy> Vector<N,T>{
|
||||
#[inline(always)]
|
||||
pub const fn from_value(value:T)->Self{
|
||||
Self{
|
||||
array:[value;N]
|
||||
}
|
||||
Self::new([value;N])
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N:usize,T:Default> Default for Vector<N,T>{
|
||||
fn default()->Self{
|
||||
Self{
|
||||
array:core::array::from_fn(|_|Default::default())
|
||||
}
|
||||
Self::new(
|
||||
core::array::from_fn(|_|Default::default())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,9 +91,9 @@ macro_rules! impl_vector {
|
||||
impl<const N:usize,T:core::ops::Neg<Output=V>,V> core::ops::Neg for Vector<N,T>{
|
||||
type Output=Vector<N,V>;
|
||||
fn neg(self)->Self::Output{
|
||||
Vector{
|
||||
array:self.array.map(|t|-t)
|
||||
}
|
||||
Vector::new(
|
||||
self.array.map(|t|-t)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user