rewrite transpose
This commit is contained in:
parent
83a39468d5
commit
63cf94499b
@ -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<T> $struct_outer<$struct_inner<T>> {
|
||||
#[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<T>>{
|
||||
$crate::matrix_transpose_outer!{self,$fields_inner,($struct_outer { $($field_outer), + })}
|
||||
pub fn transpose(self) -> $matrix_inner<$vector_outer<T>>{
|
||||
$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
|
||||
), +
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ pub struct Matrix4<T> {
|
||||
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)) );
|
||||
|
@ -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)) );
|
||||
|
Loading…
Reference in New Issue
Block a user