convert to row-major
This commit is contained in:
parent
4a1eff40da
commit
dae72d73d5
@ -4,11 +4,11 @@ macro_rules! impl_matrix {
|
||||
() => {
|
||||
impl<const X:usize,const Y:usize,T> Matrix<X,Y,T>{
|
||||
#[inline(always)]
|
||||
pub const fn new(array:[[T;Y];X])->Self{
|
||||
pub const fn new(array:[[T;X];Y])->Self{
|
||||
Self{array}
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn to_array(self)->[[T;Y];X]{
|
||||
pub fn to_array(self)->[[T;X];Y]{
|
||||
self.array
|
||||
}
|
||||
#[inline]
|
||||
@ -33,8 +33,8 @@ macro_rules! impl_matrix {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
// MatX<VecY>.MatY<VecZ> = MatX<VecZ>
|
||||
pub fn dot<const Z:usize,U,V>(self,rhs:Matrix<Y,Z,U>)->Matrix<X,Z,V>
|
||||
// MatY<VecX>.MatX<VecZ> = MatY<VecZ>
|
||||
pub fn dot<const Z:usize,U,V>(self,rhs:Matrix<Z,X,U>)->Matrix<Z,Y,V>
|
||||
where
|
||||
T:core::ops::Mul<U,Output=V>+Copy,
|
||||
V:core::iter::Sum,
|
||||
@ -61,7 +61,7 @@ macro_rules! impl_matrix {
|
||||
{
|
||||
pub const fn from_value(value:T)->Self{
|
||||
Self{
|
||||
array:[[value;Y];X]
|
||||
array:[[value;X];Y]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#[derive(Clone,Copy,Hash,Eq,PartialEq)]
|
||||
pub struct Matrix<const X:usize,const Y:usize,T>{
|
||||
pub(crate) array:[[T;Y];X],
|
||||
pub(crate) array:[[T;X];Y],
|
||||
}
|
||||
|
||||
crate::impl_matrix!();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::types::{Vector3,Matrix3x4,Matrix4x2,Matrix3x2};
|
||||
use crate::types::{Vector3,Matrix4x3,Matrix2x4,Matrix2x3};
|
||||
|
||||
#[test]
|
||||
fn test_bool(){
|
||||
@ -17,13 +17,13 @@ fn test_arithmetic(){
|
||||
#[test]
|
||||
fn matrix_dot(){
|
||||
|
||||
let rhs=Matrix4x2::new([
|
||||
let rhs=Matrix2x4::new([
|
||||
[ 1.0, 2.0],
|
||||
[ 3.0, 4.0],
|
||||
[ 5.0, 6.0],
|
||||
[ 7.0, 8.0],
|
||||
]); // | | |
|
||||
let lhs=Matrix3x4::new([ // | | |
|
||||
let lhs=Matrix4x3::new([ // | | |
|
||||
[1.0, 2.0, 3.0, 4.0],// [ 50.0, 60.0],
|
||||
[5.0, 6.0, 7.0, 8.0],// [114.0,140.0],
|
||||
[9.0,10.0,11.0,12.0],// [178.0,220.0],
|
||||
@ -34,7 +34,7 @@ fn matrix_dot(){
|
||||
//Out[1]= {{50, 60}, {114, 140}, {178, 220}}
|
||||
assert_eq!(
|
||||
m_dot.array,
|
||||
Matrix3x2::new([
|
||||
Matrix2x3::new([
|
||||
[50.0,60.0],
|
||||
[114.0,140.0],
|
||||
[178.0,220.0],
|
||||
|
Loading…
Reference in New Issue
Block a user