From dae72d73d5ad0538570c7e9eb7fc4ede0a3eb2d6 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 6 Sep 2024 10:52:17 -0700 Subject: [PATCH] convert to row-major --- fixed_wide_vectors/src/macros/matrix.rs | 10 +++++----- fixed_wide_vectors/src/matrix.rs | 2 +- fixed_wide_vectors/src/tests/tests.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index cde4330..e564df4 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -4,11 +4,11 @@ macro_rules! impl_matrix { () => { impl Matrix{ #[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.MatY = MatX - pub fn dot(self,rhs:Matrix)->Matrix + // MatY.MatX = MatY + pub fn dot(self,rhs:Matrix)->Matrix where T:core::ops::Mul+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] } } } diff --git a/fixed_wide_vectors/src/matrix.rs b/fixed_wide_vectors/src/matrix.rs index 4ca1236..784433c 100644 --- a/fixed_wide_vectors/src/matrix.rs +++ b/fixed_wide_vectors/src/matrix.rs @@ -1,6 +1,6 @@ #[derive(Clone,Copy,Hash,Eq,PartialEq)] pub struct Matrix{ - pub(crate) array:[[T;Y];X], + pub(crate) array:[[T;X];Y], } crate::impl_matrix!(); diff --git a/fixed_wide_vectors/src/tests/tests.rs b/fixed_wide_vectors/src/tests/tests.rs index 1c658dc..d81a7e0 100644 --- a/fixed_wide_vectors/src/tests/tests.rs +++ b/fixed_wide_vectors/src/tests/tests.rs @@ -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],