diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index 23755f3..f9375e7 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -3,8 +3,9 @@ #[macro_export(local_inner_macros)] macro_rules! impl_matrix { ( - ($struct_outer: ident { $($field_outer: ident), + }, ( $($generic_outer: tt), + ), $size_outer: expr), - ($struct_inner: ident, $size_inner: expr), $fields_inner:tt + ($struct_outer: ident { $($field_outer: ident), + }, $vector_outer: ident { $($vector_field_outer: ident), + }, $size_outer: expr), + ($struct_inner: ident { $($field_inner: ident), + }, $matrix_inner: ident { $($matrix_field_inner: ident), + }, $size_inner: expr), + ( $($generic_outer: tt), + ) ) => { impl $struct_outer<$struct_inner> { #[inline(always)] @@ -22,16 +23,15 @@ macro_rules! impl_matrix { where F: Fn(T) -> U { - $struct_outer { - $( - $field_outer: $crate::matrix_map2d_inner!{f,self,$field_outer,$fields_inner} - ), + - } + $crate::matrix_map2d_outer!{f,self,($struct_outer { $($field_outer), + }),($struct_inner { $($field_inner), + })} } #[inline] - pub fn transpose(self) -> $struct_inner<$struct_outer>{ - $crate::matrix_transpose_outer!{self,$fields_inner,($struct_outer { $($field_outer), + })} + pub fn transpose(self) -> $matrix_inner<$vector_outer>{ + $crate::matrix_transpose_outer!{self, + ($matrix_inner { $($matrix_field_inner), + }),($struct_inner { $($field_inner), + }), + ($vector_outer { $($vector_field_outer), + }),($struct_outer { $($field_outer), + }) + } } } @@ -52,6 +52,17 @@ macro_rules! impl_matrix { } +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! matrix_map2d_outer { + ( $f:ident, $value:ident, ($struct_outer: ident { $($field_outer: ident), + }), $unparsed_inner:tt ) => { + $struct_outer { + $( + $field_outer: $crate::matrix_map2d_inner!{$f,$value,$field_outer,$unparsed_inner} + ), + + } + } +} #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! matrix_map2d_inner { @@ -69,11 +80,13 @@ macro_rules! matrix_transpose_outer { ( $value:ident, ($struct_outer: ident { $($field_outer: ident), + }), - $fields_inner:tt + ($old_outer: ident { $($old_field_outer: ident), + }), + $fields_inner:tt, + $old_fields_inner:tt ) => { $struct_outer { $( - $field_outer: $crate::matrix_transpose_inner!{$value,$field_outer,$fields_inner} + $field_outer: $crate::matrix_transpose_inner!{$value,$old_field_outer,$fields_inner,$old_fields_inner} ), + } } @@ -81,10 +94,13 @@ macro_rules! matrix_transpose_outer { #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! matrix_transpose_inner { - ( $value:ident, $field_outer:ident, ($struct_inner: ident { $($field_inner: ident), + }) ) => { + ( $value:ident, $field_outer:ident, + ($struct_inner: ident { $($field_inner: ident), + }), + ($old_struct_inner: ident { $($old_field_inner: ident), + }) + ) => { $struct_inner { $( - $field_inner: $value.$field_inner.$field_outer + $field_inner: $value.$old_field_inner.$field_outer ), + } } diff --git a/fixed_wide_vectors/src/matrix.rs b/fixed_wide_vectors/src/matrix.rs index 9a658b8..a1e6943 100644 --- a/fixed_wide_vectors/src/matrix.rs +++ b/fixed_wide_vectors/src/matrix.rs @@ -19,12 +19,12 @@ pub struct Matrix4 { crate::impl_extend!(Matrix2 { x_axis, y_axis }, Matrix3, z_axis); crate::impl_extend!(Matrix3 { x_axis, y_axis, z_axis }, Matrix4, w_axis); -crate::impl_matrix!((Matrix2 { x_axis, y_axis }, ((T, T), (T, T)), 2), (Vector2, 2), (Vector2 { x, y }) ); -crate::impl_matrix!((Matrix2 { x_axis, y_axis }, ((T, T, T), (T, T, T)), 2), (Vector3, 3), (Vector3 { x, y, z }) ); -crate::impl_matrix!((Matrix2 { x_axis, y_axis }, ((T, T, T, T), (T, T, T, T)), 2), (Vector4, 4), (Vector4 { x, y, z, w }) ); -crate::impl_matrix!((Matrix3 { x_axis, y_axis, z_axis }, ((T, T), (T, T), (T, T)), 3), (Vector2, 2), (Vector2 { x, y }) ); -crate::impl_matrix!((Matrix3 { x_axis, y_axis, z_axis }, ((T, T, T), (T, T, T), (T, T, T)), 3), (Vector3, 3), (Vector3 { x, y, z }) ); -crate::impl_matrix!((Matrix3 { x_axis, y_axis, z_axis }, ((T, T, T, T), (T, T, T, T), (T, T, T, T)), 3), (Vector4, 4), (Vector4 { x, y, z, w }) ); -crate::impl_matrix!((Matrix4 { x_axis, y_axis, z_axis, w_axis }, ((T, T), (T, T), (T, T), (T, T)), 4), (Vector2, 2), (Vector2 { x, y }) ); -crate::impl_matrix!((Matrix4 { x_axis, y_axis, z_axis, w_axis }, ((T, T, T), (T, T, T), (T, T, T), (T, T, T)), 4), (Vector3, 3), (Vector3 { x, y, z }) ); -crate::impl_matrix!((Matrix4 { x_axis, y_axis, z_axis, w_axis }, ((T, T, T, T), (T, T, T, T), (T, T, T, T), (T, T, T, T)), 4), (Vector4, 4), (Vector4 { x, y, z, w }) ); +crate::impl_matrix!((Matrix2 { x_axis, y_axis }, Vector2 { x, y }, 2), (Vector2 { x, y }, Matrix2 { x_axis, y_axis }, 2), ((T, T), (T, T)) ); +crate::impl_matrix!((Matrix2 { x_axis, y_axis }, Vector2 { x, y }, 2), (Vector3 { x, y, z }, Matrix3 { x_axis, y_axis, z_axis }, 3), ((T, T, T), (T, T, T)) ); +crate::impl_matrix!((Matrix2 { x_axis, y_axis }, Vector2 { x, y }, 2), (Vector4 { x, y, z, w }, Matrix4 { x_axis, y_axis, z_axis, w_axis }, 4), ((T, T, T, T), (T, T, T, T)) ); +crate::impl_matrix!((Matrix3 { x_axis, y_axis, z_axis }, Vector3 { x, y, z }, 3), (Vector2 { x, y }, Matrix2 { x_axis, y_axis }, 2), ((T, T), (T, T), (T, T)) ); +crate::impl_matrix!((Matrix3 { x_axis, y_axis, z_axis }, Vector3 { x, y, z }, 3), (Vector3 { x, y, z }, Matrix3 { x_axis, y_axis, z_axis }, 3), ((T, T, T), (T, T, T), (T, T, T)) ); +crate::impl_matrix!((Matrix3 { x_axis, y_axis, z_axis }, Vector3 { x, y, z }, 3), (Vector4 { x, y, z, w }, Matrix4 { x_axis, y_axis, z_axis, w_axis }, 4), ((T, T, T, T), (T, T, T, T), (T, T, T, T)) ); +crate::impl_matrix!((Matrix4 { x_axis, y_axis, z_axis, w_axis }, Vector4 { x, y, z, w }, 4), (Vector2 { x, y }, Matrix2 { x_axis, y_axis }, 2), ((T, T), (T, T), (T, T), (T, T)) ); +crate::impl_matrix!((Matrix4 { x_axis, y_axis, z_axis, w_axis }, Vector4 { x, y, z, w }, 4), (Vector3 { x, y, z }, Matrix3 { x_axis, y_axis, z_axis }, 3), ((T, T, T), (T, T, T), (T, T, T), (T, T, T)) ); +crate::impl_matrix!((Matrix4 { x_axis, y_axis, z_axis, w_axis }, Vector4 { x, y, z, w }, 4), (Vector4 { x, y, z, w }, Matrix4 { x_axis, y_axis, z_axis, w_axis }, 4), ((T, T, T, T), (T, T, T, T), (T, T, T, T), (T, T, T, T)) ); diff --git a/fixed_wide_vectors/src/vector.rs b/fixed_wide_vectors/src/vector.rs index b9df27c..c528b5c 100644 --- a/fixed_wide_vectors/src/vector.rs +++ b/fixed_wide_vectors/src/vector.rs @@ -70,12 +70,12 @@ crate::impl_vector!(Vector4 { x, y, z, w }, (T, T, T, T), 4); crate::impl_extend!(Vector2 { x, y }, Vector3, z); crate::impl_extend!(Vector3 { x, y, z }, Vector4, w); -crate::impl_matrix!((Vector2 { x, y }, ((T, T), (T, T)), 2), (Vector2, 2), (Vector2 { x, y }) ); -crate::impl_matrix!((Vector2 { x, y }, ((T, T, T), (T, T, T)), 2), (Vector3, 3), (Vector3 { x, y, z }) ); -crate::impl_matrix!((Vector2 { x, y }, ((T, T, T, T), (T, T, T, T)), 2), (Vector4, 4), (Vector4 { x, y, z, w }) ); -crate::impl_matrix!((Vector3 { x, y, z }, ((T, T), (T, T), (T, T)), 3), (Vector2, 2), (Vector2 { x, y }) ); -crate::impl_matrix!((Vector3 { x, y, z }, ((T, T, T), (T, T, T), (T, T, T)), 3), (Vector3, 3), (Vector3 { x, y, z }) ); -crate::impl_matrix!((Vector3 { x, y, z }, ((T, T, T, T), (T, T, T, T), (T, T, T, T)), 3), (Vector4, 4), (Vector4 { x, y, z, w }) ); -crate::impl_matrix!((Vector4 { x, y, z, w }, ((T, T), (T, T), (T, T), (T, T)), 4), (Vector2, 2), (Vector2 { x, y }) ); -crate::impl_matrix!((Vector4 { x, y, z, w }, ((T, T, T), (T, T, T), (T, T, T), (T, T, T)), 4), (Vector3, 3), (Vector3 { x, y, z }) ); -crate::impl_matrix!((Vector4 { x, y, z, w }, ((T, T, T, T), (T, T, T, T), (T, T, T, T), (T, T, T, T)), 4), (Vector4, 4), (Vector4 { x, y, z, w }) ); +crate::impl_matrix!((Vector2 { x, y }, Vector2 { x, y }, 2), (Vector2 { x, y }, Vector2 { x, y }, 2), ((T, T), (T, T)) ); +crate::impl_matrix!((Vector2 { x, y }, Vector2 { x, y }, 2), (Vector3 { x, y, z }, Vector3 { x, y, z }, 3), ((T, T, T), (T, T, T)) ); +crate::impl_matrix!((Vector2 { x, y }, Vector2 { x, y }, 2), (Vector4 { x, y, z, w }, Vector4 { x, y, z, w }, 4), ((T, T, T, T), (T, T, T, T)) ); +crate::impl_matrix!((Vector3 { x, y, z }, Vector3 { x, y, z }, 3), (Vector2 { x, y }, Vector2 { x, y }, 2), ((T, T), (T, T), (T, T)) ); +crate::impl_matrix!((Vector3 { x, y, z }, Vector3 { x, y, z }, 3), (Vector3 { x, y, z }, Vector3 { x, y, z }, 3), ((T, T, T), (T, T, T), (T, T, T)) ); +crate::impl_matrix!((Vector3 { x, y, z }, Vector3 { x, y, z }, 3), (Vector4 { x, y, z, w }, Vector4 { x, y, z, w }, 4), ((T, T, T, T), (T, T, T, T), (T, T, T, T)) ); +crate::impl_matrix!((Vector4 { x, y, z, w }, Vector4 { x, y, z, w }, 4), (Vector2 { x, y }, Vector2 { x, y }, 2), ((T, T), (T, T), (T, T), (T, T)) ); +crate::impl_matrix!((Vector4 { x, y, z, w }, Vector4 { x, y, z, w }, 4), (Vector3 { x, y, z }, Vector3 { x, y, z }, 3), ((T, T, T), (T, T, T), (T, T, T), (T, T, T)) ); +crate::impl_matrix!((Vector4 { x, y, z, w }, Vector4 { x, y, z, w }, 4), (Vector4 { x, y, z, w }, Vector4 { x, y, z, w }, 4), ((T, T, T, T), (T, T, T, T), (T, T, T, T), (T, T, T, T)) );