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!{
|
paste::item!{
|
||||||
#[inline]
|
#[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}>>{
|
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.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.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),
|
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]
|
#[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}>>{
|
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());
|
let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle());
|
||||||
Matrix{
|
Matrix::new(
|
||||||
array:self.array.map(|axis|
|
self.array.map(|axis|
|
||||||
core::array::from_fn(|_|
|
core::array::from_fn(|_|
|
||||||
// axis dot product with transposed rhs array
|
// axis dot product with transposed rhs array
|
||||||
axis.iter().zip(
|
axis.iter().zip(
|
||||||
@ -141,7 +141,7 @@ macro_rules! impl_matrix_wide_dot {
|
|||||||
).sum()
|
).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}>>{
|
impl Matrix<3,3,fixed_wide::fixed::Fixed<$n,{$n*32}>>{
|
||||||
paste::item!{
|
paste::item!{
|
||||||
pub fn [<wide_adjugate_3x3_ $n>](self)->Matrix<3,3,fixed_wide::fixed::Fixed<{$n*2},{$n*2*32}>>{
|
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.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.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)],
|
[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
|
where
|
||||||
F:Fn(T)->U
|
F:Fn(T)->U
|
||||||
{
|
{
|
||||||
Matrix{
|
Matrix::new(
|
||||||
array:self.array.map(|inner|inner.map(&f)),
|
self.array.map(|inner|inner.map(&f)),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn transpose(self)->Matrix<Y,X,T>{
|
pub fn transpose(self)->Matrix<Y,X,T>{
|
||||||
//how did I think of this
|
//how did I think of this
|
||||||
let mut array_of_iterators=self.array.map(|axis|axis.into_iter());
|
let mut array_of_iterators=self.array.map(|axis|axis.into_iter());
|
||||||
Matrix{
|
Matrix::new(
|
||||||
array:core::array::from_fn(|_|
|
core::array::from_fn(|_|
|
||||||
array_of_iterators.each_mut().map(|iter|
|
array_of_iterators.each_mut().map(|iter|
|
||||||
iter.next().unwrap()
|
iter.next().unwrap()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
// MatY<VecX>.MatX<VecZ> = MatY<VecZ>
|
// MatY<VecX>.MatX<VecZ> = MatY<VecZ>
|
||||||
@ -41,8 +41,8 @@ macro_rules! impl_matrix {
|
|||||||
U:Copy,
|
U:Copy,
|
||||||
{
|
{
|
||||||
let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle());
|
let mut array_of_iterators=rhs.array.map(|axis|axis.into_iter().cycle());
|
||||||
Matrix{
|
Matrix::new(
|
||||||
array:self.array.map(|axis|
|
self.array.map(|axis|
|
||||||
core::array::from_fn(|_|
|
core::array::from_fn(|_|
|
||||||
// axis dot product with transposed rhs array
|
// axis dot product with transposed rhs array
|
||||||
axis.iter().zip(
|
axis.iter().zip(
|
||||||
@ -52,7 +52,7 @@ macro_rules! impl_matrix {
|
|||||||
).sum()
|
).sum()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>
|
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>
|
||||||
@ -60,17 +60,15 @@ macro_rules! impl_matrix {
|
|||||||
T:Copy
|
T:Copy
|
||||||
{
|
{
|
||||||
pub const fn from_value(value:T)->Self{
|
pub const fn from_value(value:T)->Self{
|
||||||
Self{
|
Self::new([[value;X];Y])
|
||||||
array:[[value;X];Y]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const X:usize,const Y:usize,T:Default> Default for Matrix<X,Y,T>{
|
impl<const X:usize,const Y:usize,T:Default> Default for Matrix<X,Y,T>{
|
||||||
fn default()->Self{
|
fn default()->Self{
|
||||||
Self{
|
Self::new(
|
||||||
array:core::array::from_fn(|_|core::array::from_fn(|_|Default::default()))
|
core::array::from_fn(|_|core::array::from_fn(|_|Default::default()))
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature="fixed_wide")]
|
#[cfg(feature="fixed_wide")]
|
||||||
|
@ -16,9 +16,9 @@ macro_rules! impl_vector {
|
|||||||
where
|
where
|
||||||
F:Fn(T)->U
|
F:Fn(T)->U
|
||||||
{
|
{
|
||||||
Vector{
|
Vector::new(
|
||||||
array:self.array.map(f),
|
self.array.map(f)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_zip<F,U,V>(self,other:Vector<N,U>,f:F)->Vector<N,V>
|
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,
|
F:Fn((T,U))->V,
|
||||||
{
|
{
|
||||||
let mut iter=self.array.into_iter().zip(other.array);
|
let mut iter=self.array.into_iter().zip(other.array);
|
||||||
Vector{
|
Vector::new(
|
||||||
array:core::array::from_fn(|_|f(iter.next().unwrap())),
|
core::array::from_fn(|_|f(iter.next().unwrap())),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<const N:usize,T:Copy> Vector<N,T>{
|
impl<const N:usize,T:Copy> Vector<N,T>{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub const fn from_value(value:T)->Self{
|
pub const fn from_value(value:T)->Self{
|
||||||
Self{
|
Self::new([value;N])
|
||||||
array:[value;N]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N:usize,T:Default> Default for Vector<N,T>{
|
impl<const N:usize,T:Default> Default for Vector<N,T>{
|
||||||
fn default()->Self{
|
fn default()->Self{
|
||||||
Self{
|
Self::new(
|
||||||
array:core::array::from_fn(|_|Default::default())
|
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>{
|
impl<const N:usize,T:core::ops::Neg<Output=V>,V> core::ops::Neg for Vector<N,T>{
|
||||||
type Output=Vector<N,V>;
|
type Output=Vector<N,V>;
|
||||||
fn neg(self)->Self::Output{
|
fn neg(self)->Self::Output{
|
||||||
Vector{
|
Vector::new(
|
||||||
array:self.array.map(|t|-t)
|
self.array.map(|t|-t)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user