mod private
{
use crate::*;
use std::panic::UnwindSafe;
pub trait Order
{
const IS_ROW_MAJOR: bool;
fn order_str() -> &'static str;
}
pub trait OrderRowMajor : Order
{
const IS_ROW_MAJOR: bool = true;
#[ inline( always ) ]
fn order_str() -> &'static str
{
"row-major"
}
}
pub trait OrderColumnMajor : Order
{
const IS_ROW_MAJOR: bool = false;
#[ inline( always ) ]
fn order_str() -> &'static str
{
"column-major"
}
}
pub trait Descriptor : Order + UnwindSafe
{
const IS_ROW_MAJOR: bool;
const IS_ORDINARY: bool;
#[ inline( always ) ]
fn coords_str() -> &'static str
{
if Self::IS_ORDINARY
{
"ordinary"
}
else
{
"homogenous"
}
}
}
#[ derive( Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, derive_tools::exposed::Display ) ]
#[ display( "DescriptorOrderRowMajor" ) ]
pub struct DescriptorOrderRowMajor;
impl Descriptor for DescriptorOrderRowMajor {
const IS_ROW_MAJOR: bool = true;
const IS_ORDINARY: bool = true;
}
impl Order for DescriptorOrderRowMajor
{
const IS_ROW_MAJOR: bool = true;
#[ inline( always ) ]
fn order_str() -> &'static str
{
"row-major"
}
}
impl OrderRowMajor for DescriptorOrderRowMajor {}
pub type DescriptorDefault = DescriptorOrderRowMajor;
#[ derive( Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, derive_tools::exposed::Display ) ]
#[ display( "DescriptorOrderColumnMajor" ) ]
pub struct DescriptorOrderColumnMajor;
impl Descriptor for DescriptorOrderColumnMajor {
const IS_ROW_MAJOR: bool = false;
const IS_ORDINARY: bool = true;
}
impl Order for DescriptorOrderColumnMajor
{
const IS_ROW_MAJOR: bool = false;
#[ inline( always ) ]
fn order_str() -> &'static str
{
"column-major"
}
}
impl OrderColumnMajor for DescriptorOrderColumnMajor {}
pub trait MatEl
where
Self : Copy + Default,
{
}
impl< T > MatEl for T
where
Self : Copy + Default,
{
}
#[ derive( Clone, Copy, PartialEq, PartialOrd, Hash ) ]
pub struct Mat< const ROWS : usize, const COLS : usize, E, Descriptor >
(
[ [ E ; COLS ] ; ROWS ],
core::marker::PhantomData< Descriptor >,
)
where
E : MatEl,
;
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
#[ inline( always ) ]
fn _new( raw_slice : [ [ E ; COLS ] ; ROWS ] ) -> Self
{
Mat( raw_slice, Default::default() )
}
#[ inline( always ) ]
pub fn _fill( scalar : E ) -> Self
where
E : MatEl,
{
Self::_new( [ [ scalar ; COLS ] ; ROWS ] )
}
#[ inline( always ) ]
pub const fn as_ptr( &self ) -> *const E
{
self.0.as_ptr() as *const E
}
#[ inline( always ) ]
pub fn as_mut_ptr( &mut self ) -> *mut E
{
self.0.as_mut_ptr() as *mut E
}
#[ inline( always ) ]
pub const fn rows( &self ) -> usize
{
ROWS
}
#[ inline( always ) ]
pub const fn cols( &self ) -> usize
{
COLS
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Default for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
#[ inline( always ) ]
fn default() -> Self
{
Mat( [ [ E::default() ; COLS ]; ROWS ], Default::default() )
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Collection
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
type Scalar = E;
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > MatWithShape< ROWS, COLS >
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > MatWithShapeMut< ROWS, COLS >
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Indexable
for Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
type Index = Ix2;
#[ inline( always ) ]
fn dim( &self ) -> Self::Index
{
Ix2( ROWS, COLS )
}
}
impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
where
E : MatEl,
{
#[ inline( always ) ]
pub fn dim( &self ) -> < Self as Indexable >::Index
{
< Self as Indexable >::dim( self )
}
}
impl
<
E,
const ROWS : usize,
const COLS : usize,
Descriptor : mat::Descriptor,
> AbsDiffEq for Mat< ROWS, COLS, E, Descriptor >
where
Descriptor : PartialEq,
Self : Collection< Scalar = E >,
Mat< ROWS, COLS, E, Descriptor > : RawSlice,
E : AbsDiffEq + MatEl,
E::Epsilon : Copy,
{
type Epsilon = E::Epsilon;
fn default_epsilon() -> Self::Epsilon
{
E::default_epsilon()
}
fn abs_diff_eq( &self, other: &Self, epsilon: Self::Epsilon ) -> bool
{
ROWS == other.rows() && COLS == other.cols() &&
Iterator::zip( self.raw_slice().iter(), other.raw_slice() ).all( | ( x, y ) | E::abs_diff_eq( x, y, epsilon ) )
}
}
impl
<
E,
const ROWS : usize,
const COLS : usize,
Descriptor : mat::Descriptor,
> RelativeEq for Mat< ROWS, COLS, E, Descriptor >
where
Descriptor : PartialEq,
Self : Collection< Scalar = E >,
Mat< ROWS, COLS, E, Descriptor > : RawSlice,
E : RelativeEq + MatEl,
E::Epsilon : Copy,
{
fn default_max_relative() -> Self::Epsilon
{
E::default_max_relative()
}
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
{
ROWS == other.rows() && COLS == other.cols() &&
Iterator::zip( self.raw_slice().iter(), other.raw_slice() ).all( | ( x, y ) | E::relative_eq( x, y, epsilon, max_relative ) )
}
}
impl
<
E,
const ROWS : usize,
const COLS : usize,
Descriptor : mat::Descriptor,
> UlpsEq for Mat< ROWS, COLS, E, Descriptor >
where
Descriptor : PartialEq,
Self : Collection< Scalar = E >,
Mat< ROWS, COLS, E, Descriptor > : RawSlice,
E : UlpsEq + MatEl,
E::Epsilon : Copy,
{
fn default_max_ulps() -> u32
{
E::default_max_ulps()
}
fn ulps_eq( &self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32 ) -> bool
{
ROWS == other.rows() && COLS == other.cols() &&
Iterator::zip( self.raw_slice().iter(), other.raw_slice() ).all( | ( x, y ) | E::ulps_eq( x, y, epsilon, max_ulps ) )
}
}
pub type Mat2< E, Descriptor > = Mat< 2, 2, E, Descriptor >;
pub type Mat3< E, Descriptor > = Mat< 3, 3, E, Descriptor >;
pub type Mat4< E, Descriptor > = Mat< 4, 4, E, Descriptor >;
pub type F32x2x2 = Mat< 2, 2, f32, DescriptorOrderColumnMajor >;
pub type F32x3x3 = Mat< 3, 3, f32, DescriptorOrderColumnMajor >;
pub type F32x4x4 = Mat< 4, 4, f32, DescriptorOrderColumnMajor >;
pub type F64x2x2 = Mat< 2, 2, f64, DescriptorOrderColumnMajor >;
pub type F64x3x3 = Mat< 3, 3, f64, DescriptorOrderColumnMajor >;
pub type F64x4x4 = Mat< 4, 4, f64, DescriptorOrderColumnMajor >;
}
mod access_common;
mod access_mirror;
mod access_row_major;
mod access_column_major;
crate::mod_interface!
{
layer fns;
layer general;
own use
{
Order,
OrderRowMajor,
OrderColumnMajor,
Descriptor,
DescriptorOrderRowMajor,
DescriptorOrderColumnMajor,
DescriptorDefault,
};
exposed use
{
MatEl,
Mat,
Mat2,
Mat3,
Mat4,
F32x2x2,
F32x3x3,
F32x4x4,
F64x2x2,
F64x3x3,
F64x4x4
};
}